Skip to content

Commit

Permalink
Migrate Fetcher.run() to obs_api.Keyinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Mar 14, 2024
1 parent b8ab169 commit 7f6c0b3
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions osc/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# either version 2, or (at your option) any later version.


import glob
import os
import re
import shutil
Expand Down Expand Up @@ -288,49 +289,47 @@ def run(self, buildinfo):
self.__fetch_cpio(buildinfo.apiurl)

prjs = list(buildinfo.projects.keys())
for i in prjs:
dest = f"{self.cachedir}/{i}"
if not os.path.exists(dest):
os.makedirs(dest, mode=0o755)
dest += '/_pubkey'

url = makeurl(buildinfo.apiurl, ['source', i, '_pubkey'])
try_parent = False
try:
if self.offline and not os.path.exists(dest):
# may need to try parent
try_parent = True
elif not self.offline:
OscFileGrabber().urlgrab(url, dest)
# not that many keys usually
if i not in buildinfo.prjkeys and not try_parent:
buildinfo.keys.append(dest)
buildinfo.prjkeys.append(i)
except KeyboardInterrupt:
print('Cancelled by user (ctrl-c)')
print('Exiting.')
if os.path.exists(dest):
os.unlink(dest)
sys.exit(0)
except HTTPError as e:
# Not found is okay, let's go to the next project
if e.code != 404:
print("Invalid answer from server", e, file=sys.stderr)
sys.exit(1)
try_parent = True
for prj in prjs:
dest = os.path.join(self.cachedir, prj)
pubkey_path_base = os.path.join(dest, "_pubkey")
pubkey_paths = glob.glob(f"{pubkey_path_base}*")

Check warning on line 295 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L292-L295

Added lines #L292 - L295 were not covered by tests

if try_parent:
if self.http_debug:
print(f"can't fetch key for {i}", file=sys.stderr)
print(f"url: {url}", file=sys.stderr)
if self.offline:

Check warning on line 297 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L297

Added line #L297 was not covered by tests
# we're offline, only index the keys found on disk
if pubkey_paths:
for pubkey_path in pubkey_paths:
buildinfo.keys.append(pubkey_path)
buildinfo.prjkeys.append(prj)
continue

Check warning on line 303 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L299-L303

Added lines #L299 - L303 were not covered by tests

if os.path.exists(dest):
os.unlink(dest)
from . import obs_api

Check warning on line 305 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L305

Added line #L305 was not covered by tests

l = i.rsplit(':', 1)
# try key from parent project
if len(l) > 1 and l[1] and not l[0] in buildinfo.projects:
prjs.append(l[0])
os.makedirs(dest, mode=0o755, exist_ok=True)
pubkeys = []

Check warning on line 308 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L307-L308

Added lines #L307 - L308 were not covered by tests

try:
keyinfo = obs_api.Keyinfo.from_api(buildinfo.apiurl, prj)
for pubkey in keyinfo.pubkey_list or []:
pubkeys.append(pubkey.value)
except HTTPError as e:
result = obs_api.Keyinfo.get_pubkey_deprecated(buildinfo.apiurl, prj, traverse=True)
if result:

Check warning on line 316 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L310-L316

Added lines #L310 - L316 were not covered by tests
# overwrite ``prj`` with the project that contains the key we're using
prj, pubkey = result
pubkeys.append(pubkey)

Check warning on line 319 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L318-L319

Added lines #L318 - L319 were not covered by tests

# remove the existing files, we'll create new files with new contents
for pubkey_path in pubkey_paths:
os.unlink(pubkey_path)

Check warning on line 323 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L322-L323

Added lines #L322 - L323 were not covered by tests

if pubkeys:
for num, pubkey in enumerate(pubkeys):
pubkey_path = f"{pubkey_path_base}-{num}"
with open(pubkey_path, "w") as f:
f.write(pubkey)
buildinfo.keys.append(pubkey_path)
if prj not in buildinfo.prjkeys:
buildinfo.prjkeys.append(prj)

Check warning on line 332 in osc/fetch.py

View check run for this annotation

Codecov / codecov/patch

osc/fetch.py#L325-L332

Added lines #L325 - L332 were not covered by tests


def verify_pacs_old(pac_list):
Expand Down

0 comments on commit 7f6c0b3

Please sign in to comment.