parsley.filesystem package

Submodules

parsley.filesystem.abstractfilesystem module

Abstract base class for filesystem implementations.

class parsley.filesystem.abstractfilesystem.Filesystem(*aspects, name, checkaliveskeptically='0')

Bases: object

Base class for a filesystem implementation.

It’s an abstraction layer for all filesystem operations like ‘create file’ or ‘remove x’. See parsley.filesystem for existing implementations.

Parameters
_create_control_filesystem(path)

Creates a control filesystem. Override this method in custom subclasses.

Return type

Tuple[parsley.filesystem.abstractfilesystem.Filesystem, bool]

checkalive()

Ensures that the filesystem is alive and throws an exception otherwise. Call this method whenever you have fetched some infos whose correctness is critical for the further processing.

Return type

None

copyfile(srcpath, dstpath, verifier=<function Filesystem.<lambda>>)

Copies a file from the local filesystem to a destination. Override this method in custom subclasses.

Parameters
  • srcpath (str) –

  • dstpath (str) –

Return type

Tuple[datetime.datetime, int]

createdirs(path, recursive=True)

Creates a directory (or a chain of directories). Override this method in custom subclasses.

Parameters
  • path (str) –

  • recursive (bool) –

Return type

List[str]

Creates a link. Override this method in custom subclasses.

Parameters
  • srcpath (str) –

  • dstpath (str) –

Return type

None

exists(path)

Returns if an item at a given location exists. Override this method in custom subclasses.

Parameters

path (str) –

Return type

bool

get_control_filesystem(path=None)

Returns a parsley.filesystem.abstractfilesystem.Filesystem wrapper to the control directory. This is typically backed within sync volume itself and can be used for storing control information on that (potentially remote) place.

Parameters

path (Optional[str]) –

Return type

parsley.filesystem.abstractfilesystem.Filesystem

get_parent_filesystem()

If this is a control filesystem, it returns the original one, otherwise self.

Return type

parsley.filesystem.abstractfilesystem.Filesystem

getftype(path)

Returns the parsley.syncengine.common.EntryType item type of an item. Override this method in custom subclasses.

Parameters

path (str) –

Return type

Optional[str]

getfulllocalpath(path)

Returns the local filesystem path of a file. Returns None if there is representation in the local filesystem. Override this method in custom subclasses or leave the default implementation. @note Returning None or not implementing it will probably restrict the things parsley can do.

Parameters

path (str) –

Return type

Optional[str]

getfulllocalpathorfallback(path)

Returns a string representation, containing the local filesystem path of a file or something else.

Parameters

path (str) –

Return type

str

getinputstream(path)

Returns a binary file stream (like Python’s open would do) for reading from a path. Override this method in custom subclasses.

Parameters

path (str) –

Return type

BinaryIO

getlinktarget(path)

Returns the link target of a link. Override this method in custom subclasses.

Parameters

path (str) –

Return type

str

getmtime(path)

Returns the time of last modification of a file. Override this method in custom subclasses.

Parameters

path (str) –

Return type

datetime.datetime

getoutputstream(path)

Returns a binary file stream (like Python’s open would do) for writing to a path. Override this method in custom subclasses.

Parameters

path (str) –

Return type

BinaryIO

getsize(path)

Returns the file size of a file. Override this method in custom subclasses.

Parameters

path (str) –

Return type

int

getxattrvalue(path, key)

Returns the extended attribute value for a file and a key. Override this method in custom subclasses.

Parameters
  • path (str) –

  • key (str) –

Return type

str

initialize(sync, runtime)

Runs initialization (before preparations are executed). Override this method in custom subclasses or leave the default implementation.

Parameters
Return type

None

initialize_late(sync, runtime)

Runs late initialization (after it is prepared). Override this method in custom subclasses or leave the default implementation.

Parameters
Return type

None

is_control_filesystem()

Checks if this is a control filesystem.

Return type

bool

is_mtime_precision_fine()

Checks if the filesystem has fine (typically milliseconds) time granularity. Override this method in custom subclasses or leave the default implementation.

Return type

bool

listdir(path)

Returns a list of the names of all items in the given location. Override this method in custom subclasses.

Parameters

path (str) –

Return type

List[str]

listxattrkeys(path)

Returns a list of names of extended attributes stored for a file. Override this method in custom subclasses.

Parameters

path (str) –

Return type

List[str]

move(path, dst)

Moves an item. Override this method in custom subclasses.

Parameters
  • path (str) –

  • dst (str) –

Return type

None

readfromfile(path)

Reads the content of a file and returns it. Override this method in custom subclasses.

Parameters

path (str) –

Return type

bytes

removedir(path, recursive=False)

Removes a directory. Override this method in custom subclasses.

Parameters
  • path (str) –

  • recursive (bool) –

Return type

None

removefile(path)

Removes a file. Override this method in custom subclasses.

Parameters

path (str) –

Return type

None

Removes a link. Override this method in custom subclasses.

Parameters

path (str) –

Return type

None

setxattrvalue(path, key, value)

Sets an extended attribute value on a file. Override this method in custom subclasses.

Parameters
  • path (str) –

  • key (str) –

  • value (str) –

Return type

None

shutdown(sync, runtime)

Shuts down the filesystem.

Parameters
Return type

None

translate_path(path, dstfs)

Translates a path from this filesystem into a path valid for another one. Returns None if this translation is not possible.

Parameters
Return type

Optional[str]

unsetxattrvalue(path, key)

Unsets an extended attribute value on a file. Override this method in custom subclasses.

Parameters
  • path (str) –

  • key (str) –

Return type

None

writetofile(path, content)

Writes a byte array to a file. Override this method in custom subclasses.

Parameters
  • path (str) –

  • content (bytes) –

Return type

None

exception parsley.filesystem.abstractfilesystem.SyncFilesystemError

Bases: parsley.exceptions.ParsleyError

parsley.filesystem.local module

class parsley.filesystem.local.LocalFilesystem(*aspects, path, external_control_directory=None, **kwa)

Bases: parsley.filesystem.abstractfilesystem.Filesystem

A location in the local filesystem.

Parameters

external_control_directory – Absolute path to an external volume storage directory. Use it for read-only filesystems.

_create_control_filesystem(path)

Creates a control filesystem. Override this method in custom subclasses.

_gettemp()
_translate_remote_time_to_local(rtime)
Parameters

rtime (datetime.datetime) –

Return type

datetime.datetime

copyfile(srcpath, dstpath, verifier=<function LocalFilesystem.<lambda>>)

Copies a file from the local filesystem to a destination. Override this method in custom subclasses.

createdirs(path, recursive=True)

Creates a directory (or a chain of directories). Override this method in custom subclasses.

Creates a link. Override this method in custom subclasses.

exists(path)

Returns if an item at a given location exists. Override this method in custom subclasses.

getftype(path)

Returns the parsley.syncengine.common.EntryType item type of an item. Override this method in custom subclasses.

getfulllocalpath(path)

Returns the local filesystem path of a file. Returns None if there is representation in the local filesystem. Override this method in custom subclasses or leave the default implementation. @note Returning None or not implementing it will probably restrict the things parsley can do.

getinputstream(path)

Returns a binary file stream (like Python’s open would do) for reading from a path. Override this method in custom subclasses.

getlinktarget(path)

Returns the link target of a link. Override this method in custom subclasses.

getmtime(path)

Returns the time of last modification of a file. Override this method in custom subclasses.

getoutputstream(path)

Returns a binary file stream (like Python’s open would do) for writing to a path. Override this method in custom subclasses.

getsize(path)

Returns the file size of a file. Override this method in custom subclasses.

getxattrvalue(path, key)

Returns the extended attribute value for a file and a key. Override this method in custom subclasses.

initialize(sync, runtime)

Runs initialization (before preparations are executed). Override this method in custom subclasses or leave the default implementation.

initialize_late(sync, runtime)

Runs late initialization (after it is prepared). Override this method in custom subclasses or leave the default implementation.

is_mtime_precision_fine()

Checks if the filesystem has fine (typically milliseconds) time granularity. Override this method in custom subclasses or leave the default implementation.

listdir(path)

Returns a list of the names of all items in the given location. Override this method in custom subclasses.

listxattrkeys(path)

Returns a list of names of extended attributes stored for a file. Override this method in custom subclasses.

move(path, dst)

Moves an item. Override this method in custom subclasses.

readfromfile(path)

Reads the content of a file and returns it. Override this method in custom subclasses.

removedir(path, recursive=False)

Removes a directory. Override this method in custom subclasses.

removefile(path)

Removes a file. Override this method in custom subclasses.

Removes a link. Override this method in custom subclasses.

setxattrvalue(path, key, value)

Sets an extended attribute value on a file. Override this method in custom subclasses.

unsetxattrvalue(path, key)

Unsets an extended attribute value on a file. Override this method in custom subclasses.

writetofile(path, content)

Writes a byte array to a file. Override this method in custom subclasses.

exception parsley.filesystem.local.SyncLocalFilesystemError

Bases: parsley.filesystem.abstractfilesystem.SyncFilesystemError

parsley.filesystem.sshfs module

class parsley.filesystem.sshfs.SshfsFilesystem(*aspects, name, sshtarget, path, idfile=None, password=None, port='22', timeout='10s', **kwa)

Bases: parsley.filesystem.local.LocalFilesystem

A location in a (remote) ssh filesystem. Please note that remote ssh filesystems have to be manually prepared before using with parsley. This is needed for some detection features. Please create the directory .parsley.control in the root directory of a directory structure, before you try to sync it via ssh with parsley!

Parameters

external_control_directory – Absolute path to an external volume storage directory. Use it for read-only

filesystems.

class _SshXattrProxy(sshfs)

Bases: object

_waitanswer(endstring, additionaltimeout=0)
request(command)
shutdown()
getsshxattrproxy()
getxattrvalue(path, key)

Returns the extended attribute value for a file and a key. Override this method in custom subclasses.

initialize(sync, runtime)

Runs initialization (before preparations are executed). Override this method in custom subclasses or leave the default implementation.

listxattrkeys(path)

Returns a list of names of extended attributes stored for a file. Override this method in custom subclasses.

setxattrvalue(path, key, value)

Sets an extended attribute value on a file. Override this method in custom subclasses.

shutdown(sync, runtime)

Shuts down the filesystem.

unsetxattrvalue(path, key)

Unsets an extended attribute value on a file. Override this method in custom subclasses.

exception parsley.filesystem.sshfs.SyncSshFilesystemError

Bases: parsley.filesystem.abstractfilesystem.SyncFilesystemError

exception parsley.filesystem.sshfs.SyncSshFilesystemRemoteProxyError

Bases: parsley.filesystem.sshfs.SyncSshFilesystemError

Module contents

Implementations of filesystems for use with parsley.syncengine.sync.Sync. Each filesystem implementation should be encapsulated as a subclass of parsley.filesystem.abstractfilesystem.Filesystem.