From b673e3466d70d2c6a175f2b13e7790f554f16e49 Mon Sep 17 00:00:00 2001 From: lokijuhy Date: Tue, 22 Jun 2021 11:39:36 +0200 Subject: [PATCH 1/4] run initial sync at startup and verbose flag --- code_sync/code_sync.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/code_sync/code_sync.py b/code_sync/code_sync.py index e87f9d3..dd8c79d 100644 --- a/code_sync/code_sync.py +++ b/code_sync/code_sync.py @@ -8,9 +8,11 @@ from typing import Dict -cmd_str = 'watchmedo shell-command --recursive --patterns="{local_dir}*" --command="rsync --filter=\':- .gitignore\' ' \ +rsync_cmd_str = 'rsync --filter=\':- .gitignore\' ' \ '--exclude \'*.ipynb\' --exclude \'.git\' --delete-after -rz --port {port} {local_dir} ' \ - '{target}:{remote_dir}" {local_dir}' + '{target}:{remote_dir}' + +cmd_str = 'watchmedo shell-command --recursive --patterns="{local_dir}*" --command="{rsync_cmd}" {local_dir}' epilog_str = ''' EXAMPLE USAGE @@ -31,15 +33,26 @@ CONFIG_FILE_NAME = '.code_sync' -def code_sync(local_dir, remote_dir, target, port=22): +def code_sync(local_dir, remote_dir, target, port=22, verbose=False): # clean up slashes + local_dir = os.path.expanduser(local_dir) local_dir = os.path.join(local_dir, '') remote_dir = os.path.join(remote_dir, '') print(f"Starting code_sync between {local_dir} and {target}:{remote_dir} ...") + rsync_cmd = rsync_cmd_str.format(local_dir=local_dir, remote_dir=remote_dir, target=target, port=port) + print('Running startup sync:') + if verbose: + print('Running command: {}'.format(rsync_cmd)) + subprocess.call(rsync_cmd, shell=True) + print(' ... startup sync complete.') + + watchmedo_cmd = cmd_str.format(rsync_cmd=rsync_cmd, local_dir=local_dir) + print('Code-sync running') + if verbose: + print('Running command: {}'.format(watchmedo_cmd)) print('(^C to quit)') - cmd = cmd_str.format(local_dir=local_dir, remote_dir=remote_dir, target=target, port=port) - subprocess.call(cmd, shell=True) + subprocess.call(watchmedo_cmd, shell=True) def get_config_file_path() -> Path: @@ -172,6 +185,7 @@ def main(): parser.add_argument('--remote_dir', help='The remote directory you want to sync', required=False) parser.add_argument('--target', help='Specify which remote machine to connect to', required=False) parser.add_argument('--port', type=int, help='ssh port for connecting to remote', default=22) + parser.add_argument('--verbose', help='Print verbose output', default=False, action='store_true') args = parser.parse_args() if args.register is not None: @@ -181,7 +195,7 @@ def main(): else: params = identify_code_sync_parameters(args) code_sync(local_dir=params['local_dir'], remote_dir=params['remote_dir'], target=params['target'], - port=params['port']) + port=params['port'], verbose=args.verbose) if __name__ == '__main__': From 426928918c51dd46c513c96fdfca4d77ede88cd5 Mon Sep 17 00:00:00 2001 From: lokijuhy Date: Tue, 22 Jun 2021 11:43:22 +0200 Subject: [PATCH 2/4] update docs re startup sync --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9b3ee91..dfb7f6b 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,6 @@ This command will use the configuration you set for the project when you registe **Starting** * In order to run `code_sync`, you must have an ssh connection open in another window. Once you've entered your password there, `code_sync` uses that connection. -* When you start this script, nothing will be synced until a file in the `local_dir` is touched. This is normal! * The destination dir must exist already, but need not be empty. **Stopping** From f3a02b51e7758a2d4d734aafe240b535cc51e1fd Mon Sep 17 00:00:00 2001 From: lokijuhy Date: Tue, 22 Jun 2021 11:56:22 +0200 Subject: [PATCH 3/4] version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 43ab5c6..4726ac0 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='code_sync', - version='0.1.0', + version='0.2.0', description='', url='https://github.com/uzh-dqbm-cmi/code-sync', packages=find_packages(), From 5a11fad9e21f1ec12bd4d82fd476c33193405a14 Mon Sep 17 00:00:00 2001 From: lokijuhy Date: Tue, 22 Jun 2021 12:09:56 +0200 Subject: [PATCH 4/4] bugfix: port set as local dir --- code_sync/code_sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_sync/code_sync.py b/code_sync/code_sync.py index dd8c79d..e5ffb17 100644 --- a/code_sync/code_sync.py +++ b/code_sync/code_sync.py @@ -172,7 +172,7 @@ def identify_code_sync_parameters(args) -> Dict: parameters['local_dir'] = args.local_dir parameters['remote_dir'] = args.remote_dir parameters['target'] = args.target - parameters['port'] = args.local_dir + parameters['port'] = args.port return parameters