Compare commits

...

4 Commits

Author SHA1 Message Date
Dirk Müller
f5ffc83a69
Remove double quoting of url parameters
makeurl quotes by itself, so this was messing it up
2024-05-16 11:49:14 +02:00
Dirk Müller
d0ccf83684
Revert "Try to fetch the element as deleted if initial access failed"
The OBS api has been fixed to provide an automatic fallback via
https://github.com/openSUSE/open-build-service/pull/15655

This reverts commit c9e07e536f19820c4bba1f11e2edcb23069874d7.
2024-05-16 11:49:14 +02:00
Dirk Müller
b0ffb01c59
cleanups 2024-05-16 11:49:14 +02:00
Dirk Müller
28d5c6e606
Switch to psycopg rather than psycopg2
It's a bit more modern and uses dedicated c bindings
2024-05-16 11:49:14 +02:00
7 changed files with 18 additions and 36 deletions

View File

@ -1,4 +1,4 @@
sudo zypper in python3-psycopg2
sudo zypper in python3-psycopg
sudo su - postgres
# `createdb -O <LOCAL_USER> imported_git`

View File

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

View File

@ -1,7 +1,6 @@
import logging
import psycopg2
from psycopg2.extras import LoggingConnection
import psycopg
from lib.config import config
@ -17,11 +16,10 @@ class DB:
# read the connection parameters
params = config(section=self.config_section)
# connect to the PostgreSQL server
self.conn = psycopg2.connect(connection_factory=LoggingConnection, **params)
logger = logging.getLogger(__name__)
self.conn.initialize(logger)
self.conn = psycopg.connect(conninfo=f"dbname={params['database']}")
logging.getLogger("psycopg.pool").setLevel(logging.INFO)
except (Exception, psycopg2.DatabaseError) as error:
except (Exception, psycopg.DatabaseError) as error:
print(error)
raise error
@ -32,7 +30,7 @@ class DB:
# execute a statement
try:
cur.execute("SELECT MAX(version) from scheme")
except psycopg2.errors.UndefinedTable as error:
except psycopg.errors.UndefinedTable as error:
cur.close()
self.close()
self.connect()
@ -273,7 +271,7 @@ class DB:
cur.execute(command)
# commit the changes
self.conn.commit()
except (Exception, psycopg2.DatabaseError) as error:
except (Exception, psycopg.DatabaseError) as error:
print(error)
self.close()
raise error

View File

@ -255,7 +255,7 @@ class DBRevision:
self._files.sort(key=lambda x: x["name"])
return self._files
def calc_delta(self, current_rev: Optional[DBRevision]):
def calc_delta(self, current_rev: DBRevision | None):
"""Calculate the list of files to download and to delete.
Param current_rev is the revision that's currently checked out.
If it's None, the repository is empty.

View File

@ -40,7 +40,7 @@ class GitExporter:
def check_repo_state(self, flats, branch_state):
state_data = dict()
if os.path.exists(self.state_file):
with open(self.state_file, "r") as f:
with open(self.state_file) as f:
state_data = yaml.safe_load(f)
if type(state_data) != dict:
state_data = {}

View File

@ -148,28 +148,12 @@ class OBS:
]
def _download(self, project, package, name, revision):
# the object might be deleted but we can only pass deleted=1
# if it is actually deleted
deleted = 0
while deleted < 2:
url = osc.core.makeurl(
self.url,
["source", project, package, urllib.parse.quote(name)],
{"rev": revision, "expand": 1, "deleted": deleted if deleted else ()},
)
try:
osc.core.http_request("HEAD", url)
break
except Exception:
pass
deleted += 1
url = osc.core.makeurl(
self.url,
["source", project, package, urllib.parse.quote(name)],
{"rev": revision, "expand": 1, "deleted": 1 if deleted else ()},
)
return osc.core.http_request("GET", url)
self.url,
["source", project, package, name],
{"rev": revision, "expand": 1},
)
return osc.core.http_GET(url)
def download(
self,

View File

@ -138,7 +138,7 @@ class TreeBuilder:
self.requests.add(node.revision.request_id)
class FindMergeWalker(AbstractWalker):
def __init__(self, builder: TreeBuilder, requests: Dict) -> None:
def __init__(self, builder: TreeBuilder, requests: dict) -> None:
super().__init__()
self.source_revisions = dict()
self.builder = builder