git-importer/lib/tree_builder.py
2022-10-26 14:16:22 +02:00

39 lines
1.3 KiB
Python

from lib.db_revision import DBRevision
from lib.request import Request
class TreeBuilder:
def __init__(self, db):
self.db = db
def filtered_revisions(self, project, package):
revisions = DBRevision.all_revisions(self.db, project, package)
revisions.sort()
ret = []
prev = None
for rev in revisions:
if rev.broken: continue
if prev and prev.files_hash(self.db) == rev.files_hash(self.db):
continue
ret.append(rev)
prev = rev
return ret
def build(self, package):
factory_revisions = self.filtered_revisions("openSUSE:Factory", package)
source_revisions = dict()
for rev in factory_revisions:
print(rev, rev.files_hash(self.db))
if rev.request_id:
req = Request.find(self.db, rev.request_id)
print(" ", req)
key = f"{req.source_project}/{req.source_package}"
if key not in source_revisions:
source_revisions[key] = self.filtered_revisions(
req.source_project, req.source_package
)
for rev2 in source_revisions.get(key):
if rev2.files_hash(self.db) == rev.files_hash(self.db):
print(" ", rev2)