fix yum run error 98/292498/9
authorbiao716.wang <biao716.wang@samsung.com>
Tue, 9 May 2023 05:49:40 +0000 (14:49 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Wed, 17 May 2023 05:30:29 +0000 (14:30 +0900)
Change-Id: Ic5269cdeaab3371d0b16920267269820503c02b6
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
cli.py
output.py
utils.py
yum-updatesd.py
yum/__init__.py
yum/config.py
yum/parser.py
yum/plugins.py

diff --git a/cli.py b/cli.py
index 7cad6af4492625995c9bfce1ffdf9353b6feba0c..5a7903d7063a740da53a961ecae47c59719d6cd2 100644 (file)
--- 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):
 
index 5852abd713e2dedfa6bc5002aef06d0644517531..8fba9eb15903fbaff2e7c2ebd406aed4009f608f 100755 (executable)
--- 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:
index 3e601063855832ca869ea784e690268d0ca17892..879e27e8b3314f7d8d3b46fe8e11a839ead97410 100644 (file)
--- 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
index 1c5b2d1c0ee38dd1608bcb9bef0e8ca562edf303..62addb588ed2d0cec1babb1d5adfba536da8bdae 100644 (file)
@@ -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)
 
index 97e3ca4dd2ad020737b6a3a01be93ea279469b98..82ef95e77ae8baa78307442a6eaeadd0c34392bc 100644 (file)
@@ -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
     
index 850e7dcb633979d4b3400935d2d657a778ab7724..857bccf6439a4973f310df856cfee0b02f2e881c 100644 (file)
@@ -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()
index f1debb62ec3ee41f7b222582460c9aa7f27016a1..0b8a5e9ab7371b5db3e6f2e4c5469bc47b25dfad 100644 (file)
@@ -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<url>.*)', line )
+                m = re.match( r'\s*include\s*=\s*(?P<url>.*)', 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<section>.*)\]', line )
+                    secmatch = re.match( r'\s*\[(?P<section>.*)\]', 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<section>.*)\]', line)
+        broken_sec_match = re.match(r'\s+\[(?P<section>.*)\]', 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
     
     
index 1f4bb399ca6e1f96c765d2a711df42dc4c0b36c8..3cb8230dc72764ff1bc56eb69fa9dacf544ef21b 100644 (file)
@@ -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):