def port_checkins(self): project = self.project pr = getToolByName(project, "portal_repository") cat = getToolByName(project, "portal_catalog") session = self.session db = self.db checkout = self.checkoutdir repo = BzrAccess(checkout, default_commit_message=" ") checkins = session.query(Checkin).order_by(Checkin.timestamp) filename_map = {} for checkin in checkins: pageId = str(checkin.wikipage) version = checkin.version logger.info("page: %s" % pageId) try: page = project.unrestrictedTraverse(pageId) except Exception, e: print e import pdb; pdb.set_trace() continue if version == -99: # it's the current version msg = None content = page.EditableBody() timestamp = zDateTime(page.ModificationDate()).timeTime() author = ILastModifiedAuthorId(page) else: version = pr.retrieve(page, checkin.version) object = version.object author = version.sys_metadata['principal'] msg = version.comment content = object.EditableBody() timestamp = version.sys_metadata['timestamp'] logger.info("page: %s\trev: %s" % (page, checkin.version)) try: repo.write(pageId, content, msg=msg, author=author, committer=self.committer, timestamp=timestamp) filename_map[pageId] = pageId except IOError, e: if e.errno == 36: import md5 hashedId = md5.md5(pageId).hexdigest() repo.write(hashedId, content, msg=msg, author=author, committer=self.committer, timestamp=timestamp) filename_map[pageId] = hashedId
def sort_checkins(self): project = self.project pr = getToolByName(project, "portal_repository") cat = getToolByName(project, "portal_catalog") session = self.session db = self.db proj_id = project.getId() pages = cat.unrestrictedSearchResults(path='/'.join(project.getPhysicalPath()), portal_type="Document") for page in pages: ob = page.getObject() pagename = ob.getId() logger.info("page: %s" % pagename) versions = pr.getHistory(ob, countPurged=False) try: for version in versions: when = datetime.fromtimestamp(version.sys_metadata['timestamp']) version_id = version.version_id print proj_id, page.getId, version_id checkin = Checkin(pagename, version_id, when) session.add(checkin) logger.info("page: %s\tversion: %s" % (pagename, version_id)) session.commit() except (cPickle.UnpicklingError, pickle.UnpicklingError, POSKeyError), e: logger.error("Corruption error on page %s in project %s: %s" % ( pagename, project.getId(), str(e))) fp = open("/tmp/unpickle.txt", 'wa') print >> fp, "Corruption error on page %s in project %s: %s" % ( pagename, project.getId(), str(e)) fp.close() logger.info("page: %s\t-* current version *-" % pagename) when = ob.ModificationDate() when = zDateTime(when) when = when.timeTime() when = datetime.fromtimestamp(when) version_id = -99 checkin = Checkin(pagename, version_id, when) session.add(checkin) session.commit()