From 39079213ac03ee9376526f41329de09ad6e744ea Mon Sep 17 00:00:00 2001 From: Parul Date: Tue, 20 Feb 2024 08:38:04 -0800 Subject: [PATCH 1/7] connection object for filepass --- cli.py | 73 +++++++------------ pyproject.toml | 2 +- src/filepass/__init__.py | 10 +++ src/filepass/filepass.py | 120 +++++++++++++++----------------- src/filepass/filepass_config.py | 18 +++++ 5 files changed, 112 insertions(+), 111 deletions(-) create mode 100644 src/filepass/filepass_config.py diff --git a/cli.py b/cli.py index 2fad0f9..55ce05e 100644 --- a/cli.py +++ b/cli.py @@ -4,35 +4,36 @@ import graypy -from src.filepass import file_pass +from src.filepass import ConnectionDetails, file_pass def main(): # Load Environmental Variables - # GREYLOG_SERVER - # GREYLOG_PORT - # INTEGRATION_NAME + # Connection objects + from_conn = ConnectionDetails( + method=os.environ.get("FROMMETHOD"), + user=os.environ.get("FROMUSER"), + password=os.environ.get("FROMPW"), + server=os.environ.get("FROMSVR"), + port=os.environ.get("FROMPORT"), + dir=os.environ.get("FROMDIR"), + share=os.environ.get("FROMSMBSHARE"), + ) + + to_conn = ConnectionDetails( + method=os.environ.get("TOMETHOD"), + user=os.environ.get("TOUSER"), + password=os.environ.get("TOPW"), + server=os.environ.get("TOSVR"), + port=os.environ.get("TOPORT"), + dir=os.environ.get("TODIR"), + share=os.environ.get("TOSMBSHARE"), + ) - from_user = os.environ.get("FROMUSER") - from_pw = os.environ.get("FROMPW") - from_svr = os.environ.get("FROMSVR") - from_port = os.environ.get("FROMPORT") - from_dir = os.environ.get("FROMDIR") - from_share = os.environ.get("FROMSMBSHARE") - from_method = os.environ.get("FROMMETHOD") from_delete = os.environ.get("FROMDELETE") from_filter = os.environ.get("FROMFILEFILTER") - - to_user = os.environ.get("TOUSER") - to_pw = os.environ.get("TOPW") - to_svr = os.environ.get("TOSVR") - to_port = os.environ.get("TOPORT") - to_dir = os.environ.get("TODIR") - to_share = os.environ.get("TOSMBSHARE") - to_method = os.environ.get("TOMETHOD") to_delete = os.environ.get("TODELETE") - # Environment variable added for filename change in single file mode new_filename = os.environ.get("NEW_FILENAME") filepass_logger = logging.getLogger("filepass_logger") @@ -51,19 +52,11 @@ def main(): logger = logging.LoggerAdapter( filepass_logger, { - "from_method": from_method, - "from_user": from_user, - "from_svr": from_svr, - "from_port": from_port, - "from_share": from_share, - "from_dir": from_dir, + "from_conn": from_conn, + "from_delete": from_delete, "from_filter": from_filter, - "to_method": to_method, - "to_user": to_user, - "to_svr": to_svr, - "to_port": to_port, - "to_share": to_share, - "to_dir": to_dir, + "to_conn": to_conn, + "to_delete": to_delete, "integration": "filepass", "filepass_name": os.environ.get("INTEGRATION_NAME"), "new_filename": new_filename, @@ -72,22 +65,10 @@ def main(): try: file_pass( logger, - from_user, - from_pw, - from_svr, - from_port, - from_dir, - from_share, - from_method, + from_conn, from_delete, from_filter, - to_user, - to_pw, - to_svr, - to_port, - to_dir, - to_share, - to_method, + to_conn, to_delete, new_filename, ) diff --git a/pyproject.toml b/pyproject.toml index dc37234..5ee5318 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "filepass" -version = "0.4.0" +version = "0.5.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 213ba3f..77d4730 100644 --- a/src/filepass/__init__.py +++ b/src/filepass/__init__.py @@ -5,3 +5,13 @@ sftp_connection, smb_connection, ) +from .filepass_config import ConnectionDetails + +__all__ = [ + "ConnectionDetails", + "sftp_connection", + "smb_connection", + "local_connection", + "osfs_connection", + "file_pass", +] diff --git a/src/filepass/filepass.py b/src/filepass/filepass.py index 273264b..449f5b8 100644 --- a/src/filepass/filepass.py +++ b/src/filepass/filepass.py @@ -3,37 +3,65 @@ import fs.smbfs from fs.walk import Walker +from .filepass_config import ConnectionDetails + # File Transfer Types -def sftp_connection(logger, user, pw, svr, port, dir): - logger.debug("sftp://{}:{}@{}:{}{}".format(user, "passwordhere", svr, port, dir)) - fs_conn = fs.open_fs("sftp://{}:{}@{}:{}{}".format(user, pw, svr, port, dir)) +def sftp_connection(logger, conn_details: ConnectionDetails): + logger.debug( + "sftp://{}:{}@{}:{}{}".format( + conn_details.user, + "passwordhere", + conn_details.server, + conn_details.port, + conn_details.dir, + ) + ) + fs_conn = fs.open_fs( + "sftp://{}:{}@{}:{}{}".format( + conn_details.user, + conn_details.password, + conn_details.server, + conn_details.port, + conn_details.dir, + ) + ) return fs_conn -def smb_connection(logger, user, pw, svr, port, smbshare, dir): +def smb_connection(logger, conn_details: ConnectionDetails): logger.debug( - "smb://{}:{}@{}:{}/{}".format(user, "passwordhere", svr, port, smbshare + dir) + "smb://{}:{}@{}:{}/{}".format( + conn_details.user, + "passwordhere", + conn_details.server, + conn_details.port, + conn_details.share + conn_details.dir, + ) ) fs_conn = fs.open_fs( "smb://{}:{}@{}:{}/{}?direct-tcp=True&name-port=139&timeout=15&domain=".format( - user, pw, svr, port, smbshare + dir + conn_details.user, + conn_details.password, + conn_details.server, + conn_details.port, + conn_details.share + conn_details.dir, ) ) # timeout, name - port, direct - tcp, hostname, and domain. return fs_conn -def local_connection(logger, dir: str): +def local_connection(logger, conn_details: ConnectionDetails): """Establishes a connection to a directory on the local filesystem""" - logger.debug("local connection to {}".format(dir)) - fs_conn = fs.open_fs("{}".format(dir)) + logger.debug("local connection to {}".format(conn_details.dir)) + fs_conn = fs.open_fs("{}".format(conn_details.dir)) return fs_conn -def osfs_connection(logger, dir): - logger.debug("osfs dir: {}".format(dir)) - fs_conn = fs.open_fs(dir) +def osfs_connection(logger, conn_details: ConnectionDetails): + logger.debug("osfs dir: {}".format(conn_details.dir)) + fs_conn = fs.open_fs(conn_details.dir) return fs_conn @@ -45,65 +73,29 @@ def transfer_file(from_fs, to_fs, filename, should_rename=False, new_filename=No def file_pass( logger, - from_user, - from_pw, - from_svr, - from_port, - from_dir, - from_share, - from_method, + from_conn: ConnectionDetails, from_delete, from_filter, - to_user, - to_pw, - to_svr, - to_port, - to_dir, - to_share, - to_method, + to_conn: ConnectionDetails, to_delete, new_filename=None, ): - # From File System - if from_method == "sftp": - logger.debug("Create from SFTP connection") - from_fs = sftp_connection( - logger, from_user, from_pw, from_svr, from_port, from_dir - ) - - if from_method == "smb": - logger.debug("Create from SMB connection") - from_fs = smb_connection( - logger, from_user, from_pw, from_svr, from_port, from_share, from_dir - ) + connection_functions = { + "sftp": sftp_connection, + "smb": smb_connection, + "local": local_connection, + "osfs": osfs_connection, + } - 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) + from_fs = connection_functions[from_conn.method](logger, from_conn) + to_fs = connection_functions[to_conn.method](logger, to_conn) + logger.debug( + f"Establishing connection 'from' server: {from_conn.server}, using method: {from_conn.method} \n Directory selected: {from_conn.dir}" + ) + logger.debug( + f"Establishing connection 'to' server: {to_conn.server}, using method: {to_conn.method} \n Directory selected: {to_conn.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. diff --git a/src/filepass/filepass_config.py b/src/filepass/filepass_config.py new file mode 100644 index 0000000..ee094a4 --- /dev/null +++ b/src/filepass/filepass_config.py @@ -0,0 +1,18 @@ +class ConnectionDetails: + def __init__( + self, + method, + user=None, + password=None, + server=None, + port=None, + dir=None, + share=None, + ): + self.method = method + self.user = user + self.password = password + self.server = server + self.port = port + self.dir = dir + self.share = share From 061c302510a831e5f451c84f16d0ccc7fcd7b73a Mon Sep 17 00:00:00 2001 From: Parul Date: Thu, 22 Feb 2024 08:01:41 -0800 Subject: [PATCH 2/7] remove redundant code block for local_connection --- src/filepass/__init__.py | 8 +------- src/filepass/filepass.py | 11 ++--------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/filepass/__init__.py b/src/filepass/__init__.py index 77d4730..4e56e27 100644 --- a/src/filepass/__init__.py +++ b/src/filepass/__init__.py @@ -1,10 +1,4 @@ -from .filepass import ( - file_pass, - local_connection, - osfs_connection, - sftp_connection, - smb_connection, -) +from .filepass import file_pass, osfs_connection, sftp_connection, smb_connection from .filepass_config import ConnectionDetails __all__ = [ diff --git a/src/filepass/filepass.py b/src/filepass/filepass.py index 449f5b8..bdb1daf 100644 --- a/src/filepass/filepass.py +++ b/src/filepass/filepass.py @@ -52,15 +52,8 @@ def smb_connection(logger, conn_details: ConnectionDetails): return fs_conn -def local_connection(logger, conn_details: ConnectionDetails): - """Establishes a connection to a directory on the local filesystem""" - logger.debug("local connection to {}".format(conn_details.dir)) - fs_conn = fs.open_fs("{}".format(conn_details.dir)) - return fs_conn - - def osfs_connection(logger, conn_details: ConnectionDetails): - logger.debug("osfs dir: {}".format(conn_details.dir)) + logger.debug("osfs/local connection to dir: {}".format(conn_details.dir)) fs_conn = fs.open_fs(conn_details.dir) return fs_conn @@ -83,7 +76,7 @@ def file_pass( connection_functions = { "sftp": sftp_connection, "smb": smb_connection, - "local": local_connection, + "local": osfs_connection, "osfs": osfs_connection, } From 5f035dfb4073af8525f9923f40178f35aeaae7bc Mon Sep 17 00:00:00 2001 From: Parul Date: Fri, 23 Feb 2024 14:20:33 -0800 Subject: [PATCH 3/7] add enum for connection object and add readme file --- README.md | 139 ++++++++++++++++++++++++++++++++ cli.py | 7 +- src/filepass/__init__.py | 4 +- src/filepass/filepass.py | 36 +++++++-- src/filepass/filepass_config.py | 57 ++++++++++++- 5 files changed, 230 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e69de29..4ccb373 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,139 @@ +# Filepass Package # + +Filepass package is a comprehensive Python package designed to facilitate the transfer of the files across different locations and protocols with ease. +It supports SFTP, SMB, and LOCAL file systems, and offers functionalities like file renaming (in single file mode) and selective file transfer based on assigned filter. +It also offeres advanced file management features such as conditional deletion of files. +With support for both custom handler and local logging, 'Filepass' ensures that you can keep a detailed log of your file trasnfers, making troubleshooting and monitoring a breeze. + + +## Features ## + +- **Multiple Protocols Support**: +Seamlessly transfer files using SFTP, SMB, and LOCAL file systems. + +- **Flexible File Selection**: +Use 'from_filter' parameter to specify exactly which files to transfer, supporting both specific filenames and wildcards for multiple files. + +- **File Renaming (in single file transfer mode)** +Easily rename files during single file transfer mode. + +- **Connection Objects**: +Utilize the pre-defined connnection objects for efficient and secure connections to server. + +- **Conditional File Deletion**: +Automatically delete older files at the destination before transfer using 'to_delete', or remove source files after a successful transfer using 'from_delete'. + +- **Advanced Logging**: +Enable custom logging handler by defining the server name, port number and adding the handler to the logger defined. Otherwise, default to local logging to stdout for monitoring and troubleshooting. + +## Installation ## + +pip install filepass + +## Quick Start ## +1. Import Filepass package: + e.g.: from filepass import file_pass, ConnectionDetails, FilepassMethod + +2. Set up connection - create a connection object (ConnectionDetails) based on your protocol of choice. FilepassMethod offers three protocols: SFTP, SMB, and LOCAL + e.g.: + ```sourceServer = ConnectionDetails( + method=FilepassMethod.SMB, + user="user", + password="password", + server="servername", + port="portnumber", + dir="directory/folder", + share="SMB share", + ) + + destinationServer = ConnectionDetails( + method=FilepassMethod.SFTP, + user="user", + password="password", + server="servername", + port="portnumber", + dir="directory/folder", + )``` + +3. Configure Logging: + (Optional) + If you want to enable custom handler logging, such as Graylog logging. Set the server details as follows: + Example: Graylog + * Import the required library for custom logging - import graypy + * Add the handler to your defined logger: + + ``` + handler = graypy. graypy.GELFTCPHandler( + ("servername"), int("portnumber") + ) + ``` + + If you want to simply use local logging: + * Import python logging package. + * Define the logger and handler. + * E.g., handler = logging.StreamHandler(sys.stdout) + * Add the handler to your defined logger. + +4. Define the required parameters for file transfer: + * from_filter = "filename/wildcard" + * e.g. + ```from_filter = "*.txt" #transfers all files in the directory, with .txt extension. + from_filter = "transfer_file.csv" #transfers the selected file.``` + * to_delete = "yes or no". + * from_delete = "yes or no". + * logger = set custom handler or local handler. + +5. Rename file in single file transfer mode: + Rename a file during transfer by specifying the new_filename parameter such as: + * e.g., ```new_filename = "newfilename"``` + Defaults to 'None', if parameter is not defined. + +6. Transfer Files: + Use the file_pass method to move files to move files from one location to another. + * e.g., + ``` + file_pass( + logger, + from_conn, + to_conn, + from_filter, + to_delete, + from_delete, + new_filename, + ) + ``` + +## Support ## +If you encounter any issues or have questions, please file an issue on our [GitHub Issues Page](https://github.com/cityofkamloops/filepass/issues) + +## Contributing ## +Contributions to Filepass are welcome! Please refer to our [Contribution Guidelines](https://docs.github.com/en/contributing) + ### Ways to Contribute ### + * Submit bug reports and feature requests. + * Write and improve documentation. + * Write code for new features and bug fixes. + * Review pull requests. + * Enhance the package's test coverage. + + ### Code of Conduct ### + - Participation in this project is governed by The City of Kamloops Code of Conduct. We expect everyone to uphold the principles of respect, kindness and cooperation. + + ### How to submit contributions ### + * Reporting bugs: + - Use the issue tracker to report bugs. + - Describe the bug and include steps to reproduce. + + * Feature Requests: + - Submit feature requests using the issue tracker. + - Please include an explanation why the feature would be useful, and how it should work if possible. + + * Pull Requests: + - Fork the repository and create your branch from 'main'. + - If you have added code, please include tests. + - Ensure your project lints and follows the project's coding conventions. + - Write a clear and descriptive commit message. + - Open a pull request with a clear title and description. + +## Thank you!! ## + +### Happy file transferring! ### diff --git a/cli.py b/cli.py index 55ce05e..d9c7343 100644 --- a/cli.py +++ b/cli.py @@ -4,7 +4,7 @@ import graypy -from src.filepass import ConnectionDetails, file_pass +from src.filepass import ConnectionDetails, FilepassMethod, file_pass def main(): @@ -12,7 +12,7 @@ def main(): # Connection objects from_conn = ConnectionDetails( - method=os.environ.get("FROMMETHOD"), + method=FilepassMethod.SFTP, user=os.environ.get("FROMUSER"), password=os.environ.get("FROMPW"), server=os.environ.get("FROMSVR"), @@ -22,7 +22,7 @@ def main(): ) to_conn = ConnectionDetails( - method=os.environ.get("TOMETHOD"), + method=FilepassMethod.SMB, user=os.environ.get("TOUSER"), password=os.environ.get("TOPW"), server=os.environ.get("TOSVR"), @@ -31,6 +31,7 @@ def main(): share=os.environ.get("TOSMBSHARE"), ) + # Parameters required by file_pass from_delete = os.environ.get("FROMDELETE") from_filter = os.environ.get("FROMFILEFILTER") to_delete = os.environ.get("TODELETE") diff --git a/src/filepass/__init__.py b/src/filepass/__init__.py index 4e56e27..27e9950 100644 --- a/src/filepass/__init__.py +++ b/src/filepass/__init__.py @@ -1,11 +1,11 @@ from .filepass import file_pass, osfs_connection, sftp_connection, smb_connection -from .filepass_config import ConnectionDetails +from .filepass_config import ConnectionDetails, FilepassMethod __all__ = [ "ConnectionDetails", + "FilepassMethod", "sftp_connection", "smb_connection", - "local_connection", "osfs_connection", "file_pass", ] diff --git a/src/filepass/filepass.py b/src/filepass/filepass.py index bdb1daf..6ff17ee 100644 --- a/src/filepass/filepass.py +++ b/src/filepass/filepass.py @@ -3,11 +3,18 @@ import fs.smbfs from fs.walk import Walker -from .filepass_config import ConnectionDetails +from .filepass_config import ConnectionDetails, FilepassMethod # File Transfer Types def sftp_connection(logger, conn_details: ConnectionDetails): + """ + Establishes an SFTP connection based on provided connection details. + Parameters: + logger (Logger): logger object for logging messages. + conn_details: Object containing connection details: user, password, server, port and directory (required). + port defaults to '22', if not explictly defined. + """ logger.debug( "sftp://{}:{}@{}:{}{}".format( conn_details.user, @@ -30,6 +37,13 @@ def sftp_connection(logger, conn_details: ConnectionDetails): def smb_connection(logger, conn_details: ConnectionDetails): + """ + Establishes an SMB connection based on provided connection details. + Parameters: + logger (Logger): logger object for logging messages. + conn_details: Object containing connection details: user, password, server, port, share, and directory (required). + port defaults to '445', if not explictly defined. + """ logger.debug( "smb://{}:{}@{}:{}/{}".format( conn_details.user, @@ -53,6 +67,12 @@ def smb_connection(logger, conn_details: ConnectionDetails): def osfs_connection(logger, conn_details: ConnectionDetails): + """ + Establishes an LOCAL connection based on provided connection details. + Parameters: + logger (Logger): logger object for logging messages. + conn_details: Object containing connection details: directory (required). + """ logger.debug("osfs/local connection to dir: {}".format(conn_details.dir)) fs_conn = fs.open_fs(conn_details.dir) return fs_conn @@ -60,6 +80,9 @@ def osfs_connection(logger, conn_details: ConnectionDetails): # 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): + """ + Transfer file using 'fs' and rename file in single file mode (new_filename required) + """ target_filename = new_filename if new_filename and should_rename else filename to_fs.writefile(target_filename, from_fs.open(filename, "rb")) @@ -74,20 +97,19 @@ def file_pass( new_filename=None, ): connection_functions = { - "sftp": sftp_connection, - "smb": smb_connection, - "local": osfs_connection, - "osfs": osfs_connection, + FilepassMethod.SFTP: sftp_connection, + FilepassMethod.SMB: smb_connection, + FilepassMethod.LOCAL: osfs_connection, } from_fs = connection_functions[from_conn.method](logger, from_conn) to_fs = connection_functions[to_conn.method](logger, to_conn) logger.debug( - f"Establishing connection 'from' server: {from_conn.server}, using method: {from_conn.method} \n Directory selected: {from_conn.dir}" + f"Establishing {from_conn.method} connection from server: {from_conn.server}\n Directory: {from_conn.dir}" ) logger.debug( - f"Establishing connection 'to' server: {to_conn.server}, using method: {to_conn.method} \n Directory selected: {to_conn.dir}" + f"Establishing {to_conn.method} connection from server: {to_conn.server}\n Directory: {to_conn.dir}" ) # Do the move walker = Walker(filter=[from_filter], ignore_errors=True, max_depth=1) diff --git a/src/filepass/filepass_config.py b/src/filepass/filepass_config.py index ee094a4..dd95d93 100644 --- a/src/filepass/filepass_config.py +++ b/src/filepass/filepass_config.py @@ -1,7 +1,17 @@ +from enum import Enum + + +# Define Enum for methods in Filepass +class FilepassMethod(str, Enum): + SFTP = "sftp" + SMB = "smb" + LOCAL = "local" + + class ConnectionDetails: def __init__( self, - method, + method: FilepassMethod, user=None, password=None, server=None, @@ -16,3 +26,48 @@ def __init__( self.port = port self.dir = dir self.share = share + # Ensure all required values are provided + self._validate_parameters() + + # Validate parameter values provided to Connection Objects and raise errors if required. + def _validate_parameters(self): + # Validate LOCAL connection details, required fields: 'dir' + if self.method == FilepassMethod.LOCAL: + if not self.dir: + raise ValueError(f"{self.method.name} connection requires 'dir' .") + + # Validate SFTP connection deatils, required fields: 'user', 'password', 'server', 'dir', 'port'. + # If port number is not defined, revert to default value - '22' + + # Validate SMB connection details, required fields: 'user', 'password', 'server', 'dir', 'share', 'port'. + # If port number not defined , revert to default value - '445' + elif self.method in [FilepassMethod.SMB, FilepassMethod.SFTP]: + if not self.user: + raise ValueError("(user) value missing (required). ", self.user) + + if not self.password: + raise ValueError("(password) value missing (required)", self.password) + + if not self.dir: + raise ValueError("Directory (dir) value missing (required)", self.dir) + + if not self.server: + raise ValueError("(server) value missing (required) ", self.server) + + if not self.port: + if self.method == FilepassMethod.SMB: + self.port = 445 + + else: + self.port = 22 + + if self.method == FilepassMethod.SMB and not self.share: + raise ValueError( + "SMBShare (share) value missing (required)", self.share + ) + + # Validate Filepass method called + else: + raise ValueError( + f"Unsupported Connection Method: {self.method}. \n Please choose a supported method: SFTP, SMB or LOCAL." + ) From a13cf5b4f5a1cb13a95989da59b3c0dbfa3401b5 Mon Sep 17 00:00:00 2001 From: Parul Date: Fri, 23 Feb 2024 14:31:26 -0800 Subject: [PATCH 4/7] format readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ccb373..6b6fca1 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,8 @@ pip install filepass 2. Set up connection - create a connection object (ConnectionDetails) based on your protocol of choice. FilepassMethod offers three protocols: SFTP, SMB, and LOCAL e.g.: - ```sourceServer = ConnectionDetails( + ``` + sourceServer = ConnectionDetails( method=FilepassMethod.SMB, user="user", password="password", @@ -53,7 +54,8 @@ pip install filepass server="servername", port="portnumber", dir="directory/folder", - )``` + ) + 3. Configure Logging: (Optional) From 226d22796cbb0e2e66708e10d2b16b4926806817 Mon Sep 17 00:00:00 2001 From: Parul Date: Fri, 23 Feb 2024 14:35:40 -0800 Subject: [PATCH 5/7] reformat readme --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6b6fca1..63e6676 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,9 @@ pip install filepass 2. Set up connection - create a connection object (ConnectionDetails) based on your protocol of choice. FilepassMethod offers three protocols: SFTP, SMB, and LOCAL e.g.: - ``` + + ```python + sourceServer = ConnectionDetails( method=FilepassMethod.SMB, user="user", @@ -55,6 +57,7 @@ pip install filepass port="portnumber", dir="directory/folder", ) + ``` 3. Configure Logging: @@ -64,7 +67,7 @@ pip install filepass * Import the required library for custom logging - import graypy * Add the handler to your defined logger: - ``` + ```python handler = graypy. graypy.GELFTCPHandler( ("servername"), int("portnumber") ) @@ -79,7 +82,8 @@ pip install filepass 4. Define the required parameters for file transfer: * from_filter = "filename/wildcard" * e.g. - ```from_filter = "*.txt" #transfers all files in the directory, with .txt extension. + ```python + from_filter = "*.txt" #transfers all files in the directory, with .txt extension. from_filter = "transfer_file.csv" #transfers the selected file.``` * to_delete = "yes or no". * from_delete = "yes or no". @@ -87,13 +91,17 @@ pip install filepass 5. Rename file in single file transfer mode: Rename a file during transfer by specifying the new_filename parameter such as: - * e.g., ```new_filename = "newfilename"``` + * e.g., + ```python + new_filename = "newfilename" + ``` + Defaults to 'None', if parameter is not defined. 6. Transfer Files: Use the file_pass method to move files to move files from one location to another. * e.g., - ``` + ```python file_pass( logger, from_conn, From afcb508992fdd33b2b6cccb8fb3cba8101e96dda Mon Sep 17 00:00:00 2001 From: Parul Date: Fri, 23 Feb 2024 14:38:17 -0800 Subject: [PATCH 6/7] reformat readme --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 63e6676..75413a8 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,13 @@ pip install filepass ## Quick Start ## 1. Import Filepass package: - e.g.: from filepass import file_pass, ConnectionDetails, FilepassMethod + e.g.: + ```from filepass import file_pass, ConnectionDetails, FilepassMethod``` 2. Set up connection - create a connection object (ConnectionDetails) based on your protocol of choice. FilepassMethod offers three protocols: SFTP, SMB, and LOCAL e.g.: ```python - sourceServer = ConnectionDetails( method=FilepassMethod.SMB, user="user", @@ -47,8 +47,7 @@ pip install filepass port="portnumber", dir="directory/folder", share="SMB share", - ) - + ) destinationServer = ConnectionDetails( method=FilepassMethod.SFTP, user="user", From 41702d25f773b253817a8184fc92e6952a021349 Mon Sep 17 00:00:00 2001 From: Parul Date: Mon, 26 Feb 2024 08:03:35 -0800 Subject: [PATCH 7/7] reformat ReadME to ensure formatting --- README.md | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 75413a8..2888c9b 100644 --- a/README.md +++ b/README.md @@ -115,33 +115,34 @@ pip install filepass ## Support ## If you encounter any issues or have questions, please file an issue on our [GitHub Issues Page](https://github.com/cityofkamloops/filepass/issues) + ## Contributing ## Contributions to Filepass are welcome! Please refer to our [Contribution Guidelines](https://docs.github.com/en/contributing) - ### Ways to Contribute ### - * Submit bug reports and feature requests. - * Write and improve documentation. - * Write code for new features and bug fixes. - * Review pull requests. - * Enhance the package's test coverage. - - ### Code of Conduct ### - - Participation in this project is governed by The City of Kamloops Code of Conduct. We expect everyone to uphold the principles of respect, kindness and cooperation. - - ### How to submit contributions ### - * Reporting bugs: - - Use the issue tracker to report bugs. - - Describe the bug and include steps to reproduce. - - * Feature Requests: - - Submit feature requests using the issue tracker. - - Please include an explanation why the feature would be useful, and how it should work if possible. - - * Pull Requests: - - Fork the repository and create your branch from 'main'. - - If you have added code, please include tests. - - Ensure your project lints and follows the project's coding conventions. - - Write a clear and descriptive commit message. - - Open a pull request with a clear title and description. +### Ways to Contribute ### + * Submit bug reports and feature requests. + * Write and improve documentation. + * Write code for new features and bug fixes. + * Review pull requests. + * Enhance the package's test coverage. + +### Code of Conduct ### + - Participation in this project is governed by The City of Kamloops Code of Conduct. We expect everyone to uphold the principles of respect, kindness and cooperation. + +### How to submit contributions ### +* Reporting bugs: + - Use the issue tracker to report bugs. + - Describe the bug and include steps to reproduce. + +* Feature Requests: + - Submit feature requests using the issue tracker. + - Please include an explanation why the feature would be useful, and how it should work if possible. + +* Pull Requests: + - Fork the repository and create your branch from 'main'. + - If you have added code, please include tests. + - Ensure your project lints and follows the project's coding conventions. + - Write a clear and descriptive commit message. + - Open a pull request with a clear title and description. ## Thank you!! ##