1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/usr/bin/env python
- #encoding:utf-8
- import sys
- import os
- import string
- import getpass
- __author__ = 'ZhenQin'
- NODE_FILE = "nodes"
- COMMAND = "scp "
- def rsync(files):
- PARAMS = ""
- nodes = getNodes(NODE_FILE)
- if len(nodes) > 0:
- for file in files:
- #dist_dir = os.path.dirname(file)
- dist_dir = os.path.abspath(file)
- file_name = os.path.basename(dist_dir)
- if dist_dir == "":
- dist_dir = os.getcwd()
- dist_dir = dist_dir[:dist_dir.index(file_name) - 1]
- print file_name, " ==> ", dist_dir
- if os.path.isdir(file):
- PARAMS = " -r "
- for node in nodes:
- cmd = COMMAND + PARAMS + file + " " + getpass.getuser()+"@"+node+":"+dist_dir
- print cmd
- result = os.popen(cmd).readlines()
- print result
- else:
- print "no nodes"
- def getNodes(filePath):
- nodes = list()
- for line in open(filePath, "r"):
- nodes.append(string.strip(line))
- return nodes
- if __name__ == "__main__" :
- if len(sys.argv) == 1:
- print "python rsync.py file1 [file2,...]"
- rsync(sys.argv[1:])
|