2022-11-01 09:05:47 +01:00
|
|
|
FAKE_ACCOUNTS = (
|
|
|
|
"unknown",
|
|
|
|
"buildservice-autocommit",
|
|
|
|
"autobuild",
|
|
|
|
"_service",
|
|
|
|
"admin",
|
|
|
|
"jg",
|
|
|
|
"mrdocs",
|
|
|
|
"AdrianSuSE",
|
|
|
|
"$user",
|
|
|
|
"embar-",
|
|
|
|
"michel_mno",
|
|
|
|
)
|
2022-10-26 11:58:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class User:
|
|
|
|
def parse(self, xml, userid):
|
|
|
|
self.userid = userid
|
|
|
|
self.realname = xml.find("realname").text
|
|
|
|
self.email = xml.find("email").text
|
|
|
|
if self.email is None:
|
|
|
|
self.email = ""
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"User {self.userid}: {self.realname} {self.email}"
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"[{self.__str__()}]"
|
|
|
|
|
|
|
|
def import_into_db(self, db):
|
|
|
|
with db.cursor() as cur:
|
|
|
|
cur.execute(
|
|
|
|
"""INSERT INTO users (userid, realname, email)
|
|
|
|
VALUES (%s,%s,%s)""",
|
|
|
|
(
|
|
|
|
self.userid,
|
|
|
|
self.realname,
|
|
|
|
self.email,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def lookup(db, userid):
|
|
|
|
with db.cursor() as cur:
|
|
|
|
cur.execute("SELECT * FROM users where userid=%s", (userid,))
|
|
|
|
row = cur.fetchone()
|
|
|
|
if not row:
|
|
|
|
return None
|
|
|
|
return row
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def missing_users(db):
|
|
|
|
with db.cursor() as cur:
|
|
|
|
cur.execute(
|
|
|
|
"""SELECT DISTINCT revisions.userid
|
|
|
|
FROM revisions LEFT JOIN users ON revisions.userid = users.userid
|
2022-10-26 14:42:39 +02:00
|
|
|
WHERE users.userid IS NULL AND revisions.userid NOT IN {}""".format(
|
|
|
|
FAKE_ACCOUNTS
|
|
|
|
)
|
2022-10-26 11:58:01 +02:00
|
|
|
)
|
|
|
|
missing_users = [row[0] for row in cur.fetchall()]
|
|
|
|
return missing_users
|