mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-26 22:56:15 +01:00
[python3] fetch.py python3 ready
* the result of a division is a float but we need int to continue. * use decode_it to decode hdr.filename
This commit is contained in:
parent
7bd9ca485d
commit
96ce14221b
28
osc/fetch.py
28
osc/fetch.py
@ -23,20 +23,16 @@ from . import oscerr
|
|||||||
import tempfile
|
import tempfile
|
||||||
import re
|
import re
|
||||||
|
|
||||||
try:
|
from osc.util.helper import decode_it
|
||||||
from .meter import TextMeter
|
from .meter import create_text_meter
|
||||||
except ImportError:
|
|
||||||
TextMeter = None
|
|
||||||
|
|
||||||
|
|
||||||
class Fetcher:
|
class Fetcher:
|
||||||
def __init__(self, cachedir='/tmp', api_host_options={}, urllist=[],
|
def __init__(self, cachedir='/tmp', api_host_options={}, urllist=[],
|
||||||
http_debug=False, cookiejar=None, offline=False, enable_cpio=True):
|
http_debug=False, cookiejar=None, offline=False, enable_cpio=True):
|
||||||
# set up progress bar callback
|
# set up progress bar callback
|
||||||
if sys.stdout.isatty() and TextMeter:
|
self.progress_obj = None
|
||||||
self.progress_obj = TextMeter()
|
if sys.stdout.isatty():
|
||||||
else:
|
self.progress_obj = create_text_meter(use_pb_fallback=False)
|
||||||
self.progress_obj = None
|
|
||||||
|
|
||||||
self.cachedir = cachedir
|
self.cachedir = cachedir
|
||||||
self.urllist = urllist
|
self.urllist = urllist
|
||||||
@ -82,16 +78,16 @@ class Fetcher:
|
|||||||
raise oscerr.APIError('CPIO archive is incomplete '
|
raise oscerr.APIError('CPIO archive is incomplete '
|
||||||
'(see .errors file)')
|
'(see .errors file)')
|
||||||
if package == '_repository':
|
if package == '_repository':
|
||||||
n = re.sub(r'\.pkg\.tar\..z$', '.arch', hdr.filename)
|
n = re.sub(b'\.pkg\.tar\..z$', b'.arch', hdr.filename)
|
||||||
if n.startswith('container:'):
|
if n.startswith(b'container:'):
|
||||||
n = re.sub(r'\.tar\..z$', '.tar', hdr.filename)
|
n = re.sub(b'\.tar\..z$', b'.tar', hdr.filename)
|
||||||
pac = pkgs[n.rsplit('.', 1)[0]]
|
pac = pkgs[decode_it(n.rsplit(b'.', 1)[0])]
|
||||||
pac.canonname = hdr.filename
|
pac.canonname = hdr.filename
|
||||||
else:
|
else:
|
||||||
pac = pkgs[n.rsplit('.', 1)[0]]
|
pac = pkgs[decode_it(n.rsplit(b'.', 1)[0])]
|
||||||
else:
|
else:
|
||||||
# this is a kiwi product
|
# this is a kiwi product
|
||||||
pac = pkgs[hdr.filename]
|
pac = pkgs[decode_it(hdr.filename)]
|
||||||
|
|
||||||
# Extract a single file from the cpio archive
|
# Extract a single file from the cpio archive
|
||||||
try:
|
try:
|
||||||
@ -118,7 +114,7 @@ class Fetcher:
|
|||||||
if len(keys) == 1:
|
if len(keys) == 1:
|
||||||
raise oscerr.APIError('unable to fetch cpio archive: '
|
raise oscerr.APIError('unable to fetch cpio archive: '
|
||||||
'server always returns code 414')
|
'server always returns code 414')
|
||||||
n = len(pkgs) / 2
|
n = int(len(pkgs) / 2)
|
||||||
new_pkgs = dict([(k, pkgs[k]) for k in keys[:n]])
|
new_pkgs = dict([(k, pkgs[k]) for k in keys[:n]])
|
||||||
self.__download_cpio_archive(apiurl, project, repo, arch,
|
self.__download_cpio_archive(apiurl, project, repo, arch,
|
||||||
package, **new_pkgs)
|
package, **new_pkgs)
|
||||||
|
Loading…
Reference in New Issue
Block a user