Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
	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)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
	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
Ejemplo n.º 8
0
	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)
Ejemplo n.º 9
0
	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
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
	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
Ejemplo n.º 13
0
 def __getFile(self, file):
     file = utils.mangle(file)
     hash = file[0:2]
     document = utils.parseFile(self.name + X + hash + X + file + ".xml")
     return document
Ejemplo n.º 14
0
 def __getFile(self, file):
     file = utils.mangle(file)
     document = utils.parseFile(self.name + X + file + ".xml")
     return document
Ejemplo n.º 15
0
	def __getFile(self, file):
		file = utils.mangle(file)
		document = utils.parseFile(self.name + X + file + ".xml")
		return document
Ejemplo n.º 16
0
	def __getFile(self, file):
		file = utils.mangle(file)
		hash = file[0:2]
		document = utils.parseFile(self.name + X + hash + X + file + ".xml")
		return document