X-Git-Url: https://code.delx.au/pymsnt/blobdiff_plain/1ecc6039e6c9cb1c0430c9a52847cdef9b2e7217..2968343a624f304d4bd1ef9abfa9be069294c6e8:/src/housekeep.py diff --git a/src/housekeep.py b/src/housekeep.py index 1020481..82a459b 100644 --- a/src/housekeep.py +++ b/src/housekeep.py @@ -8,6 +8,7 @@ import config import xdb import shutil +import sys import os import os.path @@ -77,7 +78,7 @@ def doSpoolPrepCheck(): filej = xdb.mangle(filej) if(os.path.exists(filej)): print "Need to move", file, "to", filej, "but the latter exists!\nAborting!" - os.exit(1) + sys.exit(1) else: shutil.move(pre + file, pre + filej) except: @@ -116,7 +117,7 @@ def doHashDirUpgrade(): if(os.path.exists(pre2 + file)): print "Need to move", file, "to", pre2 + file, "but the latter exists!\nAborting!" - os.exit(1) + sys.exit(1) else: shutil.move(pre + file, pre2 + file) except: @@ -125,7 +126,42 @@ def doHashDirUpgrade(): print "done" +def doMD5HashDirUpgrade(): + print "Moving the avatar directory from msn.host.com up to the spool directory." -noteList = ["doSpoolPrepCheck", "doHashDirUpgrade"] -noteListF = [doSpoolPrepCheck, doHashDirUpgrade] + pre = os.path.join(os.path.abspath(config.spooldir), config.jid) + X + if os.path.exists(pre + "avatars"): + # Remove the avatars dir that gets created when we import + # legacy/glue.py (it only contains the defaultAvatar) + shutil.rmtree(os.path.join(config.spooldir, "avatars")) + shutil.move(pre + "avatars", os.path.join(config.spooldir, "avatars")) + else: + print "Could not move your cached avatars directory automatically. It is safe to delete it, the avatars will be recreated as necessary." + + + print "Upgrading your spool directory to use md5 hashes." + + dirlist = os.listdir(pre) + dir, hash, file = "","","" + try: + for dir in dirlist: + if not os.path.isdir(pre + dir) or dir == "avatars" or len(dir) == 3: + continue + pre2 = pre + dir + X + for file in os.listdir(pre2): + if not os.path.isfile(pre2 + file): + continue + hash = xdb.makeHash(os.path.splitext(file)[0]) + if not os.path.exists(pre + hash): + os.makedirs(pre + hash) + shutil.move(pre2 + file, pre + hash + X + file) + os.rmdir(pre2) + except Exception, e: + print "Error in migration", pre, dir, hash, file, str(e) + sys.exit(1) + + + +noteList = ["doSpoolPrepCheck", "doHashDirUpgrade", "doMD5HashDirUpgrade"] +noteListF = [doSpoolPrepCheck, doHashDirUpgrade, doMD5HashDirUpgrade]