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** diff --git a/code_sync/code_sync.py b/code_sync/code_sync.py index e87f9d3..e5ffb17 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: @@ -159,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 @@ -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__': 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(),