Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r2208 - trunk/fsvs/pre-1.2-migration/migrate.py

fsvs
Discussion topic

Back to topic list

svn commit: r2208 - trunk/fsvs/pre-1.2-migration/migrate.py

Author tekknokrat
Full name Gunnar Thielebein
Date 2009-04-09 15:32:45 PDT
Message Author: tekknokrat
Date: 2009-04-09 15:32:44-0700
New Revision: 2208

Modified:
   trunk/fsvs/pre-1.2-m​igration/migrate.py

Log:
begin with rewriting to Phil's suggestions

Modified: trunk/fsvs/pre-1.2-m​igration/migrate.py
Url: http://fsvs.tigris.o​rg/source/browse/fsv​s/trunk/fsvs/pre-1.2​-migration/migrate.p​y?view=diff&path​rev=2208&r1=2207​&r2=2208
====================​====================​====================​==================
--- trunk/fsvs/pre-1.2-m​igration/migrate.py (original)
+++ trunk/fsvs/pre-1.2-m​igration/migrate.py 2009-04-09 15:32:44-0700
@@ -17,22 +17,82 @@
 import os.path
 import shutil
 import hashlib
+import getopt
 
 def main():
- files = fsvsFindWAAFiles()
- if len(files) > 0:
- fsvsMigrateFiles(files)
- else:
- print("No files to migrate.")
-
-def fsvsMigrateFiles(files):
- ip = raw_input("Number of items found for migration: " + str(len(files)) + "\nShould migration be started?((Y)es/(n)o/​(t)estonly)")
- parent = fsvsGetNewWAAParent()
     
- if ip.lower() == 'y':
+ '''cache wc for further access'''
+ currentwc = None
+
+ class Options:
+ test = False
+ quiet = False
+
+ tabcount = 2
+ usage = \
+ "fsvs_create [options] sourcedir targetdir\n" \
+ "options:\n" \
+ "\t""-t" + "\t" * tabcount + "test mode\n or" \
+ "\t""-q" + "\t" * tabcount + "quiet execution, without interaction\n" \
+ "\t""-h" + "\t" * tabcount + "show this help"
+
+ try:
+ opts,args = getopt.getopt(sys.ar​gv[1:],"tqh")
+
+ except getopt.GetOptError, err:
+ print str(err)
+ sys.exit(2)
+ for name, value in opts:
+ if name == "-t":
+ Options.test = True
+ if name == "-q":
+ Options.quiet = True
+ if Options.test and Options.quiet:
+ print ("Either -t or -q, not both at the same time allowed!")
+ print(usage)
+ sys.exit(1)
+ if name == "-h":
+ print(usage)
+ sys.exit(0)
+ '''find files for each working copy and try to migrate'''
+ for wc in fsvsGetWCList():
+ if len(wc)>0:
+ files = fsvsFindWAAFiles(wc)
+ if len(files) > 0:
+ fsvsMigrateFiles(files)
+ else:
+ print("No files to migrate.")
+ else:
+ print("No configured working copies found!")
+ exit(0)
+
+def fsvsFindWAAFiles(wc):
+ files = ('md5s', 'prop')
+ fileList = fsvsGetMonitoredFiles()
+ parent = fsvsGetOldWAAParent()
+ res = dict([])
+ for i in fileList:
+ md5 = getPathMD5(i)
+ p1 , p2 , p3 = getMD5Parts(md5)
+ for j in files:
+ path = os.path.join(parent, p1, p2, p3, j)
+ if os.path.exists(path):
+ res[path] = md5
+ return res
+
+def fsvsMigrateFiles(files):
+ '''Neither test nor quiet, so keep asking for input'''
+ if not Options.test and not Options.quiet:
+ rawinput = raw_input("Number of items found for migration: " + str(len(files)) + "\nShould migration to be started?((Y)es/(n)o/​(t)estonly)")
+ parent = fsvsGetNewWAAParent()
+
+ if rawinput.lower() == 't':
+ Options.test = True
+
+ if rawinput.lower() == 'y' or Options.quiet:
         fsvsCreateNewWAAParent(parent)
         fsvsMigrateUrlsFile()
- fsvsMigrateIgnoreFile()
+ fsvsConvertIgnoreFile()
         '''migrate the other files'''
         for src,md5 in files.iteritems():
             p1, p2, p3 = getMD5Parts(md5)
@@ -41,20 +101,15 @@
                 print ( "creating directory: " + dst)
                 os.makedirs(dst)
             if not os.path.exists(os.pa​th.join(dst, os.path.basename(src))):
- print ("copying " + src + " to " + dst)
- shutil.copy2(src, dst)
+ if not Options.quiet:
+ print ("copying " + src + " to " + dst)
+ if not Options.test:
+ shutil.move(src, dst)
             else:
                 print ("file is already migrated! Aborting here.")
- quit()
+ sys.exit(0)
                                                        
- if ip.lower() == 't':
- for src,md5 in files.iteritems():
- p1, p2, p3 = getMD5Parts(md5)
- dst = os.path.join(parent, p1, p2, p3)
- if not os.path.exists(dst):
- print ( "would create directory: " + dst)
- print ("would copy " + src + " to " + dst)
-
+
 def fsvsCreateNewWAAParent(path):
     if not os.path.exists(path):
         try:
@@ -62,16 +117,30 @@
         except: IOError
     else:
         print("New parentdir " + path + " already exists, delete manually and repeat migration.")
- quit()
+ sys.exit(0)
         
-def fsvsMigrateUrlsFile():
- src = fsvsGetWCConfPath()
- src += 'Urls'
- dst = fsvsGetNewWAAParent()
- print "migrate Urls file from " + src + " to " + dst
- shutil.copy2(src, dst)
-
-def fsvsMigrateIgnoreFile():
+def fsvsMigrateWCFiles():
+ cfgdir = fsvsGetWCConfPath()
+ digest = getPathMD5(currentwc)
+ p1, p2, p3 = getMD5Parts(digest)
+ dst = os.path.join(fsvsGet​NewWAAParent(),p1,p2​)
+ '''append the wc cfgdir, and the wc waapath then iterate through them'''
+ '''!should be a array of objects'''
+ for cfgfile in ("Urls", "Ign") do:
+ src.append(cfgdir + cfgfile)
+ src.append(os.path.j​oin(fsvsGetWAA(),p1,​p2,p3)
+ for fsobj in src:
+ if Option.quiet and not Option.test:
+ print("migrate WC file from " + os.path.join(srcdir,src) + " to " + dst)
+ if not Option.test:
+ try:
+ shutil.move(srcpath, dst)
+ if fsobj in "Ign":
+ fsvsConvertIgnoreFile()
+ except: shutil.Error
+
+'''convert Ignore File on new location'''
+def fsvsConvertIgnoreFile():
     res = []
     src = os.path.join(fsvsGet​WCConfPath(), 'Ign')
     dst = os.path.join(fsvsGet​NewWAAParent(), 'Ign')
@@ -89,22 +158,29 @@
         print "Destination Ign File already exists, delete and try to restart migration"
     
         
-def fsvsFindWAAFiles():
- files = ('dir', 'md5s', 'prop', 'cflct')
- fileList = fsvsGetMonitoredFiles()
- parent = fsvsGetOldWAAParent()
- res = dict([])
- for i in fileList:
- md5 = getPathMD5(i)
- p1 , p2 , p3 = getMD5Parts(md5)
- for j in files:
- path = os.path.join(parent, p1, p2, p3, j)
- if os.path.exists(path):
- res[path] = md5
+def fsvsGetWCList():
+ res = []
+ ''' is this same in all installations of fsvs?'''
+ wccfgpath = '/etc/fsvs'
+ try:
+ path = os.environ['FSVS_WC']
+ except KeyError:
+ path = None
+ print('FSVS_WC does not exists')
+
+ if path != None:
+ ''' If WC is given via environment FSVS_WC then this is taken only '''
+ res.append(path)
+ return res
+ else:
+ parent = os.listdir(wccfgpath)
+ for p in parent:
+ ''' readlink: path the symlink in wccfg points to; appending this to list of WC'''
+ res.append(os.link((​os.path.join(wccfgpa​th, p, '_base'))))
     return res
             
-def fsvsGetMonitoredFiles():
- cmd = ('/usr/bin/fsvs','st', '-v','/')
+def fsvsGetMonitoredFiles(wc):
+ cmd = ('/usr/bin/fsvs','st', '-v',currentwc)
     sproc = subprocess.Popen(cmd, shell=False,stdout=s​ubprocess.PIPE,stder​r=None)
     stdout = sproc.communicate(None)
     helper = stdout[0].split('\n')
@@ -114,23 +190,25 @@
     return list
         
 def fsvsGetWCConfPath():
- cmd = ('/usr/bin/fsvs','info', '/')
- sproc = subprocess.Popen(cmd, shell=False, stdout=subprocess.PI​PE,stderr=None)
- stdout = sproc.communicate(None)
- list = stdout[0].split('\n')
- for i in list:
- if "Conf-Path:" in i:
- res = getPath(i,'\t')
- return res
+ if currentwc:
+ cmd = ('/usr/bin/fsvs','info', currentwc)
+ sproc = subprocess.Popen(cmd, shell=False, stdout=subprocess.PI​PE,stderr=None)
+ stdout = sproc.communicate(None)
+ list = stdout[0].split('\n')
+ for i in list:
+ if "Conf-Path:" in i:
+ res = getPath(i,'\t')
+ return res
 
 def fsvsGetWC():
     '''split trailing / and wc part from configpath'''
     helper = os.path.abspath(fsvs​GetWCConfPath())
     res = os.path.basename(helper)
     return res
-
+
+'''old WAA is /var/spool/fsvs'''
 def fsvsGetWAA():
- cmd = ('/usr/bin/fsvs','info','/')
+ cmd = ('/usr/bin/fsvs','in​fo','currentwc')
     sproc = subprocess.Popen(cmd, shell=False, stdout=subprocess.PI​PE,stderr=None)
     stdout = sproc.communicate(None)
     list = stdout[0].split('\n')
@@ -138,33 +216,24 @@
         if "WAA-Path:" in i:
             res = getPath(i,'\t')
             return res
-
+
+'''new looks like /var/spool/fsvs/6666'''
 def fsvsGetNewWAAParent():
- WC = fsvsGetWC()
- prfx = WC[:4]
- p1, p2, p3 = getMD5Parts(WC)
- oldParent = fsvsGetOldWAAParent()
- parent = os.path.join(oldParent, prfx)
+ prfx = currentwc[:4]
+ parent = os.path.join(fsvsGetWAA, prfx)
     return parent
-
-def fsvsGetOldWAAParent():
- WC = fsvsGetWC()
- p1, p2, p3 = getMD5Parts(WC)
- waa = fsvsGetWAA()
- '''look for occurrence of first MD5 part'''
- parentWAA = waa[0:waa.find(p1)]
- return parentWAA
+
 
 def getPathMD5(path):
     encoder = hashlib.md5()
     encoder.update(path)
- result = encoder.hexdigest()
- return result
+ digest = encoder.hexdigest()
+ return digest
     
-def getMD5Parts(WC):
- p1 = WC[0:2]
- p2 = WC[2:4]
- p3 = WC [4:32]
+def getMD5Parts(digest):
+ p1 = digest[0:2]
+ p2 = digest[2:4]
+ p3 = digest[4:32]
     return p1, p2, p3
             
 def getPath(helper,delim):
@@ -173,3 +242,4 @@
 
 if __name__ == "__main__":
     main()
+

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r2208 - trunk/fsvs/pre-1.2-migration/migrate.py tekknokrat Gunnar Thielebein 2009-04-09 15:32:45 PDT
Messages per page: