mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-25 22:36:13 +01:00
Migrate Fetcher.run() to obs_api.Keyinfo
This commit is contained in:
parent
b8ab16945e
commit
7f6c0b3f8a
75
osc/fetch.py
75
osc/fetch.py
@ -4,6 +4,7 @@
|
|||||||
# either version 2, or (at your option) any later version.
|
# either version 2, or (at your option) any later version.
|
||||||
|
|
||||||
|
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@ -288,49 +289,47 @@ class Fetcher:
|
|||||||
self.__fetch_cpio(buildinfo.apiurl)
|
self.__fetch_cpio(buildinfo.apiurl)
|
||||||
|
|
||||||
prjs = list(buildinfo.projects.keys())
|
prjs = list(buildinfo.projects.keys())
|
||||||
for i in prjs:
|
for prj in prjs:
|
||||||
dest = f"{self.cachedir}/{i}"
|
dest = os.path.join(self.cachedir, prj)
|
||||||
if not os.path.exists(dest):
|
pubkey_path_base = os.path.join(dest, "_pubkey")
|
||||||
os.makedirs(dest, mode=0o755)
|
pubkey_paths = glob.glob(f"{pubkey_path_base}*")
|
||||||
dest += '/_pubkey'
|
|
||||||
|
if self.offline:
|
||||||
|
# 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
|
||||||
|
|
||||||
|
from . import obs_api
|
||||||
|
|
||||||
|
os.makedirs(dest, mode=0o755, exist_ok=True)
|
||||||
|
pubkeys = []
|
||||||
|
|
||||||
url = makeurl(buildinfo.apiurl, ['source', i, '_pubkey'])
|
|
||||||
try_parent = False
|
|
||||||
try:
|
try:
|
||||||
if self.offline and not os.path.exists(dest):
|
keyinfo = obs_api.Keyinfo.from_api(buildinfo.apiurl, prj)
|
||||||
# may need to try parent
|
for pubkey in keyinfo.pubkey_list or []:
|
||||||
try_parent = True
|
pubkeys.append(pubkey.value)
|
||||||
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:
|
except HTTPError as e:
|
||||||
# Not found is okay, let's go to the next project
|
result = obs_api.Keyinfo.get_pubkey_deprecated(buildinfo.apiurl, prj, traverse=True)
|
||||||
if e.code != 404:
|
if result:
|
||||||
print("Invalid answer from server", e, file=sys.stderr)
|
# overwrite ``prj`` with the project that contains the key we're using
|
||||||
sys.exit(1)
|
prj, pubkey = result
|
||||||
try_parent = True
|
pubkeys.append(pubkey)
|
||||||
|
|
||||||
if try_parent:
|
# remove the existing files, we'll create new files with new contents
|
||||||
if self.http_debug:
|
for pubkey_path in pubkey_paths:
|
||||||
print(f"can't fetch key for {i}", file=sys.stderr)
|
os.unlink(pubkey_path)
|
||||||
print(f"url: {url}", file=sys.stderr)
|
|
||||||
|
|
||||||
if os.path.exists(dest):
|
if pubkeys:
|
||||||
os.unlink(dest)
|
for num, pubkey in enumerate(pubkeys):
|
||||||
|
pubkey_path = f"{pubkey_path_base}-{num}"
|
||||||
l = i.rsplit(':', 1)
|
with open(pubkey_path, "w") as f:
|
||||||
# try key from parent project
|
f.write(pubkey)
|
||||||
if len(l) > 1 and l[1] and not l[0] in buildinfo.projects:
|
buildinfo.keys.append(pubkey_path)
|
||||||
prjs.append(l[0])
|
if prj not in buildinfo.prjkeys:
|
||||||
|
buildinfo.prjkeys.append(prj)
|
||||||
|
|
||||||
|
|
||||||
def verify_pacs_old(pac_list):
|
def verify_pacs_old(pac_list):
|
||||||
|
Loading…
Reference in New Issue
Block a user