def load_db(): print "\nLoading pickled database %s" % sys.argv[2] db = file(sys.argv[2], 'r') data = pickle.load(db) # Load up all of the overrides for override in data.get('overrides', []): try: BuildRootOverride.byBuild(override['build']) except SQLObjectNotFound: BuildRootOverride(**override) # Legacy format was just a list of update dictionaries # Now we'll pull things out into an organized dictionary: # {'updates': [], 'releases': []} if isinstance(data, dict): for release in data['releases']: try: Release.byName(release['name']) except SQLObjectNotFound: Release(**release) data = data['updates'] progress = ProgressBar(maxValue=len(data)) for u in data: try: release = Release.byName(u['release'][0]) except SQLObjectNotFound: release = Release(name=u['release'][0], long_name=u['release'][1], id_prefix=u['release'][2], dist_tag=u['release'][3]) ## Backwards compatbility request = u['request'] if u['request'] == 'move': request = 'stable' elif u['request'] == 'push': request = 'testing' elif u['request'] == 'unpush': request = 'obsolete' if u['approved'] in (True, False): u['approved'] = None if 'update_id' in u: u['updateid'] = u['update_id'] if not 'date_modified' in u: u['date_modified'] = None try: update = PackageUpdate.byTitle(u['title']) except SQLObjectNotFound: update = PackageUpdate(title=u['title'], date_submitted=u['date_submitted'], date_pushed=u['date_pushed'], date_modified=u['date_modified'], release=release, submitter=u['submitter'], updateid=u['updateid'], type=u['type'], status=u['status'], pushed=u['pushed'], notes=u['notes'], karma=u['karma'], request=request, approved=u['approved']) ## Create Package and PackageBuild objects for pkg, nvr in u['builds']: try: package = Package.byName(pkg) except SQLObjectNotFound: package = Package(name=pkg) try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: build = PackageBuild(nvr=nvr, package=package) update.addPackageBuild(build) ## Create all Bugzilla objects for this update for bug_num, bug_title, security, parent in u['bugs']: try: bug = Bugzilla.byBz_id(bug_num) except SQLObjectNotFound: bug = Bugzilla(bz_id=bug_num, security=security, parent=parent) bug.title = bug_title update.addBugzilla(bug) ## Create all CVE objects for this update for cve_id in u['cves']: try: cve = CVE.byCve_id(cve_id) except SQLObjectNotFound: cve = CVE(cve_id=cve_id) update.addCVE(cve) for timestamp, author, text, karma, anonymous in u['comments']: comment = Comment(timestamp=timestamp, author=author, text=text, karma=karma, update=update, anonymous=anonymous) progress()
def load_db(): print "\nLoading pickled database %s" % sys.argv[2] db = file(sys.argv[2], "r") data = pickle.load(db) # Legacy format was just a list of update dictionaries # Now we'll pull things out into an organized dictionary: # {'updates': [], 'releases': []} if isinstance(data, dict): for release in data["releases"]: try: Release.byName(release["name"]) except SQLObjectNotFound: Release(**release) data = data["updates"] progress = ProgressBar(maxValue=len(data)) for u in data: try: release = Release.byName(u["release"][0]) except SQLObjectNotFound: release = Release( name=u["release"][0], long_name=u["release"][1], id_prefix=u["release"][2], dist_tag=u["release"][3] ) ## Backwards compatbility request = u["request"] if u["request"] == "move": request = "stable" elif u["request"] == "push": request = "testing" elif u["request"] == "unpush": request = "obsolete" if u["approved"] in (True, False): u["approved"] = None if u.has_key("update_id"): u["updateid"] = u["update_id"] if not u.has_key("date_modified"): u["date_modified"] = None try: update = PackageUpdate.byTitle(u["title"]) except SQLObjectNotFound: update = PackageUpdate( title=u["title"], date_submitted=u["date_submitted"], date_pushed=u["date_pushed"], date_modified=u["date_modified"], release=release, submitter=u["submitter"], updateid=u["updateid"], type=u["type"], status=u["status"], pushed=u["pushed"], notes=u["notes"], karma=u["karma"], request=request, approved=u["approved"], ) ## Create Package and PackageBuild objects for pkg, nvr in u["builds"]: try: package = Package.byName(pkg) except SQLObjectNotFound: package = Package(name=pkg) try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: build = PackageBuild(nvr=nvr, package=package) update.addPackageBuild(build) ## Create all Bugzilla objects for this update for bug_num, bug_title, security, parent in u["bugs"]: try: bug = Bugzilla.byBz_id(bug_num) except SQLObjectNotFound: bug = Bugzilla(bz_id=bug_num, security=security, parent=parent) bug.title = bug_title update.addBugzilla(bug) ## Create all CVE objects for this update for cve_id in u["cves"]: try: cve = CVE.byCve_id(cve_id) except SQLObjectNotFound: cve = CVE(cve_id=cve_id) update.addCVE(cve) for timestamp, author, text, karma, anonymous in u["comments"]: comment = Comment( timestamp=timestamp, author=author, text=text, karma=karma, update=update, anonymous=anonymous ) progress()
def load_db(): print "\nLoading pickled database %s" % sys.argv[2] db = file(sys.argv[2], 'r') data = pickle.load(db) # Legacy format was just a list of update dictionaries # Now we'll pull things out into an organized dictionary: # {'updates': [], 'releases': []} if isinstance(data, dict): for release in data['releases']: try: Release.byName(release['name']) except SQLObjectNotFound: Release(**release) data = data['updates'] progress = ProgressBar(maxValue=len(data)) for u in data: try: release = Release.byName(u['release'][0]) except SQLObjectNotFound: release = Release(name=u['release'][0], long_name=u['release'][1], id_prefix=u['release'][2], dist_tag=u['release'][3]) ## Backwards compatbility request = u['request'] if u['request'] == 'move': request = 'stable' elif u['request'] == 'push': request = 'testing' elif u['request'] == 'unpush': request = 'obsolete' if u['approved'] in (True, False): u['approved'] = None if u.has_key('update_id'): u['updateid'] = u['update_id'] if not u.has_key('date_modified'): u['date_modified'] = None try: update = PackageUpdate.byTitle(u['title']) except SQLObjectNotFound: update = PackageUpdate(title=u['title'], date_submitted=u['date_submitted'], date_pushed=u['date_pushed'], date_modified=u['date_modified'], release=release, submitter=u['submitter'], updateid=u['updateid'], type=u['type'], status=u['status'], pushed=u['pushed'], notes=u['notes'], karma=u['karma'], request=request, approved=u['approved']) ## Create Package and PackageBuild objects for pkg, nvr in u['builds']: try: package = Package.byName(pkg) except SQLObjectNotFound: package = Package(name=pkg) try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: build = PackageBuild(nvr=nvr, package=package) update.addPackageBuild(build) ## Create all Bugzilla objects for this update for bug_num, bug_title, security, parent in u['bugs']: try: bug = Bugzilla.byBz_id(bug_num) except SQLObjectNotFound: bug = Bugzilla(bz_id=bug_num, security=security, parent=parent) bug.title = bug_title update.addBugzilla(bug) ## Create all CVE objects for this update for cve_id in u['cves']: try: cve = CVE.byCve_id(cve_id) except SQLObjectNotFound: cve = CVE(cve_id=cve_id) update.addCVE(cve) for timestamp, author, text, karma, anonymous in u['comments']: comment = Comment(timestamp=timestamp, author=author, text=text, karma=karma, update=update, anonymous=anonymous) progress()