From 8aa7c0ff52307df5b5eb59a8143c0c24b28512c0 Mon Sep 17 00:00:00 2001 From: "biao716.wang" Date: Tue, 9 May 2023 14:49:40 +0900 Subject: [PATCH] fix yum run error Change-Id: Ic5269cdeaab3371d0b16920267269820503c02b6 Signed-off-by: biao716.wang --- cli.py | 5 ++--- output.py | 14 +++++++------- utils.py | 3 +-- yum-updatesd.py | 13 ++++++++++++- yum/__init__.py | 15 +++++++++++++-- yum/config.py | 36 +++++++++++++++++++++++++++++------- yum/parser.py | 8 ++++---- yum/plugins.py | 13 ++++++++++++- 8 files changed, 80 insertions(+), 27 deletions(-) diff --git a/cli.py b/cli.py index 7cad6af..5a7903d 100644 --- a/cli.py +++ b/cli.py @@ -227,7 +227,6 @@ class YumBaseCli(yum.YumBase, output.YumOutput): pc.disabled_plugins = self.optparser._splitArg(opts.disableplugins) pc.enabled_plugins = self.optparser._splitArg(opts.enableplugins) pc.releasever = opts.releasever - self.conf # now set all the non-first-start opts from main from our setopts if self.main_setopts: @@ -1408,11 +1407,11 @@ class YumBaseCli(yum.YumBase, output.YumOutput): def usage(self): ''' Print out command line usage ''' - sys.stdout.write(self.optparser.format_help()) + print(self.optparser.format_help(), file=sys.stderr) def shellUsage(self): ''' Print out the shell usage ''' - sys.stdout.write(self.optparser.get_usage()) + print(self.optparser.get_usage(), file=sys.stderr) def _installable(self, pkg, ematch=False): diff --git a/output.py b/output.py index 5852abd..8fba9eb 100755 --- a/output.py +++ b/output.py @@ -230,19 +230,19 @@ class YumTerm: set_fg = self._tigetstr('setf') if set_fg: for (color, val) in list(self.__colors.items()): - self.FG_COLOR[color] = curses.tparm(set_fg, val) or '' + self.FG_COLOR[color] = curses.tparm(set_fg.encode(), val) or b'' set_fg_ansi = self._tigetstr('setaf') if set_fg_ansi: for (color, val) in list(self.__ansi_colors.items()): - self.FG_COLOR[color] = curses.tparm(set_fg_ansi, val) or '' + self.FG_COLOR[color] = curses.tparm(set_fg_ansi.encode(), val) or b'' set_bg = self._tigetstr('setb') if set_bg: for (color, val) in list(self.__colors.items()): - self.BG_COLOR[color] = curses.tparm(set_bg, val) or '' + self.BG_COLOR[color] = curses.tparm(set_bg.encode(), val) or b'' set_bg_ansi = self._tigetstr('setab') if set_bg_ansi: for (color, val) in list(self.__ansi_colors.items()): - self.BG_COLOR[color] = curses.tparm(set_bg_ansi, val) or '' + self.BG_COLOR[color] = curses.tparm(set_bg_ansi.encode(), val) or b'' def __init__(self, term_stream=None, color='auto'): self.reinit(term_stream, color) @@ -251,8 +251,8 @@ class YumTerm: # String capabilities can include "delays" of the form "$<2>". # For any modern terminal, we should be able to just ignore # these, so strip them out. - cap = self._ctigetstr(cap_name) or '' - return re.sub(r'\$<\d+>[/*]?', '', cap) + cap = self._ctigetstr(cap_name) or b'' + return re.sub(r'\$<\d+>[/*]?', '', cap.decode()) def sub(self, haystack, beg, end, needles, escape=None, ignore_case=False): if not self.__enabled: @@ -261,7 +261,7 @@ class YumTerm: if not escape: escape = re.escape - render = lambda match: beg + match.group() + end + def render(match): return beg + match.group() + end for needle in needles: pat = escape(needle) if ignore_case: diff --git a/utils.py b/utils.py index 3e60106..879e27e 100644 --- a/utils.py +++ b/utils.py @@ -15,7 +15,6 @@ import sys import time -import exceptions import yum from cli import * @@ -32,7 +31,7 @@ def suppress_keyboard_interrupt_message(): old_excepthook = sys.excepthook def new_hook(type, value, traceback): - if type != exceptions.KeyboardInterrupt: + if type != KeyboardInterrupt: old_excepthook(type, value, traceback) else: pass diff --git a/yum-updatesd.py b/yum-updatesd.py index 1c5b2d1..62addb5 100644 --- a/yum-updatesd.py +++ b/yum-updatesd.py @@ -620,11 +620,22 @@ def main(options = None): if os.path.exists(config_file): confpp_obj = ConfigPreProcessor(config_file) + processedLines = [] + while True: + line = confpp_obj.readline() + if not line: + break + processedLines.append(line.decode()) + congf = open('tmp_confilgfile', 'a+') + congf.writelines(processedLines) try: - confparser.readfp(confpp_obj) + confparser.read_file(congf) except ParsingError as e: print("Error reading config file: %s" % e, file=sys.stderr) sys.exit(1) + finally: + congf.close() + os.remove('tmp_confilgfile') syslog.openlog("yum-updatesd", 0, syslog.LOG_DAEMON) diff --git a/yum/__init__.py b/yum/__init__.py index 97e3ca4..82ef95e 100644 --- a/yum/__init__.py +++ b/yum/__init__.py @@ -388,11 +388,22 @@ class YumBase(depsolve.Depsolve): confpp_obj = ConfigPreProcessor(repofn, vars=self.conf.yumvar) parser = ConfigParser() + processedLines = [] + while True: + line = confpp_obj.readline() + if not line: + break + processedLines.append(line.decode()) + congf = open('tmp_confilgfile', 'a+') + congf.writelines(processedLines) try: - parser.readfp(confpp_obj) + parser.read_file(congf) except ParsingError as e: msg = str(e) raise Errors.ConfigError(msg) + finally: + congf.close() + os.remove('tmp_confilgfile') # Check sections in the .repo file that was just slurped up for section in parser.sections(): @@ -1843,7 +1854,7 @@ class YumBase(depsolve.Depsolve): raise Errors.LockError(msg.errno, errmsg, int(contents)) return 0 else: - os.write(fd, contents) + os.write(fd, contents.encode()) os.close(fd) return 1 diff --git a/yum/config.py b/yum/config.py index 850e7dc..857bccf 100644 --- a/yum/config.py +++ b/yum/config.py @@ -487,14 +487,14 @@ class BaseConfig(object): def __init__(self): self._section = None - for name in list(self.keys()): + for name in self.iterkeys(): option = self.optionobj(name) option.setup(self, name) def __str__(self): out = [] out.append('[%s]' % self._section) - for name, value in list(self.items()): + for name, value in self.iteritems(): out.append('%s: %r' % (name, value)) return '\n'.join(out) @@ -513,7 +513,7 @@ class BaseConfig(object): opts = set(parser.options(section)) else: opts = set() - for name in list(self.keys()): + for name in self.iterkeys(): option = self.optionobj(name) value = None if name in opts: @@ -557,7 +557,7 @@ class BaseConfig(object): The value returned is the parsed, validated option value. ''' # Use dir() so that we see inherited options too - for name in list(self.keys()): + for name in self.iterkeys(): yield (name, getattr(self, name)) def write(self, fileobj, section=None, always=()): @@ -578,7 +578,7 @@ class BaseConfig(object): # Updated the ConfigParser with the changed values cfgOptions = self.cfg.options(section) - for name,value in list(self.items()): + for name,value in self.iteritems(): option = self.optionobj(name) if always is None or name in always or option.default != value or name in cfgOptions : self.cfg.set(section,name, option.tostring(value)) @@ -864,10 +864,21 @@ def readStartupConfig(configfile, root): startupconf.config_file_path = configfile parser = ConfigParser() confpp_obj = ConfigPreProcessor(configfile) + processedLines = [] + while True: + line = confpp_obj.readline() + if not line: + break + processedLines.append(line.decode()) + congf = open('tmp_confilgfile', 'a+') + congf.writelines(processedLines) try: - parser.readfp(confpp_obj) + parser.read_file(congf) except ParsingError as e: raise Errors.ConfigError("Parsing file failed: %s" % e) + finally: + congf.close() + os.remove('tmp_confilgfile') startupconf.populate(parser, 'main') # Check that plugin paths are all absolute @@ -958,10 +969,21 @@ def readMainConfig(startupconf): def readVersionGroupsConfig(configfile="/etc/yum/version-groups.conf"): parser = ConfigParser() confpp_obj = ConfigPreProcessor(configfile) + processedLines = [] + while True: + line = confpp_obj.readline() + if not line: + break + processedLines.append(line.decode()) + congf = open('tmp_confilgfile', 'a+') + congf.writelines(processedLines) try: - parser.readfp(confpp_obj) + parser.read_file(congf) except ParsingError as e: raise Errors.ConfigError("Parsing file failed: %s" % e) + finally: + congf.close() + os.remove('tmp_confilgfile') ret = {} for section in parser.sections(): ret[section] = VersionGroupConf() diff --git a/yum/parser.py b/yum/parser.py index f1debb6..0b8a5e9 100644 --- a/yum/parser.py +++ b/yum/parser.py @@ -123,7 +123,7 @@ class ConfigPreProcessor: fo = self._incstack[-1] line = fo.readline() if len(line) > 0: - m = re.match( r'\s*include\s*=\s*(?P.*)', line ) + m = re.match( r'\s*include\s*=\s*(?P.*)', line.decode() ) if m: url = m.group('url') if len(url) == 0: @@ -133,7 +133,7 @@ class ConfigPreProcessor: fo = self._pushfile( url ) else: # check if the current line starts a new section - secmatch = re.match( r'\s*\[(?P
.*)\]', line ) + secmatch = re.match( r'\s*\[(?P
.*)\]', line.decode() ) if secmatch: self._section = secmatch.group('section') # line didn't match include=, just return it as is @@ -145,13 +145,13 @@ class ConfigPreProcessor: # if the section is prefixed by a space then it is breaks iniparser/configparser # so fix it - broken_sec_match = re.match(r'\s+\[(?P
.*)\]', line) + broken_sec_match = re.match(r'\s+\[(?P
.*)\]', line.decode()) if broken_sec_match: line = line.lstrip() # at this point we have a line from the topmost file on the stack # or EOF if the stack is empty if self._vars: - return varReplace(line, self._vars) + return varReplace(line.decode(), self._vars).encode() return line diff --git a/yum/plugins.py b/yum/plugins.py index 1f4bb39..3cb8230 100644 --- a/yum/plugins.py +++ b/yum/plugins.py @@ -348,11 +348,22 @@ class YumPlugins: return None parser = ConfigParser() confpp_obj = ConfigPreProcessor(conffilename) + processedLines = [] + while True: + line = confpp_obj.readline() + if not line: + break + processedLines.append(line.decode()) + congf = open('tmp_confilgfile', 'a+') + congf.writelines(processedLines) try: - parser.readfp(confpp_obj) + parser.read_file(congf) except ParsingError as e: raise Errors.ConfigError("Couldn't parse %s: %s" % (conffilename, str(e))) + finally: + congf.close() + os.remove('tmp_confilgfile') return parser def setCmdLine(self, opts, commands): -- 2.34.1