Skip to content

Commit

Permalink
minor version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sparul93 committed Feb 12, 2024
1 parent 3df6c39 commit 5ec8cb5
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 115 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.idea
*.egg-info
__pycache__
/dist
*.env
test.py
Empty file added LICENSE
Empty file.
Empty file added README.md
Empty file.
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "filepass"
version = "0.2.0"
authors = [
{ name="Orlund Norstrom", email="[email protected]" },
{ name="Marco Lussetti", email="[email protected]" },
{ name="Parul Parul", email="[email protected]" },
]
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"
20 changes: 17 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/filepass/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .filepass import file_pass, ftps_connection, smb_connection, ssh_connection
from .filepass import file_pass, smb_connection, ssh_connection
111 changes: 0 additions & 111 deletions src/filepass/filepass.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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"))

Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit 5ec8cb5

Please sign in to comment.