]> code.delx.au - pymsnt/blobdiff - src/housekeep.py
Fixed reconnecting problem (finally)
[pymsnt] / src / housekeep.py
index c3ed1defd6420bbc95543f8901e159b68fc2f3de..00f83bd7b057d7b197f3060521a3edf8a23aab72 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,14 +62,14 @@ 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):
                try:
                        file = xdb.unmangle(file).decode("utf-8")
-                       filej = jid.JID(file).full()
+                       filej = xmlw.jid.intern(file).full()
                        if(file != filej):
                                file = xdb.mangle(file)
                                filej = xdb.mangle(filej)
@@ -87,12 +88,12 @@ 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):
                        try:
                                if os.path.isfile(pre + file):
-                                       pre2 = pre + file[0:3] + "/"
+                                       pre2 = pre + file[0:3] + X
                                        if not os.path.exists(pre2):
                                                os.makedirs(pre2)
                                        shutil.move(pre + file, pre2 + file)
@@ -101,13 +102,13 @@ def doHashDirUpgrade():
                                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):
                        try:
                                if os.path.isfile(pre + file) and file != "notes_to_myself":
                                        hash = file[0:2]
-                                       pre2 = pre + hash + "/"
+                                       pre2 = pre + hash + X
                                        if not os.path.exists(pre2):
                                                os.makedirs(pre2)