Ejemplo n.º 1
0
    def merge(self):
        """
		ignore records with collection key containing 'hsbio'
		
		collisions are reported when dowrites is False.
		when dowrites is True, collisions raise an Exception
		"""
        for filename in filter(self.acceptItem, os.listdir(self.src_dir)):
            src_path = os.path.join(self.src_dir, filename)
            src_rec = DleseCollectRecord(path=src_path)
            src_key = src_rec.getKey()

            if not self.acceptCollectionKey(src_key):
                if verbose:
                    print 'SKIPPING:', src_key
                continue

            dst_path = os.path.join(self.dst_dir, src_key + '.xml')

            if os.path.exists(dst_path):
                ## COLLISION
                if dowrites:
                    raise Exception, 'dst_path exists at %s' % dst_path
                else:  # debugging - print out collisions
                    print 'COLLISION: dst_path exists at %s' % dst_path
                    continue

            if dowrites:
                src_rec.setId(src_key)
                src_rec.write(dst_path)
            else:
                if 1 or verbose:
                    print 'would have copied %s to ...\n\t%s' % (
                        os.path.basename(src_path), dst_path)
Ejemplo n.º 2
0
	def updateCollectionRecord(self, new_key, new_name=None):
		"""
		- find the collection record with this collections prefix
		  -- we look through them one by one
		- update the prefix
		- if dowrites:
		  - write collection record
	  """
		collect = os.path.join (self.repo, "dlese_collect", "collect")
		for filename in filter (lambda x:x.endswith('xml'), os.listdir(collect)):
			# print filename
			path = os.path.join(collect, filename)
			rec = DleseCollectRecord(path=path)
			oldKey = rec.getKey()
			if oldKey == self.key:
				print 'old key: %s' % rec.getKey()
				rec.setKey(new_key)
				rec.setId(new_key)
				if new_name:
					rec.setShortTitle (new_name)
					rec.setFullTitle(new_name)
				
				if self.dowrites:
					rec.write()
					os.rename(path, os.path.join(collect, new_key+'.xml'))
					print 'wrote collection record: %s' % rec.getId()
				else:
					print rec
					print 'WOULD have written collection record: %s' % rec.getId()
				return
Ejemplo n.º 3
0
 def _makeNewRec(self):
     newRec = DleseCollectRecord(path=templatepath)
     newRec.setId(self.newId)
     newRec.setFullTitle(self.fullTitle)
     newRec.setShortTitle(self.shortTitle)
     newRec.setDescription("NCAR Library " + self.shortTitle)
     newRec.setKey(self.key)
     return newRec