Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local os support for file transfer #6

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading