1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 22:56:15 +01:00
github.com_openSUSE_osc/osc/util/packagequery.py

72 lines
1.7 KiB
Python
Raw Normal View History

class PackageError(Exception):
"""base class for all package related errors"""
def __init__(self, msg):
Exception.__init__(self)
self.msg = msg
2009-09-20 19:19:33 +02:00
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
def vercmp(self, pkgq):
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())