Another method of install tpk.
authoryuhuan.yang <yuhuan.yang@samsung.com>
Mon, 16 Oct 2017 16:42:28 +0000 (00:42 +0800)
committeryuhuan.yang <yuhuan.yang@samsung.com>
Fri, 26 Jan 2018 08:35:42 +0000 (16:35 +0800)
Change-Id: Ibe2f1cfaa7625ab1ea938feda5df6406beb267e6

14 files changed:
mic/3rdparty/pykickstart/base.py
mic/3rdparty/pykickstart/handlers/control.py
mic/3rdparty/pykickstart/parser.py
mic/3rdparty/pykickstart/sections.py
mic/conf.py
mic/imager/baseimager.py
mic/kickstart/__init__.py
mic/kickstart/custom_commands/__init__.py
mic/kickstart/custom_commands/micrepo.py
mic/rt_util.py
plugins/imager/fs_plugin.py
plugins/imager/loop_plugin.py
plugins/imager/qcow_plugin.py
plugins/imager/raw_plugin.py

index e6c8f56f9dc1a1e7e8a9c5517fe1ba2a98904558..e3597dfba28e5f9a1689b93fa5d178d5d4f75ff5 100644 (file)
@@ -46,7 +46,7 @@ import types
 import warnings
 from pykickstart.errors import *
 from pykickstart.ko import *
-from pykickstart.parser import Packages
+from pykickstart.parser import Packages,TpkPackages
 from pykickstart.version import versionToString
 
 ###
@@ -253,6 +253,7 @@ class BaseHandler(KickstartObject):
         # everything else I can think of.
         self.scripts = []
         self.packages = Packages()
+        self.tpk_packages = TpkPackages()
         self.platform = ""
 
         # These will be set by the dispatcher.
index d8c8f2b89941c7c8de37393b7127e483f6a341b0..119e32fc630f2003ae7aca997a722da7db26a310 100644 (file)
@@ -19,6 +19,7 @@
 #
 from pykickstart.version import *
 from pykickstart.commands import *
+from mic.kickstart.custom_commands.micrepo import *
 
 # This map is keyed on kickstart syntax version as provided by
 # pykickstart.version.  Within each sub-dict is a mapping from command name
@@ -217,6 +218,7 @@ commandMap = {
         "raid": raid.FC5_Raid,
         "reboot": reboot.FC6_Reboot,
         "repo": repo.FC6_Repo,
+        "tpk_repo": Mic_Tpk_Repo,
         "rootpw": rootpw.FC3_RootPw,
         "selinux": selinux.FC3_SELinux,
         "services": services.FC6_Services,
@@ -1087,6 +1089,7 @@ dataMap = {
         "PartData": partition.FC4_PartData,
         "RaidData": raid.FC5_RaidData,
         "RepoData": repo.FC6_RepoData,
+        "TpkRepoData": Mic_Tpk_RepoData,
         "UserData": user.FC6_UserData,
         "VolGroupData": volgroup.FC3_VolGroupData,
         "ZFCPData": zfcp.FC3_ZFCPData,
index 02a0f320f2e5ee61718a82675fe30b912275ecee..46495f6a81c928e5128ceb77be60d9d788750559 100644 (file)
@@ -30,7 +30,6 @@ This module exports several important classes:
 
     KickstartParser - The kickstart file parser state machine.
 """
-
 from collections import Iterator
 import os
 import shlex
@@ -295,6 +294,7 @@ class Packages(KickstartObject):
         self.groupList = []
         self.handleMissing = constants.KS_MISSING_PROMPT
         self.packageList = []
+        self.tpk_packageList = []
         self.instLangs = None
 
     def __str__(self):
@@ -409,7 +409,25 @@ class Packages(KickstartObject):
         self.packageList = list(existingPackageSet)
         self.excludedList = list(existingExcludedSet)
 
-
+class TpkPackages(KickstartObject):
+    """A class representing the %tpk_packages section of the kickstart file."""
+    def __init__(self, *args, **kwargs):
+        KickstartObject.__init__(self, *args, **kwargs)
+        self.tpk_packageList = []
+    def __str__(self):
+        tpk_pkgs = ""
+        retval = "\n%tpk_packages"
+        p = self.packageList
+        p.sort()
+        for pkg in p:
+            tpk_pkgs += "%s\n" % pkg
+        return retval + "\n" +tpk_pkgs
+    def add(self, tpkPackageList):
+        tpk_PackageSet = set(self.tpk_packageList)
+        for tpk_pkg in tpkPackageList:
+            stripped = tpk_pkg.strip()
+            tpk_PackageSet.add(stripped)
+        self.tpk_packageList = list(tpk_PackageSet)
 ###
 ### PARSER
 ###
@@ -706,3 +724,5 @@ class KickstartParser:
         self.registerSection(RunScriptSection(self.handler, dataObj=Script))
         self.registerSection(PostUmountScriptSection(self.handler, dataObj=Script))
         self.registerSection(PackageSection(self.handler))
+        self.registerSection(TpkPackageSection(self.handler))
+
index 9452767771df09f6075582442a766c5b80818b46..c360a9059c4131490a2b456717d93d2241e965ee 100644 (file)
@@ -234,7 +234,6 @@ class PackageSection(Section):
 
         (h, s, t) = line.partition('#')
         line = h.rstrip()
-
         self.handler.packages.add([line])
 
     def handleHeader(self, lineno, args):
@@ -273,3 +272,21 @@ class PackageSection(Section):
 
         if opts.instLangs:
             self.handler.packages.instLangs = opts.instLangs
+
+class TpkPackageSection(Section):
+    sectionOpen = "%tpk_packages"
+
+    def handleLine(self, line):
+        if not self.handler:
+            return
+
+        (h, s, t) = line.partition('#')
+        line = h.rstrip()
+        self.handler.tpk_packages.add([line])
+
+    def handleHeader(self, lineno, args):
+        """Process the arguments to the %tpk_packages header and set attributes
+           on the Version's TpkPackages instance appropriate.  This method may be
+           overridden in a subclass if necessary.
+        """
+        Section.handleHeader(self, lineno, args)
index 77de681743c37caf6f1efa5c72ae6310f0d9124e..9299cfe47c2216696982438819d5db89eee33bb6 100755 (executable)
@@ -71,6 +71,7 @@ class ConfigMgr(object):
                     "check_pkgs": [],
                     "repourl": {},
                     "localrepos": [],  # save localrepos
+                    "localtpkrepos":[],
                     "runtime": "bootstrap",
                     "extrarepos": {},
                     "ignore_ksrepo": False,
@@ -262,6 +263,14 @@ class ConfigMgr(object):
         self.create['repomd'] = misc.get_metadata_from_repos(
                                                     ksrepos,
                                                     self.create['cachedir'])
+        kstpkrepos = kickstart.get_tpkrepos(ks)
+        if kstpkrepos:
+            for tpk_repo in kstpkrepos:
+                if hasattr(tpk_repo,'baseurl') and tpk_repo.baseurl.startswith("file:"):
+                    tpk_repourl = tpk_repo.baseurl.replace('file:','')
+                    tpk_repourl = "/%s" % tpk_repourl.lstrip('/')
+                    self.create['localtpkrepos'].append(tpk_repourl)
+
         msger.raw(" DONE")
 
         target_archlist, archlist = misc.get_arch(self.create['repomd'])
index f39d236f0b130abf7d5fb147dd38d2a87364b33b..ef86f0fad64313db8e580634112183f858bed682 100755 (executable)
@@ -1,4 +1,3 @@
-
 #!/usr/bin/python -tt
 #
 # Copyright (c) 2007 Red Hat  Inc.
@@ -28,7 +27,6 @@ import tarfile
 import glob
 import json
 from datetime import datetime
-
 import rpm
 import time
 from mic import kickstart
@@ -38,6 +36,7 @@ from mic.utils import misc, grabber, runner, fs_related as fs
 from mic.chroot import kill_proc_inchroot
 from mic.archive import get_archive_suffixes
 from mic.conf import configmgr
+from mic.utils.grabber import myurlgrab
 #post script max run time
 MAX_RUN_TIME = 120
 
@@ -1087,6 +1086,7 @@ class BaseImageCreator(object):
             if 'debuginfo' in self.install_pkgs:
                 pkg_manager.install_debuginfo = True
 
+
         for repo in kickstart.get_repos(self.ks, repo_urls, self.ignore_ksrepo):
             (name, baseurl, mirrorlist, inc, exc,
              proxy, proxy_username, proxy_password, debuginfo,
@@ -1153,6 +1153,47 @@ class BaseImageCreator(object):
             except:
                 pass
 
+    def tpkinstall(self):
+        if self.ks:
+            tpk_pkgs = kickstart.get_tpkpackages(self.ks)
+            tpk_repoList = kickstart.get_tpkrepos(self.ks)
+            if tpk_repoList and tpk_pkgs:
+                tpk_dir = "/usr/apps/.preload-tpk"
+                fs.makedirs(self._instroot + "/usr/apps")
+                fs.makedirs(self._instroot + tpk_dir)
+            for pkg in tpk_pkgs:
+                flag = 0
+                for tpk_repo in tpk_repoList:
+                    if hasattr(tpk_repo,'baseurl') and tpk_repo.baseurl.startswith("file:"):
+                        tpk_repourl = tpk_repo.baseurl.replace('file:','')
+                        tpk_repourl = "/%s" % tpk_repourl.lstrip('/')
+                        tpk_pkgpath = tpk_repourl + "/"+ pkg
+                        if os.path.isfile(tpk_pkgpath):
+                            shutil.copy(tpk_pkgpath,self._instroot + tpk_dir)
+                            flag = 1
+                            break
+                    elif hasattr(tpk_repo,'baseurl'):
+                        url = tpk_repo.baseurl.join(pkg)
+                        filename = self._instroot+tpk_dir+"/"+pkg
+                        if tpk_repo.baseurl.startswith("http:"):
+                            import urllib
+                            status = urllib.urlopen(url).code
+                            if status == 200:
+                                filename = myurlgrab(url.full, filename, None)
+                                flag = 1
+                                break
+                            elif status == 404 or status == None:
+                                continue
+                        #url is ok, then download, url wrong, check other url.
+                        elif tpk_repo.baseurl.startswith("https:") :
+                            try:
+                                flag = 1
+                                filename = myurlgrab(url.full, filename, None)
+                            except CreatorError:
+                                continue
+                if flag == 0:
+                    raise CreatorError("Tpk package missing.")
+
     def postinstall(self):
         pass
 
index bc97e2e7bf1b93eda7ed37c6fb83d81895d960e9..c3cb5f4150b0a00b9a38568f6a9cc176912d8520 100755 (executable)
@@ -100,11 +100,13 @@ def read_kickstart(path):
     using_version = ksversion.DEVEL
     commandMap[using_version]["desktop"] = desktop.Mic_Desktop
     commandMap[using_version]["repo"] = micrepo.Mic_Repo
+    commandMap[using_version]["tpk_repo"] = micrepo.Mic_Tpk_Repo
     commandMap[using_version]["bootloader"] = micboot.Mic_Bootloader
     commandMap[using_version]["part"] = partition.Mic_Partition
     commandMap[using_version]["partition"] = partition.Mic_Partition
     commandMap[using_version]["installerfw_plugins"] = installerfw.Mic_installerfw
     dataMap[using_version]["RepoData"] = micrepo.Mic_RepoData
+    dataMap[using_version]["Tpk_RepoData"] = micrepo.Mic_Tpk_RepoData
     dataMap[using_version]["PartData"] = partition.Mic_PartData
     superclass = ksversion.returnClassForVersion(version=using_version)
 
@@ -772,9 +774,32 @@ def get_repos(ks, repo_urls=None, ignore_ksrepo=False):
                                           repo.get('user', None),
                                           repo.get('passwd', None))
             repos[name] = Repo(**repo)
-
     return repos.values()
 
+TpkRepoType = collections.namedtuple("TpkRepo",
+               "name, baseurl,proxy,proxy_username,proxy_password,ssl_verify")
+
+def TpkRepo(name, baseurl, proxy=None,proxy_username=None, proxy_password=None,ssl_verify=None):
+    return TpkRepoType(name, baseurl,proxy,proxy_username,proxy_password,ssl_verify)
+
+
+def get_tpkrepos(ks):
+    tpkrepos = {}
+    for tpkrepodata in ks.handler.tpk_repo.tpkRepoList:
+        tpkrepo = {}
+        for field in TpkRepoType._fields:
+            if hasattr(tpkrepodata, field) and getattr(tpkrepodata, field):
+                tpkrepo[field] = getattr(tpkrepodata, field)
+
+        if hasattr(tpkrepodata, 'baseurl') and getattr(tpkrepodata, 'baseurl'):
+            tpkrepo['baseurl'] = SafeURL(getattr(tpkrepodata, 'baseurl'),getattr(tpkrepodata, 'user',None),getattr(tpkrepodata, 'passwd',None))
+
+        if 'name' in tpkrepo:
+            tpkrepos[tpkrepo['name']] = TpkRepo(**tpkrepo)
+
+    return tpkrepos.values()
+
+
 def convert_method_to_repo(ks):
     try:
         ks.handler.repo.methodToRepo()
@@ -790,6 +815,9 @@ def get_pre_packages(ks, required=()):
 def get_packages(ks, required=()):
     return ks.handler.packages.packageList + list(required)
 
+def get_tpkpackages(ks):
+    return ks.handler.tpk_packages.tpk_packageList
+
 def get_groups(ks, required=()):
     return ks.handler.packages.groupList + list(required)
 
index 5f4c440369d2969f5c12cd871fc984536528114d..381c91787a45f39b2012f2af52251e0248678cfe 100644 (file)
@@ -1,5 +1,5 @@
 from desktop import Mic_Desktop
-from micrepo import Mic_Repo, Mic_RepoData
+from micrepo import Mic_Repo, Mic_RepoData,Mic_Tpk_Repo, Mic_Tpk_RepoData
 from partition import Mic_Partition
 from installerfw import Mic_installerfw
 
@@ -7,6 +7,8 @@ __all__ = (
     "Mic_Desktop",
     "Mic_Repo",
     "Mic_RepoData",
+    "Mic_Tpk_Repo",
+    "Mic_Tpk_RepoData",
     "Mic_Partition",
     "Mic_installerfw",
 )
index b38ae77174789c0742cbb7fb74da569b5b0a4301..25cdae9bd52a5358a19504cceb5a6779c76ccbf1 100644 (file)
@@ -50,6 +50,14 @@ class Mic_RepoData(F14_RepoData):
 
         return retval
 
+class Mic_Tpk_RepoData(Mic_RepoData):
+    "Mic customized tpk repo data"
+    def __init__(self, *args, **kw):
+        Mic_RepoData.__init__(self, *args, **kw)
+    def __str__(self):
+        retval = Mic_RepoData._getArgsAsStr(self)
+        retval = "tpk_repo " + retval
+        return retval
 
 class Mic_Repo(F14_Repo):
     "Mic customized repo command"
@@ -71,3 +79,19 @@ class Mic_Repo(F14_Repo):
         op.add_option("--priority", type="int")
         op.add_option("--ssl_verify", default=None)
         return op
+
+
+class Mic_Tpk_Repo(Mic_Repo):
+    def __init__(self, writePriority=0, *args, **kwargs):
+        Mic_Repo.__init__(self, writePriority, *args, **kwargs)
+        self.op = self._getParser()
+
+        self.tpkRepoList = kwargs.get("tpkRepoList", [])
+
+    def _getParser(self):
+        op = Mic_Repo._getParser(self)
+        return op
+
+    def dataList(self):
+        return self.tpkRepoList
+
index ef350a6ca2cc9bf5b77239776c42f425f7274b80..61b0bb25fa9f07f5525aafa0e47933638466b23c 100644 (file)
@@ -148,6 +148,8 @@ def get_bindmounts(cropts):
 
     for lrepo in cropts['localrepos']:
         binddirs.append(lrepo)
+    for ltpkrepo in cropts['localtpkrepos']:
+        binddirs.append(ltpkrepo)
 
     bindlist = map(expath, filter(None, binddirs))
     bindlist += map(os.path.dirname, map(expath, filter(None, bindfiles)))
index a8b480b7f1cba0a64512aca2bb31ffada25a9e51..b922b28c84211fac80e2c12d79637946364eabe2 100755 (executable)
@@ -93,6 +93,7 @@ class FsPlugin(ImagerPlugin):
             creator.check_depend_tools()
             creator.mount(None, creatoropts["cachedir"])
             creator.install()
+            creator.tpkinstall()
             #Download the source packages ###private options
             if args.include_src:
                 installed_pkgs =  creator.get_installed_packages()
index 8815fe4db2a15e215d088c6839e1cff7c3dab4b2..d81eb457656a3a6e54b1f646e338c0c91c39a9cb 100755 (executable)
@@ -101,6 +101,7 @@ class LoopPlugin(ImagerPlugin):
             creator.check_depend_tools()
             creator.mount(None, creatoropts["cachedir"])
             creator.install()
+            creator.tpkinstall()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
             creator.copy_attachment()
index 7a3d860e2262b932d0a50332e47a79ef559da555..2cc9d4344789f79a14f66ce0b67cf3994390536d 100755 (executable)
@@ -132,6 +132,7 @@ class QcowPlugin(ImagerPlugin):
             creator.check_depend_tools()
             creator.mount(None, creatoropts["cachedir"])
             creator.install()
+            creator.tpkinstall()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
             creator.copy_attachment()
index ef537a42e5edb8a3daf81e18c2261ef996528681..7d44bc3266338dd4f3a9caafc9850346475e0957 100755 (executable)
@@ -99,6 +99,7 @@ class RawPlugin(ImagerPlugin):
             creator.check_depend_tools()
             creator.mount(None, creatoropts["cachedir"])
             creator.install()
+            creator.tpkinstall()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
             creator.copy_attachment()