sync-todo (905B)
1 #!/usr/bin/env python 2 3 from subprocess import call, PIPE 4 import os 5 import socket 6 import sys 7 8 remotes = { 9 'quiver': "172.24.129.211", 10 'monad': "172.24.242.111" 11 }; 12 13 DEVNULL = open(os.devnull, 'w') 14 15 def process(frm, to, file): 16 hostname = socket.gethostname() 17 dest = remotes.get(to) 18 src = remotes.get(frm) 19 20 if dest is None or src is None: 21 return 1 22 23 if frm == hostname: 24 cmd = "scp {} {}:{}".format(file, dest, file).split(" ") 25 else: 26 cmd = "scp {}:{} {}".format(src, file, file).split(" ") 27 return call(cmd, stdout=DEVNULL, stderr=DEVNULL) 28 29 argc = len(sys.argv) 30 31 if argc != 3: 32 exit(1) 33 34 frm = sys.argv[1] 35 to = sys.argv[2] 36 file = "/home/jb55/projects/razorcx/doc/org/todo.org" 37 38 [_,bn] = os.path.split(file) 39 40 ret = process(frm, to, file) 41 42 if ret != 0: 43 print("failed sync {}, {} -> {}".format(bn, frm, to)) 44 else: 45 print("sync success {}, {} -> {}".format(bn, frm, to)) 46 47 exit(ret)