simply_nwb.transferring.filesync package
Submodules
simply_nwb.transferring.filesync.oneway module
- class simply_nwb.transferring.filesync.oneway.CopyThread(src_pth: str, dst: str, filename: str, do_del: bool)
Bases:
Thread- __init__(src_pth: str, dst: str, filename: str, do_del: bool)
Create a thread to copy an object to a destination. obj could be a file or directory
- Parameters:
src_pth – File or directory location path to copy to dst
dst – Destination to copy the file to
- run_method()
- class simply_nwb.transferring.filesync.oneway.OneWayFileSync(source_directory: str, destination_directory: str, watch_file_glob: dict | str, interval: int = 5, delete_on_copy: bool = False)
Bases:
object- __init__(source_directory: str, destination_directory: str, watch_file_glob: dict | str, interval: int = 5, delete_on_copy: bool = False)
Create a new FileSync instance, to automatically copy files from src to dest, that match a file glob queried at an interval. Can provide a string for watch_file_glob or a dict. The dict will be in format:
def split_filename(filename): # Will split 'img_5.tif' and return '5' a = filename.split("_") b = a[1].split(".") return b[0] { # Will copy over files that match '*.tif' to 'image_{name}.tif' # Using the function above to reformat the filename # For example a file matched called 'img_5.tif' will be copied to 'image_5.tif' # since the above function will split off the '5' and then format to 'image_{name}.tif' # which is just 'image_5.tif' # See transferring_custom_one_way.py in the examples/ directory "*.tif": { "filename": "image_{name}.tif", "name_func": split_filename }, "*.txt": {} # Will copy all txt files without renaming them ... }
- Parameters:
source_directory – Directory to watch for new files
destination_directory – Directory to copy files to
watch_file_glob – Glob for selecting which files to copy from the source directory, can provide a dict for more customization
interval – how often should the source directory be queried in seconds
delete_on_copy – After copying a file to the destination, delete it from the source location
- start()
Start the filesync watcher, will watch for changes until killed/stopped :return:
- stop(*args, **kwargs)
Stop the filesync watcher from code
- Parameters:
args – None
kwargs – None
- Returns:
None