forked from importers/git-importer
added user table and import function
This commit is contained in:
parent
eae411941b
commit
5ed847de8b
12
lib/db.py
12
lib/db.py
@ -154,6 +154,18 @@ class DB:
|
|||||||
"create index request_number_idx2 on requests(number)",
|
"create index request_number_idx2 on requests(number)",
|
||||||
"UPDATE scheme SET version=12",
|
"UPDATE scheme SET version=12",
|
||||||
)
|
)
|
||||||
|
schemes[13] = (
|
||||||
|
"""
|
||||||
|
CREATE TABLE users (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
userid VARCHAR(255) NOT NULL,
|
||||||
|
login VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL,
|
||||||
|
realname VARCHAR(255) NOT NULL
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
"UPDATE scheme SET version=13",
|
||||||
|
)
|
||||||
|
|
||||||
schema_version = self.schema_version()
|
schema_version = self.schema_version()
|
||||||
if (schema_version + 1) not in schemes:
|
if (schema_version + 1) not in schemes:
|
||||||
|
14
lib/obs.py
14
lib/obs.py
@ -8,6 +8,7 @@ from urllib.error import HTTPError
|
|||||||
import osc.core
|
import osc.core
|
||||||
|
|
||||||
from lib.request import Request
|
from lib.request import Request
|
||||||
|
from lib.users import Users
|
||||||
|
|
||||||
|
|
||||||
# Add a retry wrapper for some of the HTTP actions.
|
# Add a retry wrapper for some of the HTTP actions.
|
||||||
@ -84,6 +85,14 @@ class OBS:
|
|||||||
return None
|
return None
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
def _users(self, userid, **params):
|
||||||
|
try:
|
||||||
|
root = self._xml(f"/person/{userid}", **params)
|
||||||
|
except HTTPError:
|
||||||
|
logging.error(f"UserID {userid} not found")
|
||||||
|
return None
|
||||||
|
return root
|
||||||
|
|
||||||
def _link(self, project, package, rev):
|
def _link(self, project, package, rev):
|
||||||
try:
|
try:
|
||||||
root = self._xml(f"source/{project}/{package}/_link", rev=rev)
|
root = self._xml(f"source/{project}/{package}/_link", rev=rev)
|
||||||
@ -122,6 +131,11 @@ class OBS:
|
|||||||
if root is not None:
|
if root is not None:
|
||||||
return Request().parse(root)
|
return Request().parse(root)
|
||||||
|
|
||||||
|
def users(self, userid):
|
||||||
|
root = self._users(userid)
|
||||||
|
if root is not None:
|
||||||
|
return Users().parse(root, userid)
|
||||||
|
|
||||||
def files(self, project, package, revision):
|
def files(self, project, package, revision):
|
||||||
root = self._xml(f"source/{project}/{package}", rev=revision, expand=1)
|
root = self._xml(f"source/{project}/{package}", rev=revision, expand=1)
|
||||||
return [
|
return [
|
||||||
|
38
lib/users.py
Normal file
38
lib/users.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
class Users:
|
||||||
|
def parse(self, xml, userid):
|
||||||
|
self.userid = userid
|
||||||
|
self.login = xml.get("login")
|
||||||
|
self.realname = xml.find("login").get("realname")
|
||||||
|
self.email = xml.find("login").get("email")
|
||||||
|
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"User {self.userid} {self.login}: {self.realname} {self.email}"
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"[{self.__str__()}]"
|
||||||
|
|
||||||
|
def import_into_db(self, db):
|
||||||
|
cur = db.cursor()
|
||||||
|
cur.execute(
|
||||||
|
"""INSERT INTO users (userid, login, realname, email)
|
||||||
|
VALUES (%s,%s,%s,%s) RETURNING id""",
|
||||||
|
(
|
||||||
|
self.userid,
|
||||||
|
self.login,
|
||||||
|
self.realname,
|
||||||
|
self.email,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
cur.close()
|
||||||
|
|
||||||
|
def user_lookup(self, db, userid):
|
||||||
|
cur= db.cursor()
|
||||||
|
cur.execute("SELECT * FROM users where userid=%s", (userid,))
|
||||||
|
row = cur.fetchone()
|
||||||
|
if not row:
|
||||||
|
cur.close()
|
||||||
|
return None
|
||||||
|
return row
|
||||||
|
|
Loading…
Reference in New Issue
Block a user