Login | Register
My pages Projects Community openCollabNet

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

fsvs
Discussion topic

Back to topic list

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

Author tekknokrat
Full name Gunnar Thielebein
Date 2009-05-26 02:08:15 PDT
Message Author: tekknokrat
Date: 2009-05-26 02:08:14-0700
New Revision: 2255

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

Log:
further work on script

Added: 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=markup&pa​threv=2255
====================​====================​====================​==================
--- (empty file)
+++ trunk/fsvs/pre-1.2-m​igration/migrate.py 2009-05-26 02:08:14-0700
@@ -0,0 +1,228 @@
+#!/usr/bin/env python
+
+'''
+Created on 15 Mar 2009
+@author: gthielebein
+@email: gunnar_thielebein at gmx dot net
+Copyright (C) 2009 Gunnar Thielebein.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 3 as
+published by the Free Software Foundation.
+'''
+
+import subprocess
+import sys # sysout
+import re
+import os
+import os.path
+import shutil
+import hashlib
+import getopt
+
+
+def main():
+ currentwc = None
+ currentwccfg = None
+ currentflist = None
+
+ '''cache wc for further access'''
+
+ 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:
+ currentwc, currentwccfg = wc
+ print("Current WC:" + currentwc + " , Config Path:" + currentwccfg)
+ files = fsvsFindWAAFiles(cur​rentflist,currentwc)​
+ if len(files) > 0:
+ fsvsMigrateFiles(files)
+ else:
+ print("No files to migrate.")
+ else:
+ print("No configured working copies found!")
+ exit(0)
+
+def fsvsFindWAAFiles(flist,wc):
+ files = ('md5s', 'prop')
+ fsvsGetMonitoredFiles(flist,wc)
+ parent = fsvsGetOldWAAParent()
+ res = dict([])
+ for f in flist:
+ md5 = getPathMD5(i)
+ p1 , p2 , p3 = getMD5Parts(md5)
+ for g in files:
+ path = os.path.join(parent, p1, p2, p3, g)
+ if os.path.exists(path):
+ res[path] = md5
+ return res
+
+def fsvsMigrateFiles(currentflist):
+ '''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()
+ fsvsConvertIgnoreFile()
+ '''migrate the other files'''
+ 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 ( "creating directory: " + dst)
+ os.makedirs(dst)
+ if not os.path.exists(os.pa​th.join(dst, os.path.basename(src))):
+ 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.")
+ sys.exit(0)
+
+def fsvsCreateNewWAAParent(path):
+ if not os.path.exists(path):
+ try:
+ os.mkdir(path)
+ except: IOError
+ else:
+ print("New parentdir " + path + " already exists, delete manually and repeat migration.")
+ sys.exit(0)
+
+def fsvsMigrateWCFiles():
+ cfgdir = currentwccfg
+ digest = getPathMD5(currentwc)
+ p1, p2, p3 = getMD5Parts(digest)
+ src = []
+ 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'''
+ print("cfgfile output:" + cfgfile)
+ sys.exit()
+ for cfgfile in ['Urls', 'Ign']:
+ 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(currentwccfg, 'Ign')
+ dst = os.path.join(fsvsGet​NewWAAParent(), 'Ign')
+ srcFile = open( src )
+ list = srcFile.readlines()
+ srcFile.close()
+ for i in list:
+ res.append(re.sub(r'​^t\.',r'take.',i))
+ if not os.path.exists(dst):
+ dstFile = open(dst, 'w')
+ for i in res:
+ dstFile.write(i)
+ dstFile.close()
+ else:
+ print "Destination Ign File already exists, delete and try to restart migration"
+
+def fsvsGetWCList():
+ wclist = []
+ try:
+ parent = os.environ['FSVS_WC']
+ except KeyError:
+ parent = '/etc/fsvs'
+ for p in os.listdir(parent):
+ ''' readlink: path the symlink in points to; appending this to list of WC'''
+ wclist.append((os.re​adlink(os.path.join(​parent, p, '_base')),os.path.jo​in(parent,p)))
+ return wclist
+
+def fsvsGetMonitoredFile​s(flist,wc):
+ if not flist:
+ cmd = ('/usr/bin/fsvs','st', '-v',wc)
+ print(cmd)
+ quit()
+ sproc = subprocess.Popen(cmd, shell=False,stdout=s​ubprocess.PIPE,stder​r=None)
+ stdout = sproc.communicate(None)
+ helper = stdout[0].split('\n')
+ for i in helper:
+ list.append(getPath(i,' '))
+ else:
+ list = flist
+ return list
+
+'''old WAA is /var/spool/fsvs'''
+def fsvsGetWAA():
+ 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')
+ for i in list:
+ if "WAA-Path:" in i:
+ res = getPath(i,'\t')
+ return res
+
+'''new looks like /var/spool/fsvs/6666'''
+def fsvsGetNewWAAParent():
+ '''fix me'''
+ prfx = currentwc[:4]
+ parent = os.path.join(fsvsGetWAA, prfx)
+ return parent
+
+def getPathMD5(path):
+ encoder = hashlib.md5()
+ encoder.update(path)
+ digest = encoder.hexdigest()
+ return digest
+
+def getMD5Parts(digest):
+ p1 = digest[0:2]
+ p2 = digest[2:4]
+ p3 = digest[4:32]
+ return p1, p2, p3
+
+def getPath(helper,delim):
+ filepath = helper[helper.rfind(​delim)+1:len(helper)​]
+ return filepath
+
+if __name__ == "__main__":
+ main()
+

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

Messages

Show all messages in topic

svn commit: r2255 - trunk/fsvs/pre-1.2-migration/migrate.py tekknokrat Gunnar Thielebein 2009-05-26 02:08:15 PDT
Messages per page: