Compare commits
No commits in common. "f5ffc83a69d98c8b454abfef5856a2936356864f" and "1e22c2895ac23cfd0132372916c53fc7bf50e574" have entirely different histories.
f5ffc83a69
...
1e22c2895a
@ -1,4 +1,4 @@
|
|||||||
sudo zypper in python3-psycopg
|
sudo zypper in python3-psycopg2
|
||||||
sudo su - postgres
|
sudo su - postgres
|
||||||
# `createdb -O <LOCAL_USER> imported_git`
|
# `createdb -O <LOCAL_USER> imported_git`
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ def config(filename="database.ini", section="production"):
|
|||||||
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"
|
"Section {0} not found in the {1} file".format(section, filename)
|
||||||
)
|
)
|
||||||
|
|
||||||
return db
|
return db
|
||||||
|
18
lib/db.py
18
lib/db.py
@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import psycopg
|
import psycopg2
|
||||||
|
from psycopg2.extras import LoggingConnection
|
||||||
|
|
||||||
from lib.config import config
|
from lib.config import config
|
||||||
|
|
||||||
@ -16,10 +17,11 @@ class DB:
|
|||||||
# read the connection parameters
|
# read the connection parameters
|
||||||
params = config(section=self.config_section)
|
params = config(section=self.config_section)
|
||||||
# connect to the PostgreSQL server
|
# connect to the PostgreSQL server
|
||||||
self.conn = psycopg.connect(conninfo=f"dbname={params['database']}")
|
self.conn = psycopg2.connect(connection_factory=LoggingConnection, **params)
|
||||||
logging.getLogger("psycopg.pool").setLevel(logging.INFO)
|
logger = logging.getLogger(__name__)
|
||||||
|
self.conn.initialize(logger)
|
||||||
|
|
||||||
except (Exception, psycopg.DatabaseError) as error:
|
except (Exception, psycopg2.DatabaseError) as error:
|
||||||
print(error)
|
print(error)
|
||||||
raise error
|
raise error
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ class DB:
|
|||||||
# 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 psycopg2.errors.UndefinedTable as error:
|
||||||
cur.close()
|
cur.close()
|
||||||
self.close()
|
self.close()
|
||||||
self.connect()
|
self.connect()
|
||||||
@ -144,9 +146,9 @@ class DB:
|
|||||||
)
|
)
|
||||||
schemes[10] = (
|
schemes[10] = (
|
||||||
"ALTER TABLE revisions ADD COLUMN request_id INTEGER",
|
"ALTER TABLE revisions ADD COLUMN request_id INTEGER",
|
||||||
"""ALTER TABLE revisions
|
"""ALTER TABLE revisions
|
||||||
ADD CONSTRAINT request_id_foreign_key
|
ADD CONSTRAINT request_id_foreign_key
|
||||||
FOREIGN KEY (request_id)
|
FOREIGN KEY (request_id)
|
||||||
REFERENCES requests (id)""",
|
REFERENCES requests (id)""",
|
||||||
"UPDATE scheme SET version=10",
|
"UPDATE scheme SET version=10",
|
||||||
)
|
)
|
||||||
@ -271,7 +273,7 @@ class DB:
|
|||||||
cur.execute(command)
|
cur.execute(command)
|
||||||
# commit the changes
|
# commit the changes
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
except (Exception, psycopg.DatabaseError) as error:
|
except (Exception, psycopg2.DatabaseError) as error:
|
||||||
print(error)
|
print(error)
|
||||||
self.close()
|
self.close()
|
||||||
raise error
|
raise error
|
||||||
|
@ -255,7 +255,7 @@ class DBRevision:
|
|||||||
self._files.sort(key=lambda x: x["name"])
|
self._files.sort(key=lambda x: x["name"])
|
||||||
return self._files
|
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.
|
"""Calculate the list of files to download and to delete.
|
||||||
Param current_rev is the revision that's currently checked out.
|
Param current_rev is the revision that's currently checked out.
|
||||||
If it's None, the repository is empty.
|
If it's None, the repository is empty.
|
||||||
|
@ -40,7 +40,7 @@ class GitExporter:
|
|||||||
def check_repo_state(self, flats, branch_state):
|
def check_repo_state(self, flats, branch_state):
|
||||||
state_data = dict()
|
state_data = dict()
|
||||||
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, "r") as f:
|
||||||
state_data = yaml.safe_load(f)
|
state_data = yaml.safe_load(f)
|
||||||
if type(state_data) != dict:
|
if type(state_data) != dict:
|
||||||
state_data = {}
|
state_data = {}
|
||||||
|
26
lib/obs.py
26
lib/obs.py
@ -148,12 +148,28 @@ class OBS:
|
|||||||
]
|
]
|
||||||
|
|
||||||
def _download(self, project, package, name, revision):
|
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(
|
url = osc.core.makeurl(
|
||||||
self.url,
|
self.url,
|
||||||
["source", project, package, name],
|
["source", project, package, urllib.parse.quote(name)],
|
||||||
{"rev": revision, "expand": 1},
|
{"rev": revision, "expand": 1, "deleted": 1 if deleted else ()},
|
||||||
)
|
)
|
||||||
return osc.core.http_GET(url)
|
return osc.core.http_request("GET", url)
|
||||||
|
|
||||||
def download(
|
def download(
|
||||||
self,
|
self,
|
||||||
|
@ -138,7 +138,7 @@ class TreeBuilder:
|
|||||||
self.requests.add(node.revision.request_id)
|
self.requests.add(node.revision.request_id)
|
||||||
|
|
||||||
class FindMergeWalker(AbstractWalker):
|
class FindMergeWalker(AbstractWalker):
|
||||||
def __init__(self, builder: TreeBuilder, requests: dict) -> None:
|
def __init__(self, builder: TreeBuilder, requests: Dict) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.source_revisions = dict()
|
self.source_revisions = dict()
|
||||||
self.builder = builder
|
self.builder = builder
|
||||||
|
Loading…
x
Reference in New Issue
Block a user