Skip to content

Commit

Permalink
local os support for file transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
sparul93 committed Feb 16, 2024
1 parent 7651d50 commit 15581a3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "filepass"
version = "0.3.0"
version = "0.4.0"
authors = [
{ name="Orlund Norstrom", email="[email protected]" },
{ name="Marco Lussetti", email="[email protected]" },
Expand Down
8 changes: 7 additions & 1 deletion src/filepass/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
)
30 changes: 30 additions & 0 deletions src/filepass/filepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 15581a3

Please sign in to comment.