Compare commits
4 Commits
1e22c2895a
...
f5ffc83a69
Author | SHA1 | Date | |
---|---|---|---|
|
f5ffc83a69 | ||
|
d0ccf83684 | ||
|
b0ffb01c59 | ||
|
28d5c6e606 |
@ -1,4 +1,4 @@
|
|||||||
sudo zypper in python3-psycopg2
|
sudo zypper in python3-psycopg
|
||||||
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(
|
||||||
"Section {0} not found in the {1} file".format(section, filename)
|
f"Section {section} not found in the {filename} file"
|
||||||
)
|
)
|
||||||
|
|
||||||
return db
|
return db
|
||||||
|
14
lib/db.py
14
lib/db.py
@ -1,7 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import psycopg2
|
import psycopg
|
||||||
from psycopg2.extras import LoggingConnection
|
|
||||||
|
|
||||||
from lib.config import config
|
from lib.config import config
|
||||||
|
|
||||||
@ -17,11 +16,10 @@ 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 = psycopg2.connect(connection_factory=LoggingConnection, **params)
|
self.conn = psycopg.connect(conninfo=f"dbname={params['database']}")
|
||||||
logger = logging.getLogger(__name__)
|
logging.getLogger("psycopg.pool").setLevel(logging.INFO)
|
||||||
self.conn.initialize(logger)
|
|
||||||
|
|
||||||
except (Exception, psycopg2.DatabaseError) as error:
|
except (Exception, psycopg.DatabaseError) as error:
|
||||||
print(error)
|
print(error)
|
||||||
raise error
|
raise error
|
||||||
|
|
||||||
@ -32,7 +30,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 psycopg2.errors.UndefinedTable as error:
|
except psycopg.errors.UndefinedTable as error:
|
||||||
cur.close()
|
cur.close()
|
||||||
self.close()
|
self.close()
|
||||||
self.connect()
|
self.connect()
|
||||||
@ -273,7 +271,7 @@ class DB:
|
|||||||
cur.execute(command)
|
cur.execute(command)
|
||||||
# commit the changes
|
# commit the changes
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
except (Exception, psycopg2.DatabaseError) as error:
|
except (Exception, psycopg.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: Optional[DBRevision]):
|
def calc_delta(self, current_rev: DBRevision | None):
|
||||||
"""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, "r") 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 type(state_data) != dict:
|
||||||
state_data = {}
|
state_data = {}
|
||||||
|
22
lib/obs.py
22
lib/obs.py
@ -148,28 +148,12 @@ 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(
|
url = osc.core.makeurl(
|
||||||
self.url,
|
self.url,
|
||||||
["source", project, package, urllib.parse.quote(name)],
|
["source", project, package, name],
|
||||||
{"rev": revision, "expand": 1, "deleted": deleted if deleted else ()},
|
{"rev": revision, "expand": 1},
|
||||||
)
|
)
|
||||||
try:
|
return osc.core.http_GET(url)
|
||||||
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)
|
|
||||||
|
|
||||||
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