From: wanchao-xu Date: Wed, 14 Aug 2024 07:39:21 +0000 (+0800) Subject: Support to install the updated packages while re-creating image. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f9869f6af9c44237132f82a5f6e83f10f5a0bde;p=tools%2Fmic.git Support to install the updated packages while re-creating image. Change-Id: Ief4d79ce92e80946ef5806dc57dc95cbf17bf167 Signed-off-by: wanchao-xu --- diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 941aadc..6700778 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -961,6 +961,22 @@ class BaseImageCreator(object): return None + def __update_packages(self, pkg_manager, updated_pkgs): + skipped_pkgs = [] + for pkg in updated_pkgs: + e = pkg_manager.updatePackage(pkg) + if e: + if kickstart.ignore_missing(self.ks): + skipped_pkgs.append(pkg) + elif self.__is_excluded_pkg(pkg): + skipped_pkgs.append(pkg) + else: + raise CreatorError("Failed to find package '%s' : %s" % + (pkg, e)) + + for pkg in skipped_pkgs: + msger.warning("Skipping missing package '%s'" % (pkg)) + def __select_packages(self, pkg_manager): skipped_pkgs = [] for pkg in self._required_pkgs: @@ -1051,7 +1067,7 @@ class BaseImageCreator(object): fpath = os.path.join(root, fname) self._attachment.append(fpath) - def install(self, repo_urls=None): + def install(self, repo_urls=None, updated_pkgs=None): """Install packages into the install root. This function installs the packages listed in the supplied kickstart @@ -1132,12 +1148,15 @@ class BaseImageCreator(object): rpm.addMacro("_install_langs", kickstart.inst_langs(self.ks)) try: - self.__preinstall_packages(pkg_manager) - self.__select_packages(pkg_manager) - self.__select_groups(pkg_manager) - self.__deselect_packages(pkg_manager) - #self.__localinst_packages(pkg_manager) - self.__check_packages(pkg_manager) + if self.reuse_environment and updated_pkgs != None: + self.__update_packages(pkg_manager, updated_pkgs) + else: + self.__preinstall_packages(pkg_manager) + self.__select_packages(pkg_manager) + self.__select_groups(pkg_manager) + self.__deselect_packages(pkg_manager) + # self.__localinst_packages(pkg_manager) + self.__check_packages(pkg_manager) BOOT_SAFEGUARD = 256 * 1024 * 1024 # 256M checksize = self._root_fs_avail diff --git a/plugins/backend/zypppkgmgr.py b/plugins/backend/zypppkgmgr.py index 950c1af..2733493 100644 --- a/plugins/backend/zypppkgmgr.py +++ b/plugins/backend/zypppkgmgr.py @@ -77,6 +77,7 @@ class Zypp(BackendPlugin): self.excpkgs = {} self.pre_pkgs = [] self.check_pkgs = [] + self.update_pkgs = [] self.probFilterFlags = [ rpm.RPMPROB_FILTER_OLDPACKAGE, rpm.RPMPROB_FILTER_REPLACEPKG ] @@ -158,20 +159,14 @@ class Zypp(BackendPlugin): name = ".".join(sp) return name, arch - def selectPackage(self, pkg): - """Select a given package or package pattern, can be specified + def _findPackage(self, pkg): + """find a given package or package pattern, can be specified with name.arch or name* or *name """ if not self.Z: self.__initialize_zypp() - def markPoolItem(obs, pi): - if obs == None: - pi.status().setToBeInstalled (zypp.ResStatus.USER) - else: - obs.status().setToBeInstalled (zypp.ResStatus.USER) - def cmpEVR(p1, p2): # compare criterion: arch compatibility first, then repo # priority, and version last @@ -198,6 +193,7 @@ class Zypp(BackendPlugin): return rpm.labelCompare((e1, v1, r1), (e2, v2, r2)) found = False + packages = [] startx = pkg.startswith("*") endx = pkg.endswith("*") ispattern = startx or endx @@ -240,9 +236,12 @@ class Zypp(BackendPlugin): obspkg = self.whatObsolete(item) if arch: if arch == str(item.arch()): - pitem.status().setToBeInstalled (zypp.ResStatus.USER) + packages.append(pitem) else: - markPoolItem(obspkg, pitem) + if obspkg == None: + packages.append(pitem) + else: + packages.append(obspkg) if not ispattern: break @@ -266,13 +265,39 @@ class Zypp(BackendPlugin): found = True obspkg = self.whatObsolete(item) - markPoolItem(obspkg, pitem) + if obspkg == None: + packages.append(pitem) + else: + packages.append(obspkg) break - if found: + return packages + + def selectPackage(self, pkg): + """Select a given package or package pattern, can be specified + with name.arch or name* or *name + """ + + packages = self._findPackage(pkg) + if len(packages) > 0: + for pkg in packages: + pkg.status().setToBeInstalled(zypp.ResStatus.USER) + return None + else: + raise CreatorError("Unable to find package: %s" % (pkg)) + + def updatePackage(self, pkg): + """Update a given package or package pattern, can be specified + with name.arch or name* or *name + """ + + packages = self._findPackage(pkg) + if len(packages) > 0: + for pkg in packages: + self.update_pkgs.append(pkg) return None else: - raise CreatorError("Unable to find package: %s" % (pkg,)) + raise CreatorError("Unable to find package: %s" % (pkg)) def inDeselectPackages(self, pitem): """check if specified pacakges are in the list of inDeselectPackages @@ -482,10 +507,28 @@ class Zypp(BackendPlugin): elif os.path.splitext(cropts['local_pkgs_path'])[-1] == '.rpm': return [cropts['local_pkgs_path']] return [] + def __localinst_packages(self): for rpm_path in self._get_local_packages(): self.installLocal(rpm_path) + + def _getPackagesToReinstall(self): + to_install_pkgs = [] + for pkg in self.update_pkgs: + to_install_pkgs.append(pkg) + isInstalled = pkg.status().isInstalled() + msger.info("Update package %s : installed = %s" % (pkg.name(), isInstalled)) + + for item in self.Z.pool(): + if item.name() == pkg.name and item.kind() == pkg.kind(): + msger.info("package %s in pool : installed = %s" % (item.name(), item.status().isInstalled())) + + return to_install_pkgs + def runInstall(self, checksize = 0): + if not self.Z: + self.__initialize_zypp() + os.environ["HOME"] = "/" os.environ["LD_PRELOAD"] = "" self.buildTransaction() @@ -495,6 +538,9 @@ class Zypp(BackendPlugin): installed_pkgs = todo._toInstall dlpkgs = [] + if len(installed_pkgs) == 0: + installed_pkgs = self._getPackagesToReinstall() + for pitem in installed_pkgs: if not zypp.isKindPattern(pitem) and \ not self.inDeselectPackages(pitem): diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index bb8f134..5053084 100755 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -56,7 +56,12 @@ class LoopPlugin(ImagerPlugin): creator.check_depend_tools() creator.mount(None, creatoropts["cachedir"]) if creator.reuse_environment: - msger.info("Re-install the packages which are modified") + msger.debug("Update the packages which are modified") + if args.updated_pkgs: + updated_pkgs = [] + for pkg in args.updated_pkgs.split(','): + updated_pkgs.append(pkg) + creator.install(updated_pkgs = updated_pkgs) else: creator.install() creator.tpkinstall() diff --git a/tools/mic b/tools/mic index e0f665d..e7fc553 100755 --- a/tools/mic +++ b/tools/mic @@ -170,8 +170,8 @@ def create_parser(parser): loop_parser.add_argument('--reuse-environment', action='store_true', default=False, help='Reuse the image creator environment of mic') group = loop_parser.add_argument_group('only for reuse create environment option') - group.add_argument('--reinsrall-pkgs', action='store', dest='reinstall_pkgs', default=[], - help='Reinstall the given packages to re-create image, ' + group.add_argument('--updated-pkgs', action='store', dest='updated_pkgs', default=None, + help='Update the given packages to re-create image, ' 'packages should be separated by comma') qcow_parser = subparsers.add_parser('qcow', parents=[parent_parser], help='create qcow image')