Skip to content

Instantly share code, notes, and snippets.

@gfreezy
Created October 29, 2011 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfreezy/1324544 to your computer and use it in GitHub Desktop.
Save gfreezy/1324544 to your computer and use it in GitHub Desktop.
Sync files between remote and local with rsync
#!/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