fix mic run error in mic-bootstrap 22/294822/14
authorbiao716.wang <biao716.wang@samsung.com>
Tue, 27 Jun 2023 06:41:13 +0000 (15:41 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Wed, 5 Jul 2023 11:27:47 +0000 (20:27 +0900)
The related code is changed in python3.10 in ubuntu22.04 for loggigng module.
once using --logfile=xxx option, it will show error: AttributeError: 'MicFileHandler' object has no attribute '_builtin_open'
this attribute is in FileHanderler, should declare it in child class MicFileHandler. Because in it, it use Handler to initialize.
Change-Id: I6eda4c1adadc73adc888262909fc825138c3af76
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
mic/3rdparty/pykickstart/base.py
mic/bootstrap.py
mic/imager/baseimager.py
mic/kickstart/__init__.py
mic/msger.py
mic/utils/misc.py
mic/utils/rpmmisc.py
plugins/backend/yumpkgmgr.py
plugins/backend/zypppkgmgr.py
tests/test_baseimager.py

index b1b7c19..c368702 100644 (file)
@@ -50,7 +50,7 @@ from pykickstart import __version__
 from pykickstart.errors import KickstartParseError, KickstartParseWarning, KickstartDeprecationWarning
 from pykickstart.ko import KickstartObject
 from pykickstart.version import versionToString
-from pykickstart.parser import Packages
+from pykickstart.parser import Packages, TpkPackages
 
 ###
 ### COMMANDS
@@ -482,6 +482,7 @@ class BaseHandler(KickstartHandler):
         # everything else I can think of.
         self.scripts = []
         self.packages = Packages()
+        self.tpk_packages = TpkPackages()
         self.platform = ""
 
         # Any sections that we do not understand but want to prevent causing errors
index f1bd137..f5df5f1 100644 (file)
@@ -179,7 +179,7 @@ class MiniBackend(object):
             os.makedirs(tmpdir)
         tmpfd, tmpfp = tempfile.mkstemp(dir=tmpdir, prefix="%s.pre-" % pkg)
         script = script.replace('\r', '')
-        os.write(tmpfd, script)
+        os.write(tmpfd, script.encode())
         os.close(tmpfd)
         os.chmod(tmpfp, 0o700)
 
index e3edcbb..2602c60 100644 (file)
@@ -1263,10 +1263,10 @@ class BaseImageCreator(object):
             (fd, path) = tempfile.mkstemp(prefix="ks-runscript-",
                                           dir=self._instroot + "/tmp")
             s.script = s.script.replace("\r", "")
-            os.write(fd, s.script)
+            os.write(fd, s.script.encode())
             if s.interp == '/bin/sh' or s.interp == '/bin/bash':
-                os.write(fd, '\n')
-                os.write(fd, 'exit 0\n')
+                os.write(fd, '\n'.encode())
+                os.write(fd, 'exit 0\n'.encode())
             os.close(fd)
             os.chmod(path, 0o700)
 
@@ -1280,7 +1280,7 @@ class BaseImageCreator(object):
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.STDOUT)
                     while p.poll() == None:
-                        msger.info(p.stdout.readline().strip())
+                        msger.info(p.stdout.readline().strip().decode())
                     if p.returncode != 0:
                         raise CreatorError("Failed to execute %%sign script "
                                            "with '%s'" % (s.interp))
@@ -1301,10 +1301,10 @@ class BaseImageCreator(object):
                                           dir=self._instroot + "/tmp")
 
             s.script = s.script.replace("\r", "")
-            os.write(fd, s.script)
+            os.write(fd, s.script.encode())
             if s.interp == '/bin/sh' or s.interp == '/bin/bash':
-                os.write(fd, '\n')
-                os.write(fd, 'exit 0\n')
+                os.write(fd, '\n'.encode())
+                os.write(fd, 'exit 0\n'.encode())
             os.close(fd)
             os.chmod(path, 0o700)
 
@@ -1327,7 +1327,7 @@ class BaseImageCreator(object):
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.STDOUT)
                     while p.poll() == None:
-                        msger.info(p.stdout.readline().strip())
+                        msger.info(p.stdout.readline().strip().decode())
                         end_time = time.time()
                         if (end_time - start_time)/60 > configmgr.create['postscripts_maxruntime']:
                             raise CreatorError("Your post script is executed more than %d mins, please check it!" % configmgr.create['postscripts_maxruntime'])
index a5f46ef..049dbb0 100755 (executable)
@@ -321,7 +321,7 @@ class UserConfig(KickstartConfig):
     def addUser(self, userconfig):
         args = [ "/usr/sbin/useradd" ]
         if userconfig.groups:
-            args += [ "--groups", string.join(userconfig.groups, ",") ]
+            args += [ "--groups", ",".join(userconfig.groups) ]
         if userconfig.name:
             args += [ "-m"]
             args += [ "-d", "/home/%s" % userconfig.name  ]
@@ -357,7 +357,7 @@ class UserConfig(KickstartConfig):
             if userconfig.name == "root":
                 msger.debug("root user, just set root user groups attribution")
                 if userconfig.groups:
-                    self.call(["/usr/sbin/usermod", "-a", "-G", "%s" % string.join(userconfig.groups, ","), "root"])
+                    self.call(["/usr/sbin/usermod", "-a", "-G", "%s" % ",".join(userconfig.groups), "root"])
                 continue
             self.addUser(userconfig)
 
@@ -386,7 +386,7 @@ class XConfig(KickstartConfig):
         if ksxconfig.defaultdesktop:
             self._check_sysconfig()
             f = open(self.path("/etc/sysconfig/desktop"), "w")
-            f.write("DESKTOP="+ksxconfig.defaultdesktop+"\n")
+            f.write("DESKTOP=" + str(ksxconfig.defaultdesktop) + "\n")
             f.close()
 
 class DesktopConfig(KickstartConfig):
@@ -396,28 +396,28 @@ class DesktopConfig(KickstartConfig):
         if ksdesktop.defaultdesktop:
             self._check_sysconfig()
             f = open(self.path("/etc/sysconfig/desktop"), "w")
-            f.write("DESKTOP="+ksdesktop.defaultdesktop+"\n")
+            f.write("DESKTOP=" + str(ksdesktop.defaultdesktop) + "\n")
             f.close()
             if os.path.exists(self.path("/etc/gdm/custom.conf")):
                 f = open(self.path("/etc/skel/.dmrc"), "w")
                 f.write("[Desktop]\n")
-                f.write("Session="+ksdesktop.defaultdesktop.lower()+"\n")
+                f.write("Session=" + str(ksdesktop.defaultdesktop.lower()) + "\n")
                 f.close()
         if ksdesktop.session:
             if os.path.exists(self.path("/etc/sysconfig/uxlaunch")):
                 f = open(self.path("/etc/sysconfig/uxlaunch"), "a+")
-                f.write("session="+ksdesktop.session.lower()+"\n")
+                f.write("session=" + str(ksdesktop.session.lower()) + "\n")
                 f.close()
         if ksdesktop.autologinuser:
             self._check_sysconfig()
             f = open(self.path("/etc/sysconfig/desktop"), "a+")
-            f.write("AUTOLOGIN_USER=" + ksdesktop.autologinuser + "\n")
+            f.write("AUTOLOGIN_USER=" + str(ksdesktop.autologinuser) + "\n")
             f.close()
             if os.path.exists(self.path("/etc/gdm/custom.conf")):
                 f = open(self.path("/etc/gdm/custom.conf"), "w")
                 f.write("[daemon]\n")
                 f.write("AutomaticLoginEnable=true\n")
-                f.write("AutomaticLogin=" + ksdesktop.autologinuser + "\n")
+                f.write("AutomaticLogin=" + str(ksdesktop.autologinuser) + "\n")
                 f.close()
 
 class MoblinRepoConfig(KickstartConfig):
@@ -873,7 +873,7 @@ def inst_langs(ks):
 def get_post_scripts(ks):
     scripts = []
     for s in ks.handler.scripts:
-        if s.type != ksparser.KS_SCRIPT_POST:
+        if s.type != ksparser.constants.KS_SCRIPT_POST:
             continue
         scripts.append(s)
     return scripts
@@ -881,8 +881,8 @@ def get_post_scripts(ks):
 def get_sign_scripts(ks):
     scripts = []
     for s in ks.handler.scripts:
-        if (s.type == ksparser.KS_SCRIPT_RUN or \
-            s.type == ksparser.KS_SCRIPT_UMOUNT):
+        if (s.type == ksparser.constants.KS_SCRIPT_RUN or \
+            s.type == ksparser.constants.KS_SCRIPT_UMOUNT):
             scripts.append(s)
     return scripts
 
index 99e4c94..8402f0e 100644 (file)
@@ -170,6 +170,8 @@ class MicFileHandler(logging.FileHandler):
         # we don't use FileHandler to initialize,
         # because filename might be expected to None
         logging.Handler.__init__(self)
+        self._builtin_open = open
+        self.errors = None
         self.stream = None
         if filename:
             self.baseFilename = os.path.abspath(filename)
index e50f8f3..fd7a080 100755 (executable)
@@ -180,7 +180,7 @@ def extract_rpm(rpmfile, targetdir):
                           stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     p1.stdout.close()
     (sout, serr) = p2.communicate()
-    msger.verbose(sout or serr)
+    msger.verbose(sout.decode() or serr.decode())
 
     os.chdir(olddir)
 
index 9d36586..a4c4962 100644 (file)
@@ -51,12 +51,14 @@ class RPMInstallCallback:
         tmpepoch = hdr['epoch']
         if tmpepoch is None: epoch = '0'
         else: epoch = str(tmpepoch)
-
+        #name, version, release must have value according to spec rule.
         return (hdr['name'], hdr['arch'], epoch, hdr['version'], hdr['release'])
 
     def _makeHandle(self, hdr):
-        handle = '%s:%s.%s-%s-%s' % (hdr['epoch'], hdr['name'], hdr['version'],
-          hdr['release'], hdr['arch'])
+        tmpepoch = hdr['epoch']
+        if tmpepoch is None: epoch = '0'
+        else: epoch = str(tmpepoch) #epoch is 'int' object
+        handle = '%s:%s.%s-%s-%s' % (tmpepoch, hdr['name'], hdr['version'], hdr['release'], hdr['arch'])
 
         return handle
 
index 3370fef..b16afbf 100644 (file)
@@ -243,11 +243,11 @@ class Yum(BackendPlugin, yum.YumBase):
     def selectGroup(self, grp, include = ksparser.constants.GROUP_DEFAULT):
         try:
             yum.YumBase.selectGroup(self, grp)
-            if include == ksparser.GROUP_REQUIRED:
+            if include == ksparser.constants.GROUP_REQUIRED:
                 for p in list(grp.default_packages.keys()):
                     self.deselectPackage(p)
 
-            elif include == ksparser.GROUP_ALL:
+            elif include == ksparser.constants.GROUP_ALL:
                 for p in list(grp.optional_packages.keys()):
                     self.selectPackage(p)
 
index b95f9bd..cde910d 100644 (file)
@@ -323,7 +323,7 @@ class Zypp(BackendPlugin):
                 break
 
         if found:
-            if include == ksparser.GROUP_REQUIRED:
+            if include == ksparser.constants.GROUP_REQUIRED:
                 list([self.deselectPackage(p) for p in list(grp.default_packages.keys())])
 
             return None
index a4f66e8..4049daf 100644 (file)
@@ -55,7 +55,7 @@ class BaseImgrTest(unittest.TestCase):
         dev_null = os.open("/dev/null", os.O_WRONLY)
         p = subprocess.Popen('mount', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         
-        for entry in p.communicate()[0].split('\n'):
+        for entry in p.communicate()[0].decode().split('\n'):
             if entry.find(pattern) > 0:
                 real_mount_list.append(entry.split(' ')[2])
         real_mount_list.sort()