Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r2204 - trunk/fsvs/pre-1.2-migration

fsvs
Discussion topic

Back to topic list

svn commit: r2204 - trunk/fsvs/pre-1.2-migration

Author tekknokrat
Full name Gunnar Thielebein
Date 2009-03-16 12:48:03 PDT
Message Author: tekknokrat
Date: 2009-03-16 12:48:02-0700
New Revision: 2204

Added:
   trunk/fsvs/pre-1.2-migration/
   trunk/fsvs/pre-1.2-m​igration/migrate.py (contents, props changed)

Log:
create migration folder/first checkin of migration 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=2204
====================​====================​====================​==================
--- (empty file)
+++ trunk/fsvs/pre-1.2-m​igration/migrate.py 2009-03-16 12:48:02-0700
@@ -0,0 +1,174 @@
+#!/usr/bin/env python
+
+'''
+Created on 15 Mar 2009
+@author: gthielebein
+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
+
+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':
+ fsvsCreateNewWAAParent(parent)
+ fsvsMigrateUrlsFile()
+ fsvsMigrateIgnoreFile()
+ '''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))):
+ print ("copying " + src + " to " + dst)
+ shutil.copy2(src, dst)
+ else:
+ print ("file is already migrated! Aborting here.")
+ quit()
+
+ 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:
+ os.mkdir(path)
+ except: IOError
+ else:
+ print("New parentdir " + path + " already exists, delete manually and repeat migration.")
+ quit()
+
+def fsvsMigrateUrlsFile():
+ src = fsvsGetWCConfPath()
+ src += 'Urls'
+ dst = fsvsGetNewWAAParent()
+ print "migrate Urls file from " + src + " to " + dst
+ shutil.copy2(src, dst)
+
+def fsvsMigrateIgnoreFile():
+ res = []
+ src = os.path.join(fsvsGet​WCConfPath(), '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 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
+ return res
+
+def fsvsGetMonitoredFiles():
+ cmd = ('/usr/bin/fsvs','st', '-v','/')
+ sproc = subprocess.Popen(cmd, shell=False,stdout=s​ubprocess.PIPE,stder​r=None)
+ stdout = sproc.communicate(None)
+ helper = stdout[0].split('\n')
+ list = []
+ for i in helper:
+ list.append(getPath(i,' '))
+ 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
+
+def fsvsGetWC():
+ '''split trailing / and wc part from configpath'''
+ helper = os.path.abspath(fsvs​GetWCConfPath())
+ res = os.path.basename(helper)
+ return res
+
+def fsvsGetWAA():
+ 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 "WAA-Path:" in i:
+ res = getPath(i,'\t')
+ return res
+
+def fsvsGetNewWAAParent():
+ WC = fsvsGetWC()
+ prfx = WC[:4]
+ p1, p2, p3 = getMD5Parts(WC)
+ oldParent = fsvsGetOldWAAParent()
+ parent = os.path.join(oldParent, 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
+
+def getMD5Parts(WC):
+ p1 = WC[0:2]
+ p2 = WC[2:4]
+ p3 = WC [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: r2204 - trunk/fsvs/pre-1.2-migration tekknokrat Gunnar Thielebein 2009-03-16 12:48:03 PDT
Messages per page: