diff --git a/lib/db_revision.py b/lib/db_revision.py index 7fe99c8..3840a5b 100644 --- a/lib/db_revision.py +++ b/lib/db_revision.py @@ -13,12 +13,17 @@ class DBRevision: self.requestid, ) = row + def __str__(self): + return f"Rev {self.project}/{self.rev} Md5 {self.unexpanded_srcmd5} {self.commit_time} {self.userid} {self.requestid}" + + def __repr__(self): + return f"[{self.__str__()}]" + def links_to(self, db, project, package): db.cursor().execute( "INSERT INTO links (revision_id, project, package) VALUES (%s,%s,%s)", (self.dbid, project, package), ) - print("links_to", project, package) @classmethod def import_obs_rev(cls, db, revision): @@ -63,3 +68,36 @@ class DBRevision: if max: return DBRevision.fetch_revision(db, project, package, int(max)) return None + + @classmethod + def all_revisions(cls, db, project, package): + cur = db.cursor() + cur.execute( + "SELECT * FROM revisions where project=%s and package=%s", + (project, package), + ) + ret = [] + for row in cur.fetchall(): + ret.append(DBRevision(row)) + cur.close() + return ret + + def linked_rev(self, db): + cur = db.cursor() + cur.execute( + "SELECT project,package FROM links where revision_id=%s", (self.dbid,) + ) + row = cur.fetchone() + if not row: + cur.close() + return None + project, package = row + cur.execute( + "SELECT * FROM revisions where project=%s and package=%s and commit_time <= %s ORDER BY commit_time DESC LIMIT 1", + (project, package, self.commit_time), + ) + revisions = [DBRevision(row) for row in cur.fetchall()] + cur.close() + if revisions: + return revisions[0] + return None diff --git a/lib/importer.py b/lib/importer.py index 2c49369..938fed4 100644 --- a/lib/importer.py +++ b/lib/importer.py @@ -133,7 +133,7 @@ class Importer: if not latest or rev.rev > latest.rev: dbrev = DBRevision.import_obs_rev(db, rev) root = rev.read_link() - if root: + if root is not None: tprj = root.get("project") or project tpkg = root.get("package") or package dbrev.links_to(db, tprj, tpkg) @@ -152,6 +152,10 @@ class Importer: for row in cur.fetchall(): (lproject, lpackage) = row self.update_db_package(db, lproject, lpackage) + + for rev in DBRevision.all_revisions(db, project, self.package): + print(rev, rev.linked_rev(db)) + cur.close() def import_all_revisions(self, gc):