From 0c58c7a289b71e1c9190fa7e7ab78405c03c292a Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Thu, 29 Aug 2019 18:30:39 +0200 Subject: [PATCH] Fix encoding in varios places, change __cmp__ to __eq__ and __lt__ + @total_ordering --- src/mio/daemon_cage.py | 2 +- src/mio/installer.py | 1 + src/mio/node.py | 40 ++++++++++++++++++++-------------------- src/mio/rpmDB.py | 28 ++++++++++++++++------------ 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/mio/daemon_cage.py b/src/mio/daemon_cage.py index 50cded9..bf5df16 100755 --- a/src/mio/daemon_cage.py +++ b/src/mio/daemon_cage.py @@ -26,7 +26,7 @@ def system(command): if len(c) == 0: # Normal exit, subprocess has closed stdout break - sys.stdout.write(c) + os.write(sys.stdout.fileno(), c) sys.stdout.flush() elif p.poll() != None: # Child has exited, but stdout is still open diff --git a/src/mio/installer.py b/src/mio/installer.py index d2f6c47..2af36c7 100755 --- a/src/mio/installer.py +++ b/src/mio/installer.py @@ -79,6 +79,7 @@ class Installer: elif node._tag == 'rpm': rpm = rpm_node(node.name[0], node, group) + if rpm in exclude: mio.log.log(CHATTY, "excluding rpm '%s'" % node.name[0]) diff --git a/src/mio/node.py b/src/mio/node.py index eaacc59..30f8eee 100755 --- a/src/mio/node.py +++ b/src/mio/node.py @@ -8,6 +8,7 @@ import os import hashlib import shutil import tempfile +from functools import total_ordering from mio.exception import * from mio.log import log, declaration, SILENT, NORMAL, VERBOSE, DEBUG @@ -20,7 +21,8 @@ def parse_boolean(value): if value.upper() == 'NO' or value.upper() == 'FALSE': return False raise Exception("yes, no, true or false expected (not '%s')" % value) - + +@total_ordering class target_node: def __init__(self, kind, name, decl, group): assert name != None @@ -31,21 +33,19 @@ class target_node: self.is_installed = False self.is_tested = False self.is_trigged = None + + def __repr__(self): + return "%s(%s)" % (self.kind, self.name) - def __cmp__(self, other): - result = 0 - if self.kind == other.kind: - if self.name < other.name: - result = -1 - elif self.name == other.name: - result = 0 - else: - result = -1 - elif self.kind < other.kind: - result = -1 - else: - result = 1 - return result + def __eq__(self, other): + return self.kind == other.kind and self.name == other.name + + def __ne__(self, other): + return not self.__eq__(other) + + def __lt__(self, other): + return (self.kind < other.kind or + self.kind == other.kind and self.name < other.name) def __hash__(self): return self.name.__hash__() @@ -86,7 +86,7 @@ class group_node(target_node): self.post = [] def assert_identical(self, other): - if self.__cmp__(other) != 0: + if self != other: raise Exception("%s %s" % (self.name, other.name)) if self.target != other.target: raise TargetException(self, other) @@ -179,7 +179,7 @@ class dir_node(target_node): self.delete = parse_boolean(self.decl.delete[0]) def assert_identical(self, other): - if self.__cmp__(other) != 0: + if self != other: raise Exception("%s %s" % (self.name, other.name)) if self.mode != other.mode: raise ModeException(self, other) @@ -267,7 +267,7 @@ class file_node(target_node): self.touch = parse_boolean(self.decl.touch_when_copied[0]) def assert_identical(self, other): - if self.__cmp__(other) != 0: + if self != other: raise Exception("%s %s" % (self.name, other.name)) if self.mode != other.mode: raise ModeException(self, other) @@ -283,7 +283,7 @@ class file_node(target_node): raise DeleteException(self, other) def digest(self, name): - f = open(name) + f = open(name, 'rb') digest = hashlib.sha1(f.read()).hexdigest() f.close() return digest @@ -431,7 +431,7 @@ class symlink_node(target_node): self.delete = parse_boolean(self.decl.delete[0]) def assert_identical(self, other): - if self.__cmp__(other) != 0: + if self != other: raise Exception("%s %s" % (self.name, other.name)) if not self.delete and (self.decl.value[0] == None or self.decl.value[0] != other.decl.value[0]): diff --git a/src/mio/rpmDB.py b/src/mio/rpmDB.py index 07ef123..95bc885 100755 --- a/src/mio/rpmDB.py +++ b/src/mio/rpmDB.py @@ -38,28 +38,32 @@ class VersionDB: read_ts = initReadOnlyTransaction() for e in read_ts.dbMatch(): (name, arch, version, release) = ( - e[rpm.RPMTAG_NAME], e[rpm.RPMTAG_ARCH], - e[rpm.RPMTAG_VERSION], e[rpm.RPMTAG_RELEASE]) + e[rpm.RPMTAG_NAME].decode('utf-8'), + e[rpm.RPMTAG_ARCH].decode('utf-8'), + e[rpm.RPMTAG_VERSION].decode('utf-8'), + e[rpm.RPMTAG_RELEASE].decode('utf-8')) if not name in self.rpm: self.rpm[name] = [] pass self.rpm[name].append(RPM(name, arch, version, release)) del read_ts except: + raise pass pass def __getitem__(self, name): - try: - if name in self.rpm: - return self.rpm[name] + if name in self.rpm: + return self.rpm[name] + if name.rfind('.') >= 0: name, arch = name.rsplit('.', 1) - for r in self.rpm[name]: - if arch == r.arch: - return [r] + if name in self.rpm: + for r in self.rpm[name]: + if arch == r.arch: + return [r] + pass pass - return None - except: - return None - pass + pass + return None + pass -- GitLab