def doSpoolPrepCheck(): 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): if os.path.isfile(pre + file) and file.find(".xml") != -1: file = utils.unmangle(file).decode("utf-8", "replace") try: filej = internJID(file).full() except InvalidFormat, UnicodeDecodeError: print "Unable to stringprep "+file+". Putting into BAD directory." file = utils.mangle(file) if not os.path.isdir(pre + "BAD"): os.makedirs(pre + "BAD") shutil.move(pre + file, pre + "BAD" + X + file) continue if file != filej: file = utils.mangle(file) filej = utils.mangle(filej) if os.path.exists(filej): print "Need to move "+file+" to "+filej+" but the latter exists!\nAborting!" sys.exit(1) else: shutil.move(pre + file, pre + filej)
def doSpoolPrepCheck(): 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): if os.path.isfile(pre + file) and file.find(".xml"): file = utils.unmangle(file).decode("utf-8", "replace") try: filej = internJID(file).full() except InvalidFormat, UnicodeDecodeError: print "Unable to stringprep " + file + ". Putting into BAD directory." file = utils.mangle(file) if not os.path.isdir(pre + "BAD"): os.makedirs(pre + "BAD") shutil.move(pre + file, pre + "BAD" + X + file) continue if file != filej: file = utils.mangle(file) filej = utils.mangle(filej) if os.path.exists(filej): print "Need to move " + file + " to " + filej + " but the latter exists!\nAborting!" sys.exit(1) else: shutil.move(pre + file, pre + filej)
def __writeFile(self, file, text): file = utils.mangle(file) prev_umask = os.umask(SPOOL_UMASK) f = open(self.name + X + file + ".xml", "w") f.write(text) f.close() os.umask(prev_umask)
def getNodeList(self, jid): """ Retrieves a list of all of the pubsub/pep items for a particular jid. Here we need to hunt through the file system and construct Node ids from what we find. """ nodes = [] X = os.path.sep pubsubbase = os.path.abspath( config.spooldir ) + X + config.jid + X + "pubsub" + X + utils.mangle(jid) if not os.path.isdir(pubsubbase): return nodes def findfiles(dir=pubsubbase): for e in os.listdir(dir): if e == "." or e == "..": continue path = dir + X + e if os.path.isdir(path): findfiles(path) elif path.endswith(".xml"): dir = dir.replace(pubsubbase + X, "", 1) if not nodes.count(dir): nodes.append(self.pathToNode(dir)) findfiles() return nodes
def remove(self, file): """ Removes an XDB file """ file = self.name + X + file[0:2] + X + file + ".xml" file = utils.mangle(file) try: os.remove(file) except: LogEvent(INFO, msg="XDB error removing file " + file) raise
def remove(self, file): """ Removes an XDB file """ file = self.name + X + file + ".xml" file = utils.mangle(file) try: os.remove(file) except: LogEvent(INFO, msg="XDB error removing file " + file) raise
def __writeFile(self, file, text): file = utils.mangle(file) prev_umask = os.umask(SPOOL_UMASK) pre = self.name + X if not os.path.exists(pre): os.makedirs(pre) f = open(pre + file + ".xml", "w") f.write(text) f.close() os.umask(prev_umask)
def dir(self, jid, node): """ 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.abspath(config.spooldir) + X + config.jid + X + "pubsub" + X + utils.mangle(jid) + X + self.nodeToPath(node) + X prev_umask = os.umask(SPOOL_UMASK) if not os.path.exists(d): os.makedirs(d) os.umask(prev_umask) return d
def dir(self, jid, node): """ 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.abspath( config.spooldir ) + X + config.jid + X + "pubsub" + X + utils.mangle( jid) + X + self.nodeToPath(node) + X prev_umask = os.umask(SPOOL_UMASK) if not os.path.exists(d): os.makedirs(d) os.umask(prev_umask) return d
def getNodeList(self, jid): """ Retrieves a list of all of the pubsub/pep items for a particular jid. Here we need to hunt through the file system and construct Node ids from what we find. """ nodes = [] X = os.path.sep pubsubbase = os.path.abspath(config.spooldir)+X+config.jid+X+"pubsub"+X+utils.mangle(jid) if not os.path.isdir(pubsubbase): return nodes def findfiles(dir=pubsubbase): for e in os.listdir(dir): if e == "." or e == "..": continue path=dir+X+e if os.path.isdir(path): findfiles(path) elif path.endswith(".xml"): dir = dir.replace(pubsubbase+X,"",1) if not nodes.count(dir): nodes.append(self.pathToNode(dir)) findfiles() return nodes
def __getFile(self, file): file = utils.mangle(file) hash = file[0:2] document = utils.parseFile(self.name + X + hash + X + file + ".xml") return document
def __getFile(self, file): file = utils.mangle(file) document = utils.parseFile(self.name + X + file + ".xml") return document