From ea1fa3b9c473a0f20fb7fb5083fcfd9b5ab51db6 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 27 Aug 2010 16:41:20 -0700 Subject: Define a cmp work-alike function for use in the egencache --update-use-local-desc code, since it's ugly to have so many repetitions of this construct. --- bin/egencache | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/egencache b/bin/egencache index eaed7b655..b8c2c82a2 100755 --- a/bin/egencache +++ b/bin/egencache @@ -337,6 +337,13 @@ class GenUseLocalDesc(object): '''.lstrip()) + # The cmp function no longer exists in python3, so we'll + # implement our own here under a slightly different name + # since we don't want any confusion given that we never + # want to rely on the builtin cmp function. + def cmp_func(a, b): + return (a > b) - (a < b) + for cp in self._portdb.cp_all(): metadata_path = os.path.join(repo_path, cp, 'metadata.xml') try: @@ -361,18 +368,17 @@ class GenUseLocalDesc(object): def atomcmp(atoma, atomb): # None is better than an atom, that's why we reverse the args if atoma is None or atomb is None: - return -1 * ((atoma > atomb) - (atoma < atomb)) + return cmp_func(atomb, atoma) # Same for plain PNs (.operator is None then) elif atoma.operator is None or atomb.operator is None: - return -1 * ((atoma.operator > atomb.operator) - \ - (atoma.operator < atomb.operator)) + return cmp_func(atomb.operator, atoma.operator) # Version matching elif atoma.cpv != atomb.cpv: return pkgcmp(pkgsplit(atoma.cpv), pkgsplit(atomb.cpv)) # Versions match, let's fallback to operator matching else: - return ((ops.get(atoma.operator, -1) > ops.get(atomb.operator, -1)) - \ - (ops.get(atoma.operator, -1) < ops.get(atomb.operator, -1))) + return cmp_func(ops.get(atoma.operator, -1), + ops.get(atomb.operator, -1)) def _Atom(key): if key is not None: -- cgit v1.2.3-1-g7c22