Fix confusion about User constructor

This commit is contained in:
Stephan Kulow 2022-11-07 16:04:23 +01:00
parent 86490b51dd
commit e1b32999f0
2 changed files with 9 additions and 2 deletions

View File

@ -75,7 +75,7 @@ class GitExporter:
for flat in left_to_commit: for flat in left_to_commit:
if flat.commit.userid not in users: if flat.commit.userid not in users:
users[flat.commit.userid] = User(db, flat.commit.userid) users[flat.commit.userid] = User.find(db, flat.commit.userid)
flat.user = users[flat.commit.userid] flat.user = users[flat.commit.userid]
logging.debug(f"USER {flat.user}") logging.debug(f"USER {flat.user}")
self.gc_cnt -= 1 self.gc_cnt -= 1

View File

@ -1,3 +1,7 @@
from __future__ import annotations
from lib.db import DB
FAKE_ACCOUNTS = ( FAKE_ACCOUNTS = (
"unknown", "unknown",
"buildservice-autocommit", "buildservice-autocommit",
@ -15,8 +19,10 @@ FAKE_ACCOUNTS = (
class User: class User:
def __init__(self, db, userid) -> None: @staticmethod
def find(db: DB, userid: str) -> User:
row = User.lookup(db, userid) row = User.lookup(db, userid)
self = User()
self.userid = userid self.userid = userid
if row: if row:
(_, _, self.email, self.realname) = row (_, _, self.email, self.realname) = row
@ -27,6 +33,7 @@ class User:
self.email = "null@suse.de" self.email = "null@suse.de"
if not self.realname: if not self.realname:
self.realname = f"OBS User {userid}" self.realname = f"OBS User {userid}"
return self
def parse(self, xml, userid): def parse(self, xml, userid):
self.userid = userid self.userid = userid