Skip to content

Instantly share code, notes, and snippets.

@akiraak
Created November 4, 2015 13:47
Show Gist options
  • Save akiraak/1e3e26231a00e0db0d20 to your computer and use it in GitHub Desktop.
Save akiraak/1e3e26231a00e0db0d20 to your computer and use it in GitHub Desktop.
$ ./watch_rsync
---- watch_rsync ----
#!/bin/sh
fswatch --exclude="/.git/" --exclude="/target/" -x ../ | xargs -I "file_path" ./conv_rsync_path.py "file_path"
---- watch_rsync ----
---- conv_rsync_path.py ----
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
if __name__ == "__main__":
args = sys.argv[1]
path = args.split(" ")[0]
events = args.split(" ")[1:]
if "Removed" in events:
rsync_path = os.path.dirname(path) + '/'
else:
rsync_path = path
base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
print "base_dir: " + base_dir
rsync_path = rsync_path.replace(base_dir + '/', '')
print "rsync_path: " + rsync_path
os.system("cd ../")
rsync_command = 'rsync --recursive --delete {src_path} {dst_path}'.format(
src_path="../{0}".format(rsync_path),
dst_path="g-vpn:~/project/{0}".format(rsync_path)
)
print "rsync_command: " + rsync_command
os.system(rsync_command)
---- conv_rsync_path.py ----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment