osclib/repomirror.py: Small cleanups
This commit is contained in:
parent
0888a8f1a0
commit
b658cefdae
@ -9,8 +9,7 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from lxml import etree as ET
|
from lxml import etree as ET
|
||||||
from osc.core import http_GET
|
from osc.core import makeurl, http_GET
|
||||||
from osc.core import makeurl
|
|
||||||
from osc.util.cpio import CpioHdr
|
from osc.util.cpio import CpioHdr
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
|
|
||||||
@ -18,7 +17,10 @@ logger = logging.getLogger('RepoMirror')
|
|||||||
|
|
||||||
|
|
||||||
class RepoMirror:
|
class RepoMirror:
|
||||||
def __init__(self, apiurl, nameignore: str = '-debug(info|source|info-32bit).rpm$'):
|
cpio_struct = struct.Struct('6s8s8s8s8s8s8s8s8s8s8s8s8s8s')
|
||||||
|
cpio_name_re = re.compile('^([^/]+)-([0-9a-f]{32})$')
|
||||||
|
|
||||||
|
def __init__(self, apiurl: str, nameignore: str = '-debug(info|source|info-32bit).rpm$'):
|
||||||
"""
|
"""
|
||||||
Class to mirror RPM headers of all binaries in a repo on OBS (full tree).
|
Class to mirror RPM headers of all binaries in a repo on OBS (full tree).
|
||||||
Debug packages are ignored by default, see the nameignore parameter.
|
Debug packages are ignored by default, see the nameignore parameter.
|
||||||
@ -27,15 +29,9 @@ class RepoMirror:
|
|||||||
self.nameignorere = re.compile(nameignore)
|
self.nameignorere = re.compile(nameignore)
|
||||||
|
|
||||||
def extract_cpio_stream(self, destdir: str, stream):
|
def extract_cpio_stream(self, destdir: str, stream):
|
||||||
hdr_fmt = '6s8s8s8s8s8s8s8s8s8s8s8s8s8s'
|
|
||||||
hdr_len = 110
|
|
||||||
|
|
||||||
name_re = re.compile('^([^/]+)-([0-9a-f]{32})$')
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
hdrtuples = self.cpio_struct.unpack(stream.read(self.cpio_struct.size))
|
||||||
# Read and parse the CPIO header
|
# Read and parse the CPIO header
|
||||||
hdrdata = stream.read(hdr_len)
|
|
||||||
hdrtuples = struct.unpack(hdr_fmt, hdrdata)
|
|
||||||
if hdrtuples[0] != b'070701':
|
if hdrtuples[0] != b'070701':
|
||||||
raise NotImplementedError(f'CPIO format {hdrtuples[0]} not implemented')
|
raise NotImplementedError(f'CPIO format {hdrtuples[0]} not implemented')
|
||||||
|
|
||||||
@ -48,7 +44,7 @@ class RepoMirror:
|
|||||||
stream.read(1) # Skip terminator
|
stream.read(1) # Skip terminator
|
||||||
align()
|
align()
|
||||||
|
|
||||||
binarymatch = name_re.match(hdr.filename)
|
binarymatch = self.cpio_name_re.match(hdr.filename)
|
||||||
if hdr.filename == '.errors':
|
if hdr.filename == '.errors':
|
||||||
content = stream.read(hdr.filesize)
|
content = stream.read(hdr.filesize)
|
||||||
raise RuntimeError('Download has errors: ' + content.decode('ascii'))
|
raise RuntimeError('Download has errors: ' + content.decode('ascii'))
|
||||||
@ -122,9 +118,9 @@ class RepoMirror:
|
|||||||
try:
|
try:
|
||||||
fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
except IOError:
|
except IOError:
|
||||||
logger.info(destdir + 'is locked, waiting... ', end='')
|
logger.info(destdir + 'is locked, waiting... ')
|
||||||
fcntl.flock(lockfile, fcntl.LOCK_EX)
|
fcntl.flock(lockfile, fcntl.LOCK_EX)
|
||||||
logger.info('acquired!')
|
logger.info('Lock acquired!')
|
||||||
|
|
||||||
return self._mirror(destdir, prj, repo, arch)
|
return self._mirror(destdir, prj, repo, arch)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user