From 98317434777fceb74f1e388c9d73702d71841c2e Mon Sep 17 00:00:00 2001 From: Masato Onodera Date: Tue, 27 Aug 2024 17:28:19 -1000 Subject: [PATCH] allow transfer targets from local to local --- src/targetdb/utils.py | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/targetdb/utils.py b/src/targetdb/utils.py index ea5adc5..feb1d6c 100644 --- a/src/targetdb/utils.py +++ b/src/targetdb/utils.py @@ -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)