#!/usr/bin/python
import os, sys

user="zhanxw"
host=("wonderland","fantasia","mrtoad")
domain="sph.umich.edu"

def usage():
    print("mysync <files> <dirs> ")

def getDestinationHosts():
    h = os.uname()[1]
    r = []
    for i in host:
        if (i != h):
            r.append(i)
    return r

def sync(name, destHost):
    src = os.path.split(os.path.abspath(name))
    for h in destHost:
        if (os.access(name, os.F_OK) != True):
            print ("Cannot access: " + name)
            sys.exit(1)
        cmd = "scp -r " + name + " "+ user + "@" + h +":" + src[0]
        print (cmd)
        os.system(cmd)
if __name__ == "__main__":
    if (len(sys.argv)<=1):
        usage()
        sys.exit(0)
    destHost= getDestinationHosts();
    for i in sys.argv[1:]:
        sync (i, destHost)
