]> code.delx.au - pymsnt/commitdiff
Use md5 hashes for spool dir. Moved avatar dir to root of spool dir.
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Fri, 14 Jul 2006 12:35:39 +0000 (12:35 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Fri, 14 Jul 2006 12:35:39 +0000 (12:35 +0000)
git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@195 55fbd22a-6204-0410-b2f0-b6c764c7e90a

committer: jamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>

src/avatar.py
src/housekeep.py
src/xdb.py

index d8d1a4c4b978c51c6e12092b0477276987a7c2b3..697400aa7c11e84fd0c6f179817ca704666c8c56 100644 (file)
@@ -73,7 +73,7 @@ class AvatarCache:
                """ Returns the full path to the directory that a 
                particular key is in. Creates that directory if it doesn't already exist. """
                X = os.path.sep
-               d = os.path.os.path.abspath(config.spooldir) + X + config.jid + X + "avatars" + X + key[0:3] + X 
+               d = os.path.os.path.abspath(config.spooldir) + X + "avatars" + X + key[0:3] + X 
                if not os.path.exists(d):
                        os.makedirs(d)
                return d
index 1020481c74bb9f7c51961d585ecd272961f71194..608c01e836bbb1d3230977ff612be8a831f89043 100644 (file)
@@ -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(config.spooldir + X + "avatars")
+               shutil.move(pre + "avatars", config.spooldir + X + "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(dir)
+       except Exception, e:
+               print "Error in migration", pre, dir, hash, file, str(e)
+               sys.exit(1)
+
+
+
+noteList = ["doSpoolPrepCheck", "doHashDirUpgrade", "doMD5HashDirUpgrade"]
+noteListF = [doSpoolPrepCheck, doHashDirUpgrade, doMD5HashDirUpgrade]
 
index 1e3e33e64c91a3a93f3a454a52a75809a998b674..e3caf0e97b50d7ff8b24ddf7b220f0f4e290099c 100644 (file)
@@ -6,6 +6,7 @@ from debug import LogEvent, INFO, WARN
 import os
 import os.path
 import shutil
+import md5
 import config
 
 X = os.path.sep
@@ -18,8 +19,11 @@ def unmangle(file):
        file = "%s@%s" % ("%".join(chunks), end)
        return file
 
-def mangle(jid):
-       return jid.replace("@", "%")
+def mangle(file):
+       return file.replace("@", "%")
+
+def makeHash(file):
+       return md5.md5(file).hexdigest()[0:3]
 
 
 class XDB:
@@ -40,7 +44,7 @@ class XDB:
                if(self.mangle):
                        file = mangle(file)
                
-               hash = file[0:2]
+               hash = makeHash(file)
                document = xmlw.parseFile(self.name + X + hash + X + file + ".xml")
                
                return document
@@ -50,7 +54,7 @@ class XDB:
                        file = mangle(file)
                
                prev_umask = os.umask(SPOOL_UMASK)
-               hash = file[0:2]
+               hash = makeHash(file)
                pre = self.name + X + hash + X
                if not os.path.exists(pre):
                        os.makedirs(pre)