Added priority and cost option for repos
authorZhang Qiang <qiang.z.zhang@intel.com>
Fri, 16 Dec 2011 06:09:58 +0000 (14:09 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Fri, 16 Dec 2011 07:24:08 +0000 (15:24 +0800)
backport from mic2:
    https://meego.gitorious.org/meego-developer-tools/image-creator/commit/7def0263d132d25f026a9317b53618ba1a48e943

mic/imager/baseimager.py
mic/kickstart/__init__.py
mic/kickstart/custom_commands/moblinrepo.py
mic/utils/misc.py
plugins/backend/yumpkgmgr.py
plugins/backend/zypppkgmgr.py

index fcaeb5f..23be5ae 100644 (file)
@@ -839,10 +839,11 @@ class BaseImageCreator(object):
         for repo in kickstart.get_repos(self.ks, repo_urls):
             (name, baseurl, mirrorlist, inc, exc,
              proxy, proxy_username, proxy_password, debuginfo,
-             source, gpgkey, disable, ssl_verify) = repo
+             source, gpgkey, disable, ssl_verify, cost, priority) = repo
 
             yr = pkg_manager.addRepository(name, baseurl, mirrorlist, proxy,
-                        proxy_username, proxy_password, inc, exc, ssl_verify)
+                        proxy_username, proxy_password, inc, exc, ssl_verify,
+                        cost, priority)
 
         if kickstart.exclude_docs(self.ks):
             rpm.addMacro("_excludedocs", "1")
index 146ce23..3fadce3 100644 (file)
@@ -688,10 +688,16 @@ def get_repos(ks, repo_urls = {}):
         ssl_verify = True
         if hasattr(repo, "ssl_verify"):
             ssl_verify = repo.ssl_verify == "yes"
+        cost = None
+        if hasattr(repo, "cost"):
+            cost = repo.cost
+        priority = None
+        if hasattr(repo, "priority"):
+            priority = repo.priority
 
         repos[repo.name] = (repo.name, baseurl, mirrorlist, inc, exc,
                             proxy, proxy_username, proxy_password, debuginfo,
-                            source, gpgkey, disable, ssl_verify)
+                            source, gpgkey, disable, ssl_verify, cost, priority)
 
     return repos.values()
 
index 9d120a4..420b126 100644 (file)
@@ -39,6 +39,7 @@ class Moblin_RepoData(F8_RepoData):
         self.source = source
         self.gpgkey = gpgkey
         self.ssl_verify = ssl_verify.lower()
+        self.priority = priority
 
     def _getArgsAsStr(self):
         retval = F8_RepoData._getArgsAsStr(self)
@@ -61,6 +62,8 @@ class Moblin_RepoData(F8_RepoData):
             retval += " --disable"
         if self.ssl_verify:
             retval += " --ssl_verify=%s" % self.ssl_verify
+        if self.priority:
+            retval += " --priority=%s" % self.priority
 
         return retval
 
@@ -99,4 +102,6 @@ class Moblin_Repo(F8_Repo):
                       default=None, nargs=1)
         op.add_option("--ssl_verify", type="string", action="store", dest="ssl_verify",
                       default="yes")
+        op.add_option("--priority", type="int", action="store", dest="priority",
+                      default=None)
         return op
index 8a76014..89d8f40 100644 (file)
@@ -223,10 +223,12 @@ def get_repostrs_from_ks(ks):
             repostr += ",debuginfo:"
         if hasattr(repodata, "source") and repodata.source:
             repostr += ",source:"
-        if  hasattr(repodata, "gpgkey") and repodata.gpgkey:
+        if hasattr(repodata, "gpgkey") and repodata.gpgkey:
             repostr += ",gpgkey:" + repodata.gpgkey
         if hasattr(repodata, "ssl_verify") and repodata.ssl_verify:
             repostr += ",ssl_verify:" + repodata.ssl_verify
+        if hasattr(repodata, "priority") and repodata.priority:
+            repostr += ",priority:%d" % repodata.priority
         kickstart_repos.append(repostr[1:])
     return kickstart_repos
 
index 5d31d55..6ebf69b 100644 (file)
@@ -190,7 +190,9 @@ class Yum(BackendPlugin, yum.YumBase):
 
     def addRepository(self, name, url = None, mirrorlist = None, proxy = None,
                       proxy_username = None, proxy_password = None,
-                      inc = None, exc = None, ssl_verify=True):
+                      inc = None, exc = None, ssl_verify=True, cost = None,
+                      priority=None):
+        # TODO: Handle priority attribute for repos
         def _varSubstitute(option):
             # takes a variable and substitutes like yum configs do
             option = option.replace("$basearch", rpmUtils.arch.getBaseArch())
@@ -231,6 +233,8 @@ class Yum(BackendPlugin, yum.YumBase):
         repo.enable()
         repo.setup(0)
         self.repos.add(repo)
+        if cost:
+            repo.cost = cost
 
         msger.verbose('repo: %s was added' % name)
         return repo
index cb02aa4..9fd487a 100644 (file)
@@ -45,6 +45,7 @@ class RepositoryStub:
         self.enabled = True
         self.autorefresh = True
         self.keeppackages = True
+        self.priority = None
 
 class RepoError(CreatorError):
     pass
@@ -251,7 +252,9 @@ class Zypp(BackendPlugin):
 
     def addRepository(self, name, url = None, mirrorlist = None, proxy = None,
                       proxy_username = None, proxy_password = None,
-                      inc = None, exc = None, ssl_verify = True):
+                      inc = None, exc = None, ssl_verify = True, cost=None,
+                      priority=None):
+        # TODO: Handle cost attribute for repos
         if not self.repo_manager:
             self.__initialize_repo_manager()
 
@@ -280,6 +283,8 @@ class Zypp(BackendPlugin):
 
         # Enable gpg check for verifying corrupt packages
         repo.gpgcheck = 1
+        if priority:
+            repo.priority = priority
         self.repos.append(repo)
 
         try:
@@ -301,6 +306,8 @@ class Zypp(BackendPlugin):
                     port = proxyinfo[1]
                 baseurl.setQueryParam ("proxyport", port)
             repo_info.addBaseUrl(baseurl)
+            if repo.priority:
+                repo_info.setPriority(repo.priority)
             self.repo_manager.addRepository(repo_info)
             self.__build_repo_cache(name)
         except RuntimeError, e: