ballet.util.fs module¶
-
ballet.util.fs.isemptyfile(filepath)[source]¶ Determine if the file both exists and isempty
- Return type
bool
-
ballet.util.fs.pwalk(d, **kwargs)[source]¶ Similar to os.walk but with pathlib.Path objects
- Return type
Iterator[Path]
-
ballet.util.fs.replaceext(filepath, new_ext)[source]¶ Replace any existing file extension with a new one
If the new extension is the empty string, all existing extensions will be removed.
Example:
>>> replaceext('/foo/bar.txt', 'py') '/foo/bar.py' >>> replaceext('/foo/bar.txt', '.doc') '/foo/bar.doc'
- Parameters
filepath (
Union[str,PathLike]) – file pathnew_ext (
str) – new file extension; if a leading dot is not included, it will be added.
- Return type
str
-
ballet.util.fs.spliceext(filepath, s)[source]¶ Add s into filepath before the extension
- Return type
str
-
ballet.util.fs.splitext2(filepath)[source]¶ Split filepath into root, filename, ext
- Return type
Tuple[str,str,str]
-
ballet.util.fs.synctree(src, dst, onexist=None)[source]¶ Recursively sync files at directory src to dst
This is more or less equivalent to:
cp -n -R ${src}/ ${dst}/If a file at the same path exists in src and dst, it is NOT overwritten in dst. Pass
onexistin order to raise an error on such conditions.- Parameters
src (
Union[str,PathLike]) – source directorydst (
Union[str,PathLike]) – destination directory, does not need to existonexist (
Optional[Callable[[Path],None]]) – function to call if file exists at destination, takes the full path to destination file as only argument
- Return type
List[Tuple[Path,str]]- Returns
changes made by synctree, list of tuples of the form (“/absolute/path/to/file”, “<kind>”) where the change kind is one of “dir” (new directory was created) or “file” (new file was created).