From 1f51445859652f696941968cb8afdb913d52aa43 Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Thu, 21 Oct 2010 21:46:08 +0200 Subject: [PATCH] - add "fname" attribute to util.PackageError class --- osc/util/debquery.py | 8 ++++---- osc/util/packagequery.py | 3 ++- osc/util/rpmquery.py | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/osc/util/debquery.py b/osc/util/debquery.py index 40a0f7e8..f2f08e42 100644 --- a/osc/util/debquery.py +++ b/osc/util/debquery.py @@ -23,18 +23,18 @@ class DebQuery(packagequery.PackageQuery): arfile.read() debbin = arfile.get_file('debian-binary') if debbin is None: - raise DebError('no debian binary') + raise DebError(self.__path, 'no debian binary') if debbin.read() != '2.0\n': - raise DebError('invalid debian binary format') + raise DebError(self.__path, 'invalid debian binary format') control = arfile.get_file('control.tar.gz') if control is None: - raise DebError('missing control.tar.gz') + raise DebError(self.__path, 'missing control.tar.gz') # XXX: python24 relies on a name tar = tarfile.open(name = 'control.tar.gz', fileobj = control) try: control = tar.extractfile('./control') except KeyError: - raise DebError('missing \'control\' file in control.tar.gz') + raise DebError(self.__path, 'missing \'control\' file in control.tar.gz') self.__parse_control(control, all_tags, *extra_tags) def __parse_control(self, control, all_tags = False, *extra_tags): diff --git a/osc/util/packagequery.py b/osc/util/packagequery.py index 410a57dd..70bb8ebb 100644 --- a/osc/util/packagequery.py +++ b/osc/util/packagequery.py @@ -1,7 +1,8 @@ class PackageError(Exception): """base class for all package related errors""" - def __init__(self, msg): + def __init__(self, fname, msg): Exception.__init__(self) + self.fname = fname self.msg = msg class PackageQueries(dict): diff --git a/osc/util/rpmquery.py b/osc/util/rpmquery.py index de29bf0e..d8ac27eb 100644 --- a/osc/util/rpmquery.py +++ b/osc/util/rpmquery.py @@ -71,7 +71,7 @@ class RpmQuery(packagequery.PackageQuery): data = self.__file.read(RpmHeaderEntry.ENTRY_SIZE) hdrmgc, reserved, il, dl = struct.unpack('!I3i', data) if self.HEADER_MAGIC != hdrmgc: - raise RpmHeaderError('invalid headermagic \'%s\'' % hdrmgc) + raise RpmHeaderError(self.__path, 'invalid headermagic \'%s\'' % hdrmgc) # skip signature header for now size = il * RpmHeaderEntry.ENTRY_SIZE + dl # data is 8 byte aligned @@ -81,7 +81,7 @@ class RpmQuery(packagequery.PackageQuery): hdrmgc, reserved, il, dl = struct.unpack('!I3i', data) self.header = RpmHeader(pad, dl) if self.HEADER_MAGIC != hdrmgc: - raise RpmHeaderError('invalid headermagic \'%s\'' % hdrmgc) + raise RpmHeaderError(self.__path, 'invalid headermagic \'%s\'' % hdrmgc) data = self.__file.read(il * RpmHeaderEntry.ENTRY_SIZE) while len(data) > 0: ei = struct.unpack('!4i', data[:RpmHeaderEntry.ENTRY_SIZE]) @@ -98,10 +98,10 @@ class RpmQuery(packagequery.PackageQuery): data = self.__file.read(self.LEAD_SIZE) leadmgc, = struct.unpack('!I', data[:4]) if leadmgc != self.LEAD_MAGIC: - raise RpmError('invalid lead magic \'%s\'' % leadmgc) + raise RpmError(self.__path, 'invalid lead magic \'%s\'' % leadmgc) sigtype, = struct.unpack('!h', data[78:80]) if sigtype != self.HEADERSIG_TYPE: - raise RpmError('invalid header signature \'%s\'' % sigtype) + raise RpmError(self.__path, 'invalid header signature \'%s\'' % sigtype) def __read_data(self, entry, data): off = entry.offset @@ -144,14 +144,14 @@ class RpmQuery(packagequery.PackageQuery): cnt += 1 entry.data = entry.data[0] else: - raise RpmHeaderError('unsupported tag type \'%d\' (tag: \'%s\'' % (entry.type, entry.tag)) + raise RpmHeaderError(self.__path, 'unsupported tag type \'%d\' (tag: \'%s\'' % (entry.type, entry.tag)) def __reqprov(self, tag, flags, version): pnames = self.header.gettag(tag).data pflags = self.header.gettag(flags).data pvers = self.header.gettag(version).data if not (pnames and pflags and pvers): - raise RpmError('cannot get provides/requires, tags are missing') + raise RpmError(self.__path, 'cannot get provides/requires, tags are missing') res = [] for name, flags, ver in zip(pnames, pflags, pvers): # RPMSENSE_SENSEMASK = 15 (see rpmlib.h) but ignore RPMSENSE_SERIAL (= 1 << 0) therefore use 14