Browse Source

add cunsor syrnc

ZhenQin 12 years ago
parent
commit
16075f70c0
2 changed files with 51 additions and 0 deletions
  1. 1 0
      rsync/nodes
  2. 50 0
      rsync/rsync.py

+ 1 - 0
rsync/nodes

@@ -0,0 +1 @@
+localhost

+ 50 - 0
rsync/rsync.py

@@ -0,0 +1,50 @@
+#!/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:])