From 39fde7744ae8d79766e7a3aa2fda9e1a38cd5ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dirk=20M=C3=BCller?= Date: Thu, 16 May 2024 15:47:45 +0200 Subject: [PATCH] Code cleanup --- lib/config.py | 4 +--- lib/db.py | 3 +-- lib/db_revision.py | 3 +-- lib/git_exporter.py | 2 +- lib/importer.py | 2 +- lib/obs.py | 1 - lib/proxy_sha256.py | 1 - lib/tree_builder.py | 1 - 8 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/config.py b/lib/config.py index c8dc2c9..b2a5aad 100644 --- a/lib/config.py +++ b/lib/config.py @@ -14,8 +14,6 @@ def config(filename="database.ini", section="production"): for param in params: db[param[0]] = param[1] else: - raise Exception( - f"Section {section} not found in the {filename} file" - ) + raise Exception(f"Section {section} not found in the {filename} file") return db diff --git a/lib/db.py b/lib/db.py index f18a169..a264f2b 100644 --- a/lib/db.py +++ b/lib/db.py @@ -26,11 +26,10 @@ class DB: def schema_version(self): # create a cursor with self.conn.cursor() as cur: - # execute a statement try: cur.execute("SELECT MAX(version) from scheme") - except psycopg.errors.UndefinedTable as error: + except psycopg.errors.UndefinedTable: cur.close() self.close() self.connect() diff --git a/lib/db_revision.py b/lib/db_revision.py index cdc246f..bb56722 100644 --- a/lib/db_revision.py +++ b/lib/db_revision.py @@ -2,7 +2,6 @@ from __future__ import annotations from hashlib import md5 from pathlib import Path -from typing import Optional from lib.db import DB from lib.obs_revision import OBSRevision @@ -206,7 +205,7 @@ class DBRevision: ): continue 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)""", ( entry.get("name"), diff --git a/lib/git_exporter.py b/lib/git_exporter.py index 76313df..36ebf73 100644 --- a/lib/git_exporter.py +++ b/lib/git_exporter.py @@ -42,7 +42,7 @@ class GitExporter: if os.path.exists(self.state_file): with open(self.state_file) as f: state_data = yaml.safe_load(f) - if type(state_data) != dict: + if not isinstance(state_data, dict): state_data = {} left_to_commit = [] for flat in reversed(flats): diff --git a/lib/importer.py b/lib/importer.py index c086f85..6ec511f 100644 --- a/lib/importer.py +++ b/lib/importer.py @@ -167,7 +167,7 @@ class Importer: with self.db.cursor() as cur: cur.execute( "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()] diff --git a/lib/obs.py b/lib/obs.py index a959c85..147b051 100644 --- a/lib/obs.py +++ b/lib/obs.py @@ -165,7 +165,6 @@ class OBS: cachedir: str, file_md5: str, ) -> None: - cached_file = self._path_from_md5(name, cachedir, file_md5) if not self.in_cache(name, cachedir, file_md5): with (dirpath / name).open("wb") as f: diff --git a/lib/proxy_sha256.py b/lib/proxy_sha256.py index 73648a9..605af08 100644 --- a/lib/proxy_sha256.py +++ b/lib/proxy_sha256.py @@ -41,7 +41,6 @@ class ProxySHA256: } def put(self, project, package, name, revision, file_md5, size): - if not self.mime: self.mime = magic.Magic(mime=True) diff --git a/lib/tree_builder.py b/lib/tree_builder.py index 65a5594..8f179d5 100644 --- a/lib/tree_builder.py +++ b/lib/tree_builder.py @@ -1,4 +1,3 @@ -from typing import Dict from xmlrpc.client import Boolean from lib.db_revision import DBRevision