]> code.delx.au - pymsnt/blobdiff - src/housekeep.py
Fixed msn2jid to not do /msn/msn
[pymsnt] / src / housekeep.py
index 6a472ca9761311b186c98435fd12bcbcd53dfcda..1020481c74bb9f7c51961d585ecd272961f71194 100644 (file)
@@ -1,19 +1,19 @@
 # Copyright 2005 James Bunton <james@delx.cjb.net>
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
+from tlib import xmlw
+
 import utils
 import config
 import xdb
-if(utils.checkTwisted()):
-       from twisted.words.protocols.jabber import jid
-else:
-       from tlib.jabber import jid
 
 import shutil
 import os
 import os.path
 
 
+X = os.path.sep
+
 def init():
        global noteList
        global noteListF
@@ -32,18 +32,19 @@ def init():
 
 class NotesToMyself:
        def __init__(self):
-               pre = os.path.abspath(config.spooldir) + "/" + config.jid + "/"
-               self.filename = pre + "/notes_to_myself"
+               pre = os.path.abspath(config.spooldir) + X + config.jid + X
+               self.filename = pre + X + "notes_to_myself"
                self.notes = []
                
                if os.path.exists(self.filename):
                        f = open(self.filename, "r")
                        self.notes = [x.strip() for x in f.readlines()]
                        f.close()
-               elif not os.path.exists(pre):
+               else:
+                       if not os.path.exists(pre):
+                               os.makedirs(pre)
                        global noteList
                        self.notes = noteList
-                       os.makedirs(pre)
        
        def check(self, note):
                return self.notes.count(note) == 0
@@ -61,21 +62,27 @@ class NotesToMyself:
 
 
 def doSpoolPrepCheck():
-       pre = os.path.abspath(config.spooldir) + "/" + config.jid + "/"
+       pre = os.path.abspath(config.spooldir) + X + config.jid + X
 
        print "Checking spool files and stringprepping any if necessary...",
 
        for file in os.listdir(pre):
-               file = xdb.unmangle(file).decode("utf-8")
-               filej = jid.JID(file).full()
-               if(file != filej):
-                       file = xdb.mangle(file)
-                       filej = xdb.mangle(filej)
-                       if(os.path.exists(filej)):
-                               print "Need to move", file, "to", filej, "but the latter exists!\nAborting!"
-                               os.exit(1)
-                       else:
-                               shutil.move(pre + file, pre + filej)
+               try:
+                       if not os.path.isfile(file):
+                               continue
+                       file = xdb.unmangle(file).decode("utf-8")
+                       filej = xmlw.jid.intern(file).full()
+                       if(file != filej):
+                               file = xdb.mangle(file)
+                               filej = xdb.mangle(filej)
+                               if(os.path.exists(filej)):
+                                       print "Need to move", file, "to", filej, "but the latter exists!\nAborting!"
+                                       os.exit(1)
+                               else:
+                                       shutil.move(pre + file, pre + filej)
+               except:
+                       print "File: " + file
+                       raise
        print "done"
 
 
@@ -83,30 +90,37 @@ def doHashDirUpgrade():
        print "Upgrading your XDB structure to use hashed directories for speed...",
 
        # Do avatars...
-       pre = os.path.abspath(config.spooldir) + "/" + config.jid + "/avatars/"
+       pre = os.path.join(os.path.abspath(config.spooldir), config.jid) + X + "avatars" + X
        if os.path.exists(pre):
                for file in os.listdir(pre):
-                       if os.path.isfile(pre + file):
-                               pre2 = pre + file[0:3] + "/"
-                               if not os.path.exists(pre2):
-                                       os.makedirs(pre2)
-                               shutil.move(pre + file, pre2 + file)
+                       try:
+                               if os.path.isfile(pre + file):
+                                       pre2 = pre + file[0:3] + X
+                                       if not os.path.exists(pre2):
+                                               os.makedirs(pre2)
+                                       shutil.move(pre + file, pre2 + file)
+                       except:
+                               print "File: " + file
+                               raise
        
        # Do spool files...
-       pre = os.path.abspath(config.spooldir) + "/" + config.jid + "/"
+       pre = os.path.join(os.path.abspath(config.spooldir), config.jid) + X
        if os.path.exists(pre):
                for file in os.listdir(pre):
-                       if os.path.isfile(pre + file) and file != "notes_to_myself":
-                               hash = file[0:2]
-                               pre2 = pre + hash + "/"
-                               if not os.path.exists(pre2):
-                                       os.makedirs(pre2)
-
-                               if(os.path.exists(pre2 + file)):
-                                       print "Need to move", file, "to", pre2 + file, "but the latter exists!\nAborting!"
-                                       os.exit(1)
-                               else:
-                                       shutil.move(pre + file, pre2 + file)
+                       try:
+                               if os.path.isfile(pre + file) and file != "notes_to_myself":
+                                       hash = file[0:2]
+                                       pre2 = pre + hash + X
+                                       if not os.path.exists(pre2):
+                                               os.makedirs(pre2)
+
+                                       if(os.path.exists(pre2 + file)):
+                                               print "Need to move", file, "to", pre2 + file, "but the latter exists!\nAborting!"
+                                               os.exit(1)
+                                       else:
+                                               shutil.move(pre + file, pre2 + file)
+                       except:
+                               print "File: " + file
 
        print "done"