-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from uzh-dqbm-cmi/initialization
Initialization
- Loading branch information
Showing
6 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,34 @@ | ||
# code-sync | ||
# code_sync | ||
Python utility for syncing code to a remote machine in the background | ||
|
||
## Installation | ||
`pip install code_sync` | ||
|
||
## Usage | ||
|
||
After installing this package, the `code_sync` tool will be available from the command line. | ||
|
||
The `code_sync` script allows you to auto-sync any changes to code in a local directory to a remote machine. | ||
Under the hood, it is running an `rsync` command whenever `watchdog` notices changes to the code. | ||
|
||
### Example usage | ||
Assuming you have defined `my_remote_machine` in your ssh config: | ||
|
||
`code_sync --local_dir mylocaldir/ --remote_dir myremotedir/ --target my_remote_machine --port 2222` | ||
|
||
### Notes | ||
**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 happen until a file in the `local_dir` is touched. This is normal! | ||
|
||
**Stopping** | ||
* You can safely quit `code_sync` with control-c. | ||
|
||
**About `code_sync` + `git`** | ||
* The destination directory should not be treated as an active git repo. | ||
The destination dir must exist already, but need not already be empty. | ||
If the destination directory is a git repo already, it will be overwritten with the "git state" of the local git directory. | ||
* **Do not run git commands from the destination terminal** on the destination directory. | ||
The destination dir will have its contents synced to exactly match the local dir, including when you checkout a different branch on local. | ||
* The sync command adheres to any filters set by `.gitignore` files within the specified directories. | ||
It also excludes `.git` and `.ipynb` files. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#! python | ||
|
||
import argparse | ||
import os | ||
import subprocess | ||
|
||
cmd_str = 'watchmedo shell-command --recursive --patterns="{local_dir}*" --command="rsync --filter=\':- .gitignore\' ' \ | ||
'--exclude \'*.ipynb\' --exclude \'.git\' --delete-after -rz --port {port} {local_dir} ' \ | ||
'{target}:{remote_dir}" {local_dir}' | ||
|
||
epilog_str = ''' | ||
Example for connecting to LeoMed: | ||
code_sync --local_dir mylocaldir/ --remote_dir myremotedir/ --target medinfmk --port 2222\n | ||
''' | ||
|
||
|
||
def code_sync(local_dir, remote_dir, target, port=22): | ||
# clean up slashes | ||
local_dir = os.path.join(local_dir, '') | ||
remote_dir = os.path.join(remote_dir, '') | ||
|
||
# subprocess.call() | ||
cmd = cmd_str.format(local_dir=local_dir, remote_dir=remote_dir, target=target, port=port) | ||
subprocess.call(cmd, shell=True) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, epilog=epilog_str) | ||
parser.add_argument('--local_dir', help='the local code directory you want to sync', required=True) | ||
parser.add_argument('--remote_dir', help='the remote directory you want to sync', required=True) | ||
parser.add_argument('--target', help='specify which remote machine to connect to', required=True) | ||
parser.add_argument('--port', type=int, help='ssh port for connecting to remote', default=22) | ||
|
||
args = parser.parse_args() | ||
|
||
code_sync(local_dir=args.local_dir, remote_dir=args.remote_dir, target=args.target, port=args.port) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
max-line-length = 120 | ||
exclude = .git,__pycache__,tests,docs,build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup(name='code_sync', | ||
version='0.0.1', | ||
description='', | ||
url='https://github.com/uzh-dqbm-cmi/code-sync', | ||
packages=find_packages(), | ||
python_requires='>3.6.0', | ||
install_requires=[ | ||
'watchdog', | ||
'pyyaml', | ||
'argh', | ||
], | ||
entry_points={ | ||
'console_scripts': [ | ||
'code_sync = code_sync.code_sync:main', | ||
] | ||
}, | ||
zip_safe=False) |