Fileson module

Fileson class to manipulate Fileson databases.

class fileson.Fileson(*args, **kwargs)[source]

File database with previous versions support based on LogDict.

The file format is fully compatible so you can use LogDict.create() to instantiate one. Special keys like :scan:, :checksum: used for metadata and additional files() and dirs() methods expose certain types of contents. Also, set() used to implement “set if changed” functionality.

dirs() list[source]

Return paths to dirs.

files() list[source]

Return paths to files.

classmethod load(dbfile: str) Fileson[source]

Overloaded class method to support f.fson~1 history syntax.

classmethod load_or_scan(db_or_dir: str, **kwargs) Fileson[source]

Load Fileson database or create one by scanning a directory.

This basically calls load() or creates a new instance and uses scan() after it (passing kwargs).

Parameters:

db_or_dir (str) – Database or directory name

Returns:

New class instance

Return type:

Fileson

scan(directory: str, **kwargs) None[source]

Scan a directory for objects or changes.

Every invocation creates a new ‘run’, a version to Fileson database. Only changes need to be stored. You can then use for example genItems() and pick only objects that were changed on a given run.

Parameters:
  • directory (str) – Directory to scan

  • **kwargs – Booleans ‘verbose’ and ‘strict’ control behaviour

set(key: Any, val: Any) bool[source]

Set key to val if there’s a change, in which case return True.

fileson.gmt_epoch(mtime: str) int[source]

Convert YYYY-MM-DD HH:MM:SS in GMT to epoch.

fileson.gmt_str(mtime: Optional[int] = None) str[source]

Convert st_mtime to GMT string.

fileson.scantree(path, skip=<function <lambda>>)[source]

Recursively yield DirEntry objects for given directory.