2022-10-17 14:53:18 +02:00
|
|
|
class Request:
|
|
|
|
def parse(self, xml):
|
2022-10-19 14:00:07 +02:00
|
|
|
self.number = int(xml.get("id"))
|
2022-10-17 14:53:18 +02:00
|
|
|
self.creator = xml.get("creator")
|
2022-10-19 14:00:07 +02:00
|
|
|
self.state = xml.find("state").get("name")
|
2022-10-21 15:02:02 +02:00
|
|
|
# not used in the database
|
2022-10-20 08:57:14 +02:00
|
|
|
self.target = xml.find("action/target").get("project")
|
2022-10-17 14:53:18 +02:00
|
|
|
|
|
|
|
self.type_ = xml.find("action").get("type")
|
|
|
|
if self.type_ == "delete":
|
2022-10-20 08:57:14 +02:00
|
|
|
self.source_package = None
|
|
|
|
self.source_project = None
|
|
|
|
self.source_rev = None
|
2022-10-17 14:53:18 +02:00
|
|
|
# not much to do
|
|
|
|
return self
|
|
|
|
|
2022-10-19 14:00:07 +02:00
|
|
|
self.source_project = xml.find("action/source").get("project")
|
|
|
|
self.source_package = xml.find("action/source").get("package")
|
|
|
|
|
2022-10-17 14:53:18 +02:00
|
|
|
# expanded MD5 or commit revision
|
2022-10-19 14:00:07 +02:00
|
|
|
self.source_rev = xml.find("action/source").get("rev")
|
2022-10-17 14:53:18 +02:00
|
|
|
|
|
|
|
# TODO: support muti-action requests
|
|
|
|
# TODO: parse review history
|
|
|
|
# TODO: add description
|
|
|
|
return self
|
|
|
|
|
|
|
|
def type(self):
|
|
|
|
return self.type_
|
|
|
|
|
|
|
|
def __str__(self):
|
2022-10-21 15:02:02 +02:00
|
|
|
return f"Req {self.number} {self.creator} {self.type_} {self.source_project} {self.state}"
|
2022-10-17 14:53:18 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"[{self.__str__()}]"
|
2022-10-19 14:00:07 +02:00
|
|
|
|
|
|
|
def import_into_db(self, db):
|
2022-10-26 11:58:01 +02:00
|
|
|
with db.cursor() as cur:
|
|
|
|
cur.execute(
|
|
|
|
"""INSERT INTO requests (number, creator, type, state,
|
|
|
|
source_project, source_package, source_rev)
|
|
|
|
VALUES (%s,%s,%s,%s,%s,%s,%s) RETURNING id""",
|
|
|
|
(
|
|
|
|
self.number,
|
|
|
|
self.creator,
|
|
|
|
self.type_,
|
|
|
|
self.state,
|
|
|
|
self.source_project,
|
|
|
|
self.source_package,
|
|
|
|
self.source_rev,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
rowid = cur.fetchone()[0]
|
|
|
|
cur.execute(
|
|
|
|
"UPDATE revisions SET request_id=%s WHERE request_number=%s",
|
|
|
|
(rowid, self.number),
|
|
|
|
)
|
2022-10-21 09:48:31 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def find(db, request_id):
|
|
|
|
with db.cursor() as cur:
|
|
|
|
cur.execute("""SELECT * from requests WHERE id=%s""", (request_id,))
|
|
|
|
row = cur.fetchone()
|
2022-10-31 08:03:01 +01:00
|
|
|
return Request.from_db(row)
|
2022-10-21 09:48:31 +02:00
|
|
|
|
2022-10-31 08:03:01 +01:00
|
|
|
@staticmethod
|
|
|
|
def from_db(row):
|
|
|
|
ret = Request()
|
2022-10-21 09:48:31 +02:00
|
|
|
(
|
2022-10-31 08:03:01 +01:00
|
|
|
ret.dbid,
|
|
|
|
ret.number,
|
|
|
|
ret.creator,
|
|
|
|
ret.type_,
|
|
|
|
ret.state,
|
|
|
|
ret.source_package,
|
|
|
|
ret.source_project,
|
|
|
|
ret.source_rev,
|
2022-10-21 09:48:31 +02:00
|
|
|
) = row
|
2022-10-31 08:03:01 +01:00
|
|
|
return ret
|
2022-10-21 09:48:31 +02:00
|
|
|
|
|
|
|
def as_dict(self):
|
|
|
|
return {
|
|
|
|
"number": self.number,
|
|
|
|
"creator": self.creator,
|
|
|
|
"type": self.type_,
|
|
|
|
"state": self.state,
|
|
|
|
"source_project": self.source_project,
|
|
|
|
"source_package": self.source_package,
|
|
|
|
"source_rev": self.source_rev,
|
|
|
|
}
|