From 5ec8cb542db6e273f42ba7aa5fb9f134b4c66e66 Mon Sep 17 00:00:00 2001 From: Parul Date: Mon, 12 Feb 2024 15:47:31 -0800 Subject: [PATCH] minor version 0.2.0 --- .gitignore | 3 ++ LICENSE | 0 README.md | 0 pyproject.toml | 24 +++++++++ requirements.txt | 20 +++++-- src/filepass/__init__.py | 2 +- src/filepass/filepass.py | 111 --------------------------------------- 7 files changed, 45 insertions(+), 115 deletions(-) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index 93a7d74..0da3226 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ .idea *.egg-info __pycache__ +/dist +*.env +test.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..87aec4d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,24 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "filepass" +version = "0.2.0" +authors = [ + { name="Orlund Norstrom", email="onorstrom@kamloops.ca" }, + { name="Marco Lussetti", email="mlussetti@kamloops.ca" }, + { name="Parul Parul", email="pparul@kamloops.ca" }, +] +description = "Wrapper around fs libraries to synchronized files between different system types including SMB, SFTP, FSTP." +readme = "README.md" +license = { file="LICENSE" } +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", +] + +[project.urls] +"Homepage" = "https://github.com/cityofkamloops/filepass" +"Bug Tracker" = "https://github.com/cityofkamloops/filepass/issues" diff --git a/requirements.txt b/requirements.txt index 0f3e418..43dc3f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,28 +1,42 @@ appdirs==1.4.4 bcrypt==3.2.0 black==21.11b1 +build==1.0.3 cffi==1.14.5 +cfgv==3.4.0 click==8.0.3 colorama==0.4.4 cryptography==3.4.7 +distlib==0.3.8 +filelock==3.13.1 fs==2.4.13 -fs.smbfs==1.0.2 +fs.smbfs==1.0.7 fs.sshfs==1.0.0 ftpfs==0.2 fusepy==3.0.1 graypy==2.1.0 +identify==2.5.33 mypy-extensions==0.4.3 +nodeenv==1.8.0 +packaging==23.2 paramiko==2.7.2 pathspec==0.9.0 platformdirs==2.4.0 +pre-commit==3.6.0 property-cached==1.6.4 pyasn1==0.4.8 pycparser==2.20 PyNaCl==1.4.0 -pysmb==1.2.7 +pyproject_hooks==1.0.0 +pysmb==1.2.9.1 +pyspnego==0.10.2 pytz==2021.1 +PyYAML==6.0.1 regex==2021.11.10 scp==0.13.5 six==1.16.0 +smbprotocol==1.12.0 tomli==1.2.2 -typing-extensions==4.0.1 +tqdm==4.66.2 +typing_extensions==4.0.1 +virtualenv==20.25.0 diff --git a/src/filepass/__init__.py b/src/filepass/__init__.py index d89a17e..d169ea3 100644 --- a/src/filepass/__init__.py +++ b/src/filepass/__init__.py @@ -1 +1 @@ -from .filepass import file_pass, ftps_connection, smb_connection, ssh_connection +from .filepass import file_pass, smb_connection, ssh_connection diff --git a/src/filepass/filepass.py b/src/filepass/filepass.py index 72db5ad..27a6f37 100644 --- a/src/filepass/filepass.py +++ b/src/filepass/filepass.py @@ -1,11 +1,6 @@ -import logging -import os -import sys - import fs import fs.ftpfs import fs.smbfs -import graypy from fs.walk import Walker @@ -29,17 +24,6 @@ def smb_connection(logger, user, pw, svr, port, smbshare, dir): return fs_conn -def ftps_connection(logger, user, pw, svr, port, tls, dir): - logger.debug( - "ftps host: {} user: {} password: {} port: {} tls: {} dir: {}".format( - svr, user, "passwordhere", port, tls, dir - ) - ) - # fs_conn = fs.ftpfs.FTPFS(host=svr, user=user, passwd=pw, port=port, tls=tls) - fs_conn = fs.open_fs("ftps://{}:{}@{}/{}".format(user, pw, svr, dir)) - return fs_conn - - def transfer_file(from_fs, to_fs, filename): to_fs.writefile(filename, from_fs.open(filename, "rb")) @@ -77,12 +61,6 @@ def file_pass( logger, from_user, from_pw, from_svr, from_port, from_share, from_dir ) - if from_method == "ftps": - logger.debug("Create from FTPS connection") - from_fs = ftps_connection( - logger, from_user, from_pw, from_svr, from_port, True, from_dir - ) - # To File System if to_method == "ssh": logger.debug("Create to SSH connection") @@ -92,9 +70,6 @@ def file_pass( to_fs = smb_connection( logger, to_user, to_pw, to_svr, to_port, to_share, to_dir ) - if to_method == "ftps": - logger.debug("Create to FTPS connection") - to_fs = ftps_connection(logger, to_user, to_pw, to_svr, to_port, True, to_dir) # Do the move walker = Walker(filter=[from_filter], ignore_errors=True, max_depth=1) @@ -132,89 +107,3 @@ def file_pass( from_fs.close() to_fs.close() - - -def main(): - # Load Environmental Variables - - # GREYLOG_SERVER - # GREYLOG_PORT - # INTEGRATION_NAME - - 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") - - filepass_logger = logging.getLogger("filepass_logger") - filepass_logger.setLevel(logging.DEBUG) - - handler = graypy.GELFTCPHandler( - os.environ.get("GREYLOG_SERVER"), int(os.environ.get("GREYLOG_PORT")) - ) - filepass_logger.addHandler(handler) - - handler_std = logging.StreamHandler(sys.stdout) - filepass_logger.addHandler(handler_std) - - 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_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, - "integration": "filepass", - "filepass_name": os.environ.get("INTEGRATION_NAME"), - }, - ) - try: - file_pass( - logger, - from_user, - from_pw, - from_svr, - from_port, - from_dir, - from_share, - from_method, - from_delete, - from_filter, - to_user, - to_pw, - to_svr, - to_port, - to_dir, - to_share, - to_method, - to_delete, - ) - except: - logger.exception("Critical error found", stack_info=True) - - -if __name__ == "__main__": - main()