Code cleanup

This commit is contained in:
Dirk Müller 2024-05-16 15:47:45 +02:00
parent f5ffc83a69
commit 39fde7744a
No known key found for this signature in database
8 changed files with 5 additions and 12 deletions

View File

@ -14,8 +14,6 @@ def config(filename="database.ini", section="production"):
for param in params: for param in params:
db[param[0]] = param[1] db[param[0]] = param[1]
else: else:
raise Exception( raise Exception(f"Section {section} not found in the {filename} file")
f"Section {section} not found in the {filename} file"
)
return db return db

View File

@ -26,11 +26,10 @@ class DB:
def schema_version(self): def schema_version(self):
# create a cursor # create a cursor
with self.conn.cursor() as cur: with self.conn.cursor() as cur:
# execute a statement # execute a statement
try: try:
cur.execute("SELECT MAX(version) from scheme") cur.execute("SELECT MAX(version) from scheme")
except psycopg.errors.UndefinedTable as error: except psycopg.errors.UndefinedTable:
cur.close() cur.close()
self.close() self.close()
self.connect() self.connect()

View File

@ -2,7 +2,6 @@ from __future__ import annotations
from hashlib import md5 from hashlib import md5
from pathlib import Path from pathlib import Path
from typing import Optional
from lib.db import DB from lib.db import DB
from lib.obs_revision import OBSRevision from lib.obs_revision import OBSRevision
@ -206,7 +205,7 @@ class DBRevision:
): ):
continue continue
cur.execute( cur.execute(
"""INSERT INTO files (name, md5, size, mtime, revision_id) """INSERT INTO files (name, md5, size, mtime, revision_id)
VALUES (%s,%s,%s,%s,%s)""", VALUES (%s,%s,%s,%s,%s)""",
( (
entry.get("name"), entry.get("name"),

View File

@ -42,7 +42,7 @@ class GitExporter:
if os.path.exists(self.state_file): if os.path.exists(self.state_file):
with open(self.state_file) as f: with open(self.state_file) as f:
state_data = yaml.safe_load(f) state_data = yaml.safe_load(f)
if type(state_data) != dict: if not isinstance(state_data, dict):
state_data = {} state_data = {}
left_to_commit = [] left_to_commit = []
for flat in reversed(flats): for flat in reversed(flats):

View File

@ -167,7 +167,7 @@ class Importer:
with self.db.cursor() as cur: with self.db.cursor() as cur:
cur.execute( cur.execute(
"SELECT * FROM revisions WHERE package=%s AND broken=FALSE AND expanded_srcmd5 IS NULL", "SELECT * FROM revisions WHERE package=%s AND broken=FALSE AND expanded_srcmd5 IS NULL",
(package, ) (package,),
) )
return [DBRevision(self.db, row) for row in cur.fetchall()] return [DBRevision(self.db, row) for row in cur.fetchall()]

View File

@ -165,7 +165,6 @@ class OBS:
cachedir: str, cachedir: str,
file_md5: str, file_md5: str,
) -> None: ) -> None:
cached_file = self._path_from_md5(name, cachedir, file_md5) cached_file = self._path_from_md5(name, cachedir, file_md5)
if not self.in_cache(name, cachedir, file_md5): if not self.in_cache(name, cachedir, file_md5):
with (dirpath / name).open("wb") as f: with (dirpath / name).open("wb") as f:

View File

@ -41,7 +41,6 @@ class ProxySHA256:
} }
def put(self, project, package, name, revision, file_md5, size): def put(self, project, package, name, revision, file_md5, size):
if not self.mime: if not self.mime:
self.mime = magic.Magic(mime=True) self.mime = magic.Magic(mime=True)

View File

@ -1,4 +1,3 @@
from typing import Dict
from xmlrpc.client import Boolean from xmlrpc.client import Boolean
from lib.db_revision import DBRevision from lib.db_revision import DBRevision