forked from adamm/git-importer
fixed formatting and other suggestions
This commit is contained in:
@@ -23,122 +23,115 @@ class DBRevision:
|
||||
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),
|
||||
)
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"INSERT INTO links (revision_id, project, package) VALUES (%s,%s,%s)",
|
||||
(self.dbid, project, package),
|
||||
)
|
||||
|
||||
@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, request_number)
|
||||
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.request_number,
|
||||
),
|
||||
)
|
||||
cur.close()
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, commit_time, userid, comment, request_number)
|
||||
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.request_number,
|
||||
),
|
||||
)
|
||||
return cls.fetch_revision(db, revision.project, revision.package, revision.rev)
|
||||
|
||||
@classmethod
|
||||
def fetch_revision(cls, db, project, package, rev):
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"SELECT * FROM revisions where project=%s and package=%s and rev=%s",
|
||||
(project, package, str(rev)),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
cur.close()
|
||||
@staticmethod
|
||||
def fetch_revision(db, project, package, rev):
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"SELECT * FROM revisions where project=%s and package=%s and rev=%s",
|
||||
(project, package, str(rev)),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
return DBRevision(row)
|
||||
|
||||
@classmethod
|
||||
def latest_revision(cls, db, project, package):
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"SELECT MAX(rev) FROM revisions where project=%s and package=%s",
|
||||
(project, package),
|
||||
)
|
||||
max = cur.fetchone()[0]
|
||||
cur.close()
|
||||
@staticmethod
|
||||
def latest_revision(db, project, package):
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"SELECT MAX(rev) FROM revisions where project=%s and package=%s",
|
||||
(project, package),
|
||||
)
|
||||
max = cur.fetchone()[0]
|
||||
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()
|
||||
@staticmethod
|
||||
def all_revisions(db, project, package):
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"SELECT * FROM revisions where project=%s and package=%s",
|
||||
(project, package),
|
||||
)
|
||||
ret = []
|
||||
for row in cur.fetchall():
|
||||
ret.append(DBRevision(row))
|
||||
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()
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"SELECT project,package FROM links where revision_id=%s", (self.dbid,)
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
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()]
|
||||
if revisions:
|
||||
return revisions[0]
|
||||
return None
|
||||
|
||||
def set_broken(self, db):
|
||||
cur = db.cursor()
|
||||
cur.execute("UPDATE revisions SET broken=TRUE where id=%s", (self.dbid,))
|
||||
cur.close()
|
||||
with db.cursor() as cur:
|
||||
cur.execute("UPDATE revisions SET broken=TRUE where id=%s", (self.dbid,))
|
||||
|
||||
|
||||
def import_dir_list(self, db, xml):
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"UPDATE revisions SET expanded_srcmd5=%s where id=%s",
|
||||
(xml.get("srcmd5"), self.dbid),
|
||||
)
|
||||
for entry in xml.findall("entry"):
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"""INSERT INTO files (name, md5, size, mtime, revision_id)
|
||||
VALUES (%s,%s,%s,%s,%s)""",
|
||||
(
|
||||
entry.get("name"),
|
||||
entry.get("md5"),
|
||||
entry.get("size"),
|
||||
entry.get("mtime"),
|
||||
self.dbid,
|
||||
),
|
||||
"UPDATE revisions SET expanded_srcmd5=%s where id=%s",
|
||||
(xml.get("srcmd5"), self.dbid),
|
||||
)
|
||||
cur.close()
|
||||
for entry in xml.findall("entry"):
|
||||
cur.execute(
|
||||
"""INSERT INTO files (name, md5, size, mtime, revision_id)
|
||||
VALUES (%s,%s,%s,%s,%s)""",
|
||||
(
|
||||
entry.get("name"),
|
||||
entry.get("md5"),
|
||||
entry.get("size"),
|
||||
entry.get("mtime"),
|
||||
self.dbid,
|
||||
),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def requests_to_fetch(self, db, project, package):
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"""SELECT request_number FROM revisions revs left join requests
|
||||
reqs on reqs.number=revs.request_number where reqs.id is null and
|
||||
revs.request_number is not null and project=%s and package=%s;""",
|
||||
(project, package),
|
||||
)
|
||||
ret = [row[0] for row in cur.fetchall()]
|
||||
cur.close()
|
||||
@staticmethod
|
||||
def requests_to_fetch(db, project, package):
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"""SELECT request_number FROM revisions revs left join requests
|
||||
reqs on reqs.number=revs.request_number where reqs.id is null and
|
||||
revs.request_number is not null and project=%s and package=%s;""",
|
||||
(project, package),
|
||||
)
|
||||
ret = [row[0] for row in cur.fetchall()]
|
||||
return ret
|
||||
|
Reference in New Issue
Block a user