From 15581a395b61bf4446d23582254cb9a8db417aaf Mon Sep 17 00:00:00 2001 From: Parul Date: Fri, 16 Feb 2024 07:57:08 -0800 Subject: [PATCH] local os support for file transfer --- pyproject.toml | 2 +- src/filepass/__init__.py | 8 +++++++- src/filepass/filepass.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d2d82f7..dc37234 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "filepass" -version = "0.3.0" +version = "0.4.0" authors = [ { name="Orlund Norstrom", email="onorstrom@kamloops.ca" }, { name="Marco Lussetti", email="mlussetti@kamloops.ca" }, diff --git a/src/filepass/__init__.py b/src/filepass/__init__.py index 69d6714..213ba3f 100644 --- a/src/filepass/__init__.py +++ b/src/filepass/__init__.py @@ -1 +1,7 @@ -from .filepass import file_pass, sftp_connection, smb_connection +from .filepass import ( + file_pass, + local_connection, + osfs_connection, + sftp_connection, + smb_connection, +) diff --git a/src/filepass/filepass.py b/src/filepass/filepass.py index 6a7de38..273264b 100644 --- a/src/filepass/filepass.py +++ b/src/filepass/filepass.py @@ -24,6 +24,19 @@ def smb_connection(logger, user, pw, svr, port, smbshare, dir): return fs_conn +def local_connection(logger, dir: str): + """Establishes a connection to a directory on the local filesystem""" + logger.debug("local connection to {}".format(dir)) + fs_conn = fs.open_fs("{}".format(dir)) + return fs_conn + + +def osfs_connection(logger, dir): + logger.debug("osfs dir: {}".format(dir)) + fs_conn = fs.open_fs(dir) + return fs_conn + + # Boolean parameter to add ability to rename target file in single file mode def transfer_file(from_fs, to_fs, filename, should_rename=False, new_filename=None): target_filename = new_filename if new_filename and should_rename else filename @@ -64,16 +77,33 @@ def file_pass( logger, from_user, from_pw, from_svr, from_port, from_share, from_dir ) + if from_method == "local": + logger.debug("Create from local/osfs connection") + from_fs = local_connection(logger, from_dir) + + if from_method == "osfs": + logger.debug("Create osfs connection") + from_fs = osfs_connection(logger, from_dir) + # To File System if to_method == "sftp": logger.debug("Create to SFTP connection") to_fs = sftp_connection(logger, to_user, to_pw, to_svr, to_port, to_dir) + if to_method == "smb": logger.debug("Create to SMB connection") to_fs = smb_connection( logger, to_user, to_pw, to_svr, to_port, to_share, to_dir ) + if to_method == "local": + logger.debug("Create from local connection") + to_fs = local_connection(logger, to_dir) + + if to_method == "osfs": + logger.debug("Create to OSFS connection") + to_fs = osfs_connection(logger, to_dir) + # Do the move walker = Walker(filter=[from_filter], ignore_errors=True, max_depth=1) # Create a list of files to be transferred based on the filter.