Compare commits

..

No commits in common. "f5ffc83a69d98c8b454abfef5856a2936356864f" and "1e22c2895ac23cfd0132372916c53fc7bf50e574" have entirely different histories.

7 changed files with 36 additions and 18 deletions

View File

@ -1,4 +1,4 @@
sudo zypper in python3-psycopg
sudo zypper in python3-psycopg2
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(
f"Section {section} not found in the {filename} file"
"Section {0} not found in the {1} file".format(section, filename)
)
return db

View File

@ -1,6 +1,7 @@
import logging
import psycopg
import psycopg2
from psycopg2.extras import LoggingConnection
from lib.config import config
@ -16,10 +17,11 @@ class DB:
# read the connection parameters
params = config(section=self.config_section)
# connect to the PostgreSQL server
self.conn = psycopg.connect(conninfo=f"dbname={params['database']}")
logging.getLogger("psycopg.pool").setLevel(logging.INFO)
self.conn = psycopg2.connect(connection_factory=LoggingConnection, **params)
logger = logging.getLogger(__name__)
self.conn.initialize(logger)
except (Exception, psycopg.DatabaseError) as error:
except (Exception, psycopg2.DatabaseError) as error:
print(error)
raise error
@ -30,7 +32,7 @@ class DB:
# execute a statement
try:
cur.execute("SELECT MAX(version) from scheme")
except psycopg.errors.UndefinedTable as error:
except psycopg2.errors.UndefinedTable as error:
cur.close()
self.close()
self.connect()
@ -144,9 +146,9 @@ class DB:
)
schemes[10] = (
"ALTER TABLE revisions ADD COLUMN request_id INTEGER",
"""ALTER TABLE revisions
"""ALTER TABLE revisions
ADD CONSTRAINT request_id_foreign_key
FOREIGN KEY (request_id)
FOREIGN KEY (request_id)
REFERENCES requests (id)""",
"UPDATE scheme SET version=10",
)
@ -271,7 +273,7 @@ class DB:
cur.execute(command)
# commit the changes
self.conn.commit()
except (Exception, psycopg.DatabaseError) as error:
except (Exception, psycopg2.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: DBRevision | None):
def calc_delta(self, current_rev: Optional[DBRevision]):
"""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) as f:
with open(self.state_file, "r") as f:
state_data = yaml.safe_load(f)
if type(state_data) != dict:
state_data = {}

View File

@ -148,12 +148,28 @@ 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, name],
{"rev": revision, "expand": 1},
)
return osc.core.http_GET(url)
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)
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