-
-
Save gfreezy/1324544 to your computer and use it in GitHub Desktop.
Sync files between remote and local with rsync
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
#!/usr/bin/env python | |
import os | |
import sys | |
import subprocess | |
APP = 'demo_app' | |
REMOTE_USER = 'gfreezy' | |
REMOTE_HOST = 'norida.me' | |
REMOTE_DIR = '/home/gfreezy/rails/' | |
REMOTE_PATH = os.path.normpath(os.path.join(REMOTE_DIR, APP)) | |
REMOTE_PARAM = '%s@%s:%s/' % (REMOTE_USER, REMOTE_HOST, REMOTE_PATH) | |
LOCAL_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
LOCAL_PATH = os.path.normpath(os.path.join(LOCAL_DIR, APP)) | |
LOCAL_PARAM = '%s/' % LOCAL_PATH | |
CMD = 'rsync' | |
EXCLUDES = [ | |
'sync', | |
] | |
CMD_PARAM = '''-za --delete''' | |
def excludes(): | |
global CMD_PARAM | |
for exclude in EXCLUDES: | |
CMD_PARAM += ' --exclude "%s"' % exclude | |
excludes() | |
def push(): | |
cmd_str = ' '.join([CMD, CMD_PARAM, LOCAL_PARAM, REMOTE_PARAM]) | |
print cmd_str | |
subprocess.call(cmd_str, shell=True) | |
def pull(): | |
cmd_str = ' '.join([CMD, CMD_PARAM, REMOTE_PARAM, LOCAL_PARAM]) | |
print cmd_str | |
subprocess.call(cmd_str, shell=True) | |
def main(): | |
if sys.argv[1] == 'push': | |
push() | |
elif sys.argv[1] == 'pull': | |
pull() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment