mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-14 09:36:21 +01:00
Convert repodata.RepoDataQueryResult to a bytes API
The repodata.RepoDataQueryResult is supposed to be a bytes API and that's what our users (see build module) expect. Note that the repodata.RepoDataQueryResult.path method still returns a str. That's what the rpmquery.RpmQuery, debquery.DebQuery, and archquery.ArchQuery classes also do (if the "path" was initially passed as a str). Fixes: #760 ("osc build fails when called with --prefer-pkgs where the passed directory is a repodata repository or a subdirectory of one")
This commit is contained in:
parent
cd51f47a77
commit
55aef1a014
@ -71,6 +71,25 @@ def queries(directory):
|
|||||||
|
|
||||||
return packageQueries
|
return packageQueries
|
||||||
|
|
||||||
|
|
||||||
|
def _to_bytes_or_None(method):
|
||||||
|
def _method(self, *args, **kwargs):
|
||||||
|
res = method(self, *args, **kwargs)
|
||||||
|
if res is None:
|
||||||
|
return None
|
||||||
|
return res.encode()
|
||||||
|
|
||||||
|
return _method
|
||||||
|
|
||||||
|
|
||||||
|
def _to_bytes_list(method):
|
||||||
|
def _method(self, *args, **kwargs):
|
||||||
|
res = method(self, *args, **kwargs)
|
||||||
|
return [data.encode() for data in res]
|
||||||
|
|
||||||
|
return _method
|
||||||
|
|
||||||
|
|
||||||
class RepoDataQueryResult(osc.util.packagequery.PackageQueryResult):
|
class RepoDataQueryResult(osc.util.packagequery.PackageQueryResult):
|
||||||
"""PackageQueryResult that reads in data from the repodata directory files."""
|
"""PackageQueryResult that reads in data from the repodata directory files."""
|
||||||
|
|
||||||
@ -119,18 +138,22 @@ class RepoDataQueryResult(osc.util.packagequery.PackageQueryResult):
|
|||||||
def __versionElement(self):
|
def __versionElement(self):
|
||||||
return self.__element.find(namespace("common") + "version")
|
return self.__element.find(namespace("common") + "version")
|
||||||
|
|
||||||
|
@_to_bytes_or_None
|
||||||
def arch(self):
|
def arch(self):
|
||||||
return self.__element.find(namespace("common") + "arch").text
|
return self.__element.find(namespace("common") + "arch").text
|
||||||
|
|
||||||
|
@_to_bytes_or_None
|
||||||
def description(self):
|
def description(self):
|
||||||
return self.__element.find(namespace("common") + "description").text
|
return self.__element.find(namespace("common") + "description").text
|
||||||
|
|
||||||
def distribution(self):
|
def distribution(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@_to_bytes_or_None
|
||||||
def epoch(self):
|
def epoch(self):
|
||||||
return self.__versionElement().get("epoch")
|
return self.__versionElement().get("epoch")
|
||||||
|
|
||||||
|
@_to_bytes_or_None
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.__element.find(namespace("common") + "name").text
|
return self.__element.find(namespace("common") + "name").text
|
||||||
|
|
||||||
@ -141,30 +164,39 @@ class RepoDataQueryResult(osc.util.packagequery.PackageQueryResult):
|
|||||||
|
|
||||||
return absolutePath
|
return absolutePath
|
||||||
|
|
||||||
|
@_to_bytes_list
|
||||||
def provides(self):
|
def provides(self):
|
||||||
return self.__parseEntryCollection("provides")
|
return self.__parseEntryCollection("provides")
|
||||||
|
|
||||||
|
@_to_bytes_or_None
|
||||||
def release(self):
|
def release(self):
|
||||||
return self.__versionElement().get("rel")
|
return self.__versionElement().get("rel")
|
||||||
|
|
||||||
|
@_to_bytes_list
|
||||||
def requires(self):
|
def requires(self):
|
||||||
return self.__parseEntryCollection("requires")
|
return self.__parseEntryCollection("requires")
|
||||||
|
|
||||||
|
@_to_bytes_list
|
||||||
def conflicts(self):
|
def conflicts(self):
|
||||||
return self.__parseEntryCollection('conflicts')
|
return self.__parseEntryCollection('conflicts')
|
||||||
|
|
||||||
|
@_to_bytes_list
|
||||||
def obsoletes(self):
|
def obsoletes(self):
|
||||||
return self.__parseEntryCollection('obsoletes')
|
return self.__parseEntryCollection('obsoletes')
|
||||||
|
|
||||||
|
@_to_bytes_list
|
||||||
def recommends(self):
|
def recommends(self):
|
||||||
return self.__parseEntryCollection('recommends')
|
return self.__parseEntryCollection('recommends')
|
||||||
|
|
||||||
|
@_to_bytes_list
|
||||||
def suggests(self):
|
def suggests(self):
|
||||||
return self.__parseEntryCollection('suggests')
|
return self.__parseEntryCollection('suggests')
|
||||||
|
|
||||||
|
@_to_bytes_list
|
||||||
def supplements(self):
|
def supplements(self):
|
||||||
return self.__parseEntryCollection('supplements')
|
return self.__parseEntryCollection('supplements')
|
||||||
|
|
||||||
|
@_to_bytes_list
|
||||||
def enhances(self):
|
def enhances(self):
|
||||||
return self.__parseEntryCollection('enhances')
|
return self.__parseEntryCollection('enhances')
|
||||||
|
|
||||||
@ -172,23 +204,27 @@ class RepoDataQueryResult(osc.util.packagequery.PackageQueryResult):
|
|||||||
if self.release() is None:
|
if self.release() is None:
|
||||||
release = None
|
release = None
|
||||||
else:
|
else:
|
||||||
release = self.release().encode()
|
release = self.release()
|
||||||
return osc.util.rpmquery.RpmQuery.filename(self.name().encode(), None,
|
return osc.util.rpmquery.RpmQuery.filename(self.name(), None,
|
||||||
self.version().encode(), release, self.arch().encode())
|
self.version(), release, self.arch())
|
||||||
|
|
||||||
def gettag(self, tag):
|
def gettag(self, tag):
|
||||||
# implement me, if needed
|
# implement me, if needed
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def vercmp(self, other):
|
def vercmp(self, other):
|
||||||
|
# if either self.epoch() or other.epoch() is None, the vercmp will do
|
||||||
|
# the correct thing because one is transformed into b'None' and the
|
||||||
|
# other one into b"b'<epoch>'" (and 'b' is greater than 'N')
|
||||||
res = osc.util.rpmquery.RpmQuery.rpmvercmp(str(self.epoch()).encode(), str(other.epoch()).encode())
|
res = osc.util.rpmquery.RpmQuery.rpmvercmp(str(self.epoch()).encode(), str(other.epoch()).encode())
|
||||||
if res != 0:
|
if res != 0:
|
||||||
return res
|
return res
|
||||||
res = osc.util.rpmquery.RpmQuery.rpmvercmp(self.version().encode(), other.version().encode())
|
res = osc.util.rpmquery.RpmQuery.rpmvercmp(self.version(), other.version())
|
||||||
if res != 0:
|
if res != 0:
|
||||||
return res
|
return res
|
||||||
res = osc.util.rpmquery.RpmQuery.rpmvercmp(self.release().encode(), other.release().encode())
|
res = osc.util.rpmquery.RpmQuery.rpmvercmp(self.release(), other.release())
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@_to_bytes_or_None
|
||||||
def version(self):
|
def version(self):
|
||||||
return self.__versionElement().get("ver")
|
return self.__versionElement().get("ver")
|
||||||
|
Loading…
Reference in New Issue
Block a user