2022-10-18 12:17:43 +02:00
|
|
|
class DBRevision:
|
|
|
|
def __init__(self, row):
|
2022-10-18 13:13:52 +02:00
|
|
|
# need to stay in sync with the schema creation in db.py
|
|
|
|
(
|
|
|
|
self.dbid,
|
|
|
|
self.project,
|
|
|
|
self.package,
|
|
|
|
self.rev,
|
|
|
|
self.unexpanded_srcmd5,
|
|
|
|
self.commit_time,
|
|
|
|
self.userid,
|
|
|
|
self.comment,
|
|
|
|
self.requestid,
|
|
|
|
) = row
|
|
|
|
|
|
|
|
def links_to(self, db, project, package):
|
2022-10-18 13:48:27 +02:00
|
|
|
db.cursor().execute(
|
|
|
|
"INSERT INTO links (revision_id, project, package) VALUES (%s,%s,%s)",
|
|
|
|
(self.dbid, project, package),
|
|
|
|
)
|
|
|
|
print("links_to", project, package)
|
|
|
|
|
2022-10-18 13:13:52 +02:00
|
|
|
@classmethod
|
|
|
|
def import_obs_rev(cls, db, revision):
|
|
|
|
cur = db.cursor()
|
|
|
|
cur.execute(
|
|
|
|
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, commit_time, userid, comment, requestid)
|
|
|
|
VALUES(%s, %s, %s, %s, %s, %s, %s, %s)""",
|
|
|
|
(
|
|
|
|
revision.project,
|
|
|
|
revision.package,
|
|
|
|
revision.rev,
|
|
|
|
revision.unexpanded_srcmd5,
|
|
|
|
revision.time,
|
|
|
|
revision.userid,
|
|
|
|
revision.comment,
|
|
|
|
revision.requestid,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
cur.close()
|
|
|
|
return cls.fetch_revision(db, revision.project, revision.package, revision.rev)
|
2022-10-18 12:17:43 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def fetch_revision(cls, db, project, package, rev):
|
|
|
|
cur = db.cursor()
|
2022-10-18 13:13:52 +02:00
|
|
|
cur.execute(
|
|
|
|
"SELECT * FROM revisions where project=%s and package=%s and rev=%s",
|
2022-10-18 13:48:27 +02:00
|
|
|
(project, package, str(rev)),
|
2022-10-18 13:13:52 +02:00
|
|
|
)
|
2022-10-18 12:17:43 +02:00
|
|
|
row = cur.fetchone()
|
|
|
|
cur.close()
|
|
|
|
return DBRevision(row)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def latest_revision(cls, db, project, package):
|
|
|
|
cur = db.cursor()
|
2022-10-18 13:13:52 +02:00
|
|
|
cur.execute(
|
|
|
|
"SELECT MAX(rev) FROM revisions where project=%s and package=%s",
|
|
|
|
(project, package),
|
|
|
|
)
|
2022-10-18 12:17:43 +02:00
|
|
|
max = cur.fetchone()[0]
|
|
|
|
cur.close()
|
|
|
|
if max:
|
|
|
|
return DBRevision.fetch_revision(db, project, package, int(max))
|
|
|
|
return None
|