dol.filesys

File system access

class dol.filesys.DirCollection(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.DirReader(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.FileBytesPersister(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.FileBytesReader(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.FileCollection(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.FileInfoReader(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.FileStringPersister(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.FileStringReader(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.FileSysCollection(rootdir, subpath='', pattern_for_field=None, max_levels=None, *, include_hidden=False, assert_rootdir_existence=False)[source]
class dol.filesys.Files(*args, **kwargs)[source]

FileBytesPersister with relative paths

class dol.filesys.FilesReader(*args, **kwargs)[source]

FileBytesReader with relative paths

exception dol.filesys.KeyValidationError[source]
class dol.filesys.MakeMissingDirsStoreMixin[source]

Will make a local file store automatically create the directories needed to create a file. Should be placed before the concrete perisister in the mro but in such a manner so that it receives full paths.

class dol.filesys.PickleStore(*args, **kwargs)[source]

A store of pickles

class dol.filesys.PickleStores(*args, **kwargs)[source]
dol.filesys.RelPathFileBytesPersister

alias of dol.filesys.Files

dol.filesys.RelPathFileBytesReader

alias of dol.filesys.FilesReader

dol.filesys.RelPathFileStringPersister

alias of dol.filesys.TextFiles

dol.filesys.RelPathFileStringReader

alias of dol.filesys.TextFilesReader

class dol.filesys.TextFiles(*args, **kwargs)[source]

FileStringPersister with relative paths

class dol.filesys.TextFilesReader(*args, **kwargs)[source]

FileStringReader with relative paths

dol.filesys.ensure_dir(dirpath, verbose: Union[bool, str, Callable] = False)[source]

Ensure that a directory exists, creating it if necessary.

Parameters
  • dirpath – path to the directory to create

  • verbose – controls verbosity (the noise ensure_dir makes if it make folder)

Returns

the path to the directory

When the path does not exist, if verbose is:

  • a bool’ a standard message will be printed

  • a callable; will be called on dirpath before directory is created – you

can use this to ask the user for confirmation for example

  • a ‘’string``; this string will be printed

Usage note: If you want to string or the (argument-less) callable to be dependent on dirpath, you need make them so when calling ensure_dir.

dol.filesys.ensure_slash_suffix(path: str)[source]

Add a file separation (/ or ) at the end of path str, if not already present.

dol.filesys.iter_dirpaths_in_folder_recursively(root_folder, max_levels=None, _current_level=0, include_hidden=False)[source]

Recursively generates dirpaths of folder (and subfolders, etc.) up to a given level

dol.filesys.iter_filepaths_in_folder_recursively(root_folder, max_levels=None, _current_level=0, include_hidden=False)[source]

Recursively generates filepaths of folder (and subfolders, etc.) up to a given level

dol.filesys.mk_dirs_if_missing(store_cls=None, *, verbose: Union[bool, str, Callable] = False, key_condition=None, __module__=None, __name__=None, __qualname__=None, __doc__=None, __annotations__=None, __defaults__=None, __kwdefaults__=None)[source]

Store decorator that will make the store create directories on write as needed.

Note that it’ll only effect paths relative to the rootdir, which needs to be ensured to exist separatedly.

dol.filesys.resolve_dir(dirpath: str, assert_existence: bool = False, ensure_existence: bool = False)[source]

Resolve a path to a full, real, path to a directory

dol.filesys.resolve_path(path, assert_existence: bool = False)[source]

Resolve a path to a full, real, (file or folder) path (opt assert existence). That is, resolve situations where ~ and . prefix the paths.