diff --git a/src/zasd/filesystem.py b/src/zasd/filesystem.py index 0b7f3b0..9d034d3 100644 --- a/src/zasd/filesystem.py +++ b/src/zasd/filesystem.py @@ -1,4 +1,6 @@ -filesystems = {} +# Public API + +''' Base filesystem classes and registration facilities ''' class Filesystem: ''' Base filsystem class inherited by each filesystem implementation ''' @@ -8,7 +10,7 @@ class Filesystem: self._name = name # Process arguments to extract all properties - props = process_args(props, kwprops) + props = _process_args(props, kwprops) # Delegate further initialisation to the subclass self.initialise(props) @@ -45,7 +47,7 @@ class Filesystem: class Snapshot: ''' Base snapshot class inherited by each filesystem implementation ''' - def __init__(self, filesystem, tag, *props, **kwprops): + def __init__(self, filesystem, tag, props, **kwprops): # pylint: disable=unused-argument # Set common properties @@ -53,7 +55,7 @@ class Snapshot: self._tag = tag # Process arguments to extract all properties - props = process_args(props, kwprops) + props = _process_args(props, kwprops) # Delegate further initialisation to the subclass self.initialise(props) @@ -96,7 +98,30 @@ class Snapshot: ''' Delete this snapshot. No further method calls are made on the snapshot once it has been destroyed. ''' -def process_args(props, kwprops): +class FilesystemRegistry: + ''' Class that keeps a global registry of available Filesystem classes ''' + + _filesystems = {} + + @classmethod + def register(cls, name, klass): + ''' Register a filesystem. If a filesystem needs to be configured by the + user, it must retrieve its configuration from a dictionary at + config['filesystems'][name]. ''' + cls._filesystems[name] = klass + + @classmethod + def all(cls): + ''' Retrieve a {name: class} dictionary of all registered + filesystems ''' + return dict(cls._filesystems) + +# +# Private objects + +_filesystems = {} + +def _process_args(props, kwprops): ''' Merge 'props' and 'kwprops' into single dictionary ''' if props: if not isinstance(props, dict): @@ -108,10 +133,4 @@ def process_args(props, kwprops): # Update properties dictionary with keyword arguments props.update(kwprops) - return props - -def register(name, klass): - ''' Register a filesystem. If a filesystem needs to be configured by the - user, it must retrieve its configuration from a dictionary at - config['filesystems'][name]. ''' - filesystems[name] = klass \ No newline at end of file + return props \ No newline at end of file