mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-03 21:36:15 +01:00
4bb893a114
* util/packagequery.py: it's used to query a RPM or DEB package. It also contains a base class for all package types (PackageQuery()) * util/debquery.py: query a DEB package (name, version, release, provides, requires etc.) - adapted util/rpmquery.py to use PackageQuery() as a base class - minor changes in util/ar.py
69 lines
1.6 KiB
Python
69 lines
1.6 KiB
Python
class PackageError(Exception):
|
|
"""base class for all package related errors"""
|
|
def __init__(self, msg):
|
|
Exception.__init__(self)
|
|
self.msg = msg
|
|
|
|
class PackageQuery():
|
|
"""abstract base class for all package types"""
|
|
def read(self):
|
|
raise NotImplementedError
|
|
|
|
def name(self):
|
|
raise NotImplementedError
|
|
|
|
def version(self):
|
|
raise NotImplementedError
|
|
|
|
def release(self):
|
|
raise NotImplementedError
|
|
|
|
def arch(self):
|
|
raise NotImplementedError
|
|
|
|
def description(self):
|
|
raise NotImplementedError
|
|
|
|
def provides(self):
|
|
raise NotImplementedError
|
|
|
|
def requires(self):
|
|
raise NotImplementedError
|
|
|
|
def getTag(self):
|
|
raise NotImplementedError
|
|
|
|
@staticmethod
|
|
def query(filename):
|
|
f = open(filename, 'rb')
|
|
magic = f.read(7)
|
|
f.seek(0)
|
|
pkgq = None
|
|
if magic[:4] == '\xed\xab\xee\xdb':
|
|
import rpmquery
|
|
pkgq = rpmquery.RpmQuery(f)
|
|
elif magic == '!<arch>':
|
|
import debquery
|
|
pkgq = debquery.DebQuery(f)
|
|
else:
|
|
raise PackageError('unsupported package type. magic: \'%s\' (%s)' % (magic, filename))
|
|
pkgq.read()
|
|
f.close()
|
|
return pkgq
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
try:
|
|
pkgq = PackageQuery.query(sys.argv[1])
|
|
except PackageError, e:
|
|
print e.msg
|
|
sys.exit(2)
|
|
print pkgq.name()
|
|
print pkgq.version()
|
|
print pkgq.release()
|
|
print pkgq.description()
|
|
print '##########'
|
|
print '\n'.join(pkgq.provides())
|
|
print '##########'
|
|
print '\n'.join(pkgq.requires())
|