示例#1
0
文件: xsd.py 项目: ostwald/python-lib
	def write (self, path, verbose=False):
		"""
		require a path so we don't tromp the template
		"""
		if self.dowrites:
			XmlRecord.write (self, path, verbose)
		else:
			print "WOULD have written to " + path
示例#2
0
 def write(self, path=None):
     XmlRecord.write(self, path)
     writePath = None
     if path is not None:
         writePath = path
     elif self.path is not None:
         writePath = self.path
     if writePath is not None:
         print "xml written to %s" % writePath
示例#3
0
	def writeXml (self, path=None):
		"""
		write record info file to disk as xml
		"""
		path = path or "not-fy10-records.xml"
		rec = XmlRecord (xml="<not-fy10-records/>")
		rec.doc.setAttribute ("date", time.asctime(time.localtime()))
		for recInfo in self:
			rec.doc.appendChild (recInfo.asElement())
		rec.write(path)
		print 'wrote to ', path
示例#4
0
 def writeTopicRecords(self):
     for topic in self.keys():
         print "%s - %d" % (topic, len(self[topic]))
         rec = XmlRecord(xml="<AsnDocuments/>")
         root = rec.doc
         root.setAttribute("topic", topic)
         for asnInfo in self[topic]:
             root.appendChild(asnInfo)
         path = os.path.join(self.topicCache, topic + '.xml')
         rec.write(path)
         print 'wrote to', path
示例#5
0
	def write (self, dir="."):
		id = self.getId()
		if not id:
			raise Exception, "Could not write record: id not found"
		path = os.path.join (dir, id + ".xml")
		if os.path.exists (path):
			msg = "Could not write: File already exists for %s" % path
			raise Exception,  msg
		# fp = open (path, 'w')
		# fp.write (self.doc.toprettyxml ("  ","\n"))
		# fp.close()
		XmlRecord.write(self, path)
示例#6
0
    def toxml(self):
        """
		make an xml document containing id and dcslastTouchDate value for each record
		"""
        rec = XmlRecord(xml="<lastTouchInfo></lastTouchInfo>")
        rec.doc.setAttribute("collection", self.collection)
        for result in self:
            el = XmlUtils.addElement(rec.dom, rec.doc, 'rec')
            for key in result.keys():
                el.setAttribute(key, result[key])

        dest = "RAW_lastTouchData/%s.xml" % self.collection
        rec.write(dest)
        print "wrote to ", dest
示例#7
0
 def write(self, filename, dir="."):
     doPP = True
     path = os.path.join(dir, filename + ".xml")
     if os.path.exists(path):
         msg = "Could not write: File already exists for %s" % path
         raise Exception, msg
     ## XmlRecord.write(self, path)
     if doPP:
         fp = open(path, 'w')
         fp.write(self.__repr__())
         fp.close()
     else:
         XmlRecord.write(self, path)
     print 'wrote %s' % os.path.basename(path)
示例#8
0
    def toxml(self, path=None):
        """
		write this map as xml to a file in the "grouping_data" directory, named after the classname
		"""
        if path is None:
            path = 'grouping_data/' + self.__class__.__name__ + '.xml'
        rec = XmlRecord(xml="<dupGroups/>")
        rec.doc.setAttribute('name', self.__class__.__name__)
        groupNum = 1
        for key in self.getReportingKeys():
            groupEl = XmlUtils.addElement(rec.dom, rec.doc, 'group')
            groupEl.setAttribute('key', key)
            groupEl.setAttribute('size', str(len(self[key])))
            groupEl.setAttribute('groupNum', str(groupNum))
            for recInfo in self[key]:
                groupEl.appendChild(recInfo.element.cloneNode(1))
            groupNum = groupNum + 1
        rec.write(path)
        print 'wrote to ', path
示例#9
0
class CollectionInfo(UserList):

    # baseDir = "meta-metadata"
    baseDir = '/home/ostwald/python-lib/ncar_lib/dups/data/meta-metadata'

    def __init__(self, collection):
        UserList.__init__(self)
        self.collection = collection
        self.dataPath = os.path.join(self.baseDir, collection + '.xml')
        print "DATA_PATH: ", self.dataPath
        self.rec = XmlRecord(path=self.dataPath)
        nodes = self.rec.selectNodes(self.rec.dom, "collectionInfo:rec")
        print "%d recs read from meta-metadata" % len(nodes)
        map(self.append, map(RecordInfo, nodes))

    def selectByUnionDate(self, unionDate):
        """
		takes union date (e.g., 2011, 2011-02, 2011-02-25)
		and returns recs having lastTouch AFTER union date
		"""
        threshold = unionDateToSecs(unionDate)
        predicate = lambda x: x.timeStamp >= threshold
        return self.select(predicate)

    def select(self, predicate):
        """
		applies predicate to each item
		returns only those for which preciate is True
		"""
        return filter(predicate, self.data)

    def write(self, path=None):
        """
		self.rec writes to self.rec.path by default
		"""
        self.rec.write(path)
示例#10
0
 def write(self, path):
     XmlRecord.write(self, path)
     print 'wrote to ', path
示例#11
0
 def write(self, filename, dir="."):
     path = os.path.join(dir, filename + ".xml")
     if os.path.exists(path):
         msg = "Could not write: File already exists for %s" % path
         raise Exception, msg
     XmlRecord.write(self, path)