mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-13 17:16:23 +01:00
- don't read all rpm/deb tags/fields by default
This commit is contained in:
parent
e4fb64daba
commit
de84575ab0
@ -90,7 +90,7 @@ class Fetcher:
|
||||
print >>sys.stderr, '\n'.join(pac.urllist)
|
||||
sys.exit(1)
|
||||
|
||||
pkgq = packagequery.PackageQuery.query(pac.fullpartname)
|
||||
pkgq = packagequery.PackageQuery.query(pac.fullpartname, extra_rpmtags=(1044, 1051, 1052))
|
||||
arch = pkgq.arch()
|
||||
# SOURCERPM = 1044
|
||||
if pkgq.filename_suffix == 'rpm' and not pkgq.getTag(1044):
|
||||
|
@ -7,12 +7,16 @@ class DebError(packagequery.PackageError):
|
||||
pass
|
||||
|
||||
class DebQuery(packagequery.PackageQuery):
|
||||
|
||||
default_tags = ('package', 'version', 'release', 'epoch', 'architecture', 'description',
|
||||
'provides', 'depends', 'pre_depends')
|
||||
|
||||
def __init__(self, fh):
|
||||
self.__file = fh
|
||||
self.filename_suffix = 'deb'
|
||||
self.fields = {}
|
||||
|
||||
def read(self):
|
||||
def read(self, all_tags = False, *extra_tags):
|
||||
arfile = ar.Ar(fh = self.__file)
|
||||
arfile.read()
|
||||
debbin = arfile.get_file('debian-binary')
|
||||
@ -29,9 +33,9 @@ class DebQuery(packagequery.PackageQuery):
|
||||
control = tar.extractfile('./control')
|
||||
except KeyError:
|
||||
raise DebError('missing \'control\' file in control.tar.gz')
|
||||
self.__parse_control(control)
|
||||
self.__parse_control(control, all_tags, *extra_tags)
|
||||
|
||||
def __parse_control(self, control):
|
||||
def __parse_control(self, control, all_tags = False, *extra_tags):
|
||||
data = control.readline().strip()
|
||||
while data:
|
||||
field, val = re.split(':\s*', data.strip(), 1)
|
||||
@ -39,8 +43,10 @@ class DebQuery(packagequery.PackageQuery):
|
||||
while data and re.match('\s+', data):
|
||||
val += '\n' + data.strip()
|
||||
data = control.readline().rstrip()
|
||||
# a hyphen is not allowed in dict keys
|
||||
self.fields[field.replace('-', '_').lower()] = val
|
||||
field = field.replace('-', '_').lower()
|
||||
if field in self.default_tags + extra_tags or all_tags:
|
||||
# a hyphen is not allowed in dict keys
|
||||
self.fields[field] = val
|
||||
versrel = self.fields['version'].rsplit('-', 1)
|
||||
if len(versrel) == 2:
|
||||
self.fields['version'] = versrel[0]
|
||||
@ -97,10 +103,10 @@ class DebQuery(packagequery.PackageQuery):
|
||||
return self.fields.get(num, None)
|
||||
|
||||
@staticmethod
|
||||
def query(filename):
|
||||
def query(filename, all_tags = False, *extra_tags):
|
||||
f = open(filename, 'rb')
|
||||
debq = DebQuery(f)
|
||||
debq.read()
|
||||
debq.read(all_tags, *extra_tags)
|
||||
f.close()
|
||||
return debq
|
||||
|
||||
|
@ -6,7 +6,7 @@ class PackageError(Exception):
|
||||
|
||||
class PackageQuery:
|
||||
"""abstract base class for all package types"""
|
||||
def read(self):
|
||||
def read(self, all_tags = False, *extra_tags):
|
||||
raise NotImplementedError
|
||||
|
||||
def name(self):
|
||||
@ -40,20 +40,23 @@ class PackageQuery:
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
def query(filename):
|
||||
def query(filename, all_tags = False, extra_rpmtags = (), extra_debtags = ()):
|
||||
f = open(filename, 'rb')
|
||||
magic = f.read(7)
|
||||
f.seek(0)
|
||||
extra_tags = ()
|
||||
pkgq = None
|
||||
if magic[:4] == '\xed\xab\xee\xdb':
|
||||
import rpmquery
|
||||
pkgq = rpmquery.RpmQuery(f)
|
||||
extra_tags = extra_rpmtags
|
||||
elif magic == '!<arch>':
|
||||
import debquery
|
||||
pkgq = debquery.DebQuery(f)
|
||||
extra_tags = extra_debtags
|
||||
else:
|
||||
raise PackageError('unsupported package type. magic: \'%s\' (%s)' % (magic, filename))
|
||||
pkgq.read()
|
||||
pkgq.read(all_tags, *extra_tags)
|
||||
f.close()
|
||||
return pkgq
|
||||
|
||||
|
@ -54,12 +54,18 @@ class RpmQuery(packagequery.PackageQuery):
|
||||
LESS = 1 << 1
|
||||
GREATER = 1 << 2
|
||||
EQUAL = 1 << 3
|
||||
|
||||
default_tags = (1000, 1001, 1002, 1003, 1004, 1022, 1005, 1020,
|
||||
1047, 1112, 1113, # provides
|
||||
1049, 1048, 1050 # requires
|
||||
)
|
||||
|
||||
def __init__(self, fh):
|
||||
self.__file = fh
|
||||
self.filename_suffix = 'rpm'
|
||||
self.header = None
|
||||
|
||||
def read(self, *tags):
|
||||
def read(self, all_tags = False, *extra_tags):
|
||||
self.__read_lead()
|
||||
data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE)
|
||||
hdrmgc, reserved, il, dl = struct.unpack('!I3i', data)
|
||||
@ -82,7 +88,7 @@ class RpmQuery(packagequery.PackageQuery):
|
||||
data = data[RpmHeaderEntry.ENTRY_SIZE:]
|
||||
data = self.__file.read(self.header.length)
|
||||
for i in self.header:
|
||||
if i.tag in tags or len(tags) == 0:
|
||||
if i.tag in self.default_tags + extra_tags or all_tags:
|
||||
try: # this may fail for -debug* packages
|
||||
self.__read_data(i, data)
|
||||
except: pass
|
||||
|
Loading…
Reference in New Issue
Block a user