Skip to content

Commit

Permalink
Merge pull request #100 from Subaru-PFS/u/monodera/cli_localhost
Browse files Browse the repository at this point in the history
allow transfer targets from local to local
  • Loading branch information
monodera authored Aug 28, 2024
2 parents bf6dc61 + 9831743 commit 22742b7
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/targetdb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,29 +1206,44 @@ def transfer_data_from_uploader(df, config, local_dir=Path("."), force=False):
source_dir = os.path.join(
config["uploader"]["data_dir"], f"????/??/????????-??????-{upload_id}"
)
dest_dir = local_dir
dest_dir = local_dir.as_posix()
logger.info(
f"Searching for the source directory on the remote host: {source_dir}"
)

# Construct the rsync command
if "user" in config["uploader"].keys() and config["uploader"]["user"] != "":
rsync_remote = f"{config['uploader']['user']}@{config['uploader']['host']}:{source_dir}"
if config["uploader"]["host"] == "localhost":
rsync_remote = f"{source_dir}"
# rsync_command = [
# "rsync",
# "-av",
# rsync_remote,
# dest_dir,
# ]
rsync_command = f"rsync -av {rsync_remote} {dest_dir}"
use_shell = True
else:
rsync_remote = f"{config['uploader']['host']}:{source_dir}"

rsync_command = [
"rsync",
"-avz",
"-e",
"ssh",
rsync_remote,
dest_dir,
]
if (
"user" in config["uploader"].keys()
and config["uploader"]["user"] != ""
):
rsync_remote = f"{config['uploader']['user']}@{config['uploader']['host']}:{source_dir}"
else:
rsync_remote = f"{config['uploader']['host']}:{source_dir}"

rsync_command = [
"rsync",
"-avz",
"-e",
"ssh",
rsync_remote,
dest_dir,
]
use_shell = False

# Execute the rsync command
try:
subprocess.run(rsync_command, check=True)
subprocess.run(rsync_command, shell=use_shell, check=True)
except subprocess.CalledProcessError as e:
logger.error(f"Failed to transfer data for upload_id: {upload_id}")
logger.error(e)
Expand Down

0 comments on commit 22742b7

Please sign in to comment.