From f33b9e51c8af3fd07b86757218258ce9b10188a1 Mon Sep 17 00:00:00 2001 From: Zhang Qiang Date: Tue, 1 Nov 2011 18:03:19 +0800 Subject: [PATCH] arch: check arch type from repository data. --- mic/configmgr.py | 16 +++++++++++++++- mic/utils/misc.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/mic/configmgr.py b/mic/configmgr.py index f41ed89..c62dceb 100644 --- a/mic/configmgr.py +++ b/mic/configmgr.py @@ -155,9 +155,23 @@ class ConfigMgr(object): msger.info("Retrieving repo metadata:") ksrepos = misc.get_repostrs_from_ks(ks) self.create['repomd'] = misc.get_metadata_from_repos(ksrepos, self.create['cachedir']) - kickstart.resolve_groups(self.create, self.create['repomd']) msger.raw(" DONE") + target_archlist = misc.get_arch(self.create['repomd']) + if self.create['arch']: + if self.create['arch'] not in target_archlist: + raise errors.ConfigError("Invalid arch %s for repository. Valid arches: %s"\ + % (self.create['arch'], ', '.join(target_archlist))) + else: + if len(target_archlist) == 1: + self.create['arch'] = str(target_archlist[0]) + msger.info("\nUse detected arch %s." % target_archlist[0]) + else: + raise errors.ConfigError("Please specify a valid arch, "\ + "your choise can be: " % ', '.join(target_archlist)) + + kickstart.resolve_groups(self.create, self.create['repomd']) + def getConfigMgr(): return configmgr diff --git a/mic/utils/misc.py b/mic/utils/misc.py index 4477fd7..4b40db6 100644 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -320,6 +320,49 @@ def get_metadata_from_repos(repostrs, cachedir): return my_repo_metadata +def get_arch(repometadata): + archlist = [] + for repo in repometadata: + if repo["primary"].endswith(".xml"): + root = xmlparse(repo["primary"]) + ns = root.getroot().tag + ns = ns[0:ns.rindex("}")+1] + for elm in root.getiterator("%spackage" % ns): + if elm.find("%sarch" % ns).text not in ("noarch", "src"): + arch = elm.find("%sarch" % ns).text + if arch not in archlist: + archlist.append(arch) + elif repo["primary"].endswith(".sqlite"): + con = sqlite.connect(repo["primary"]) + for row in con.execute("select arch from packages where arch not in (\"src\", \"noarch\")"): + if row[0] not in archlist: + archlist.append(row[0]) + + con.close() + + uniq_arch = [] + for i in range(len(archlist)): + if archlist[i] not in rpmmisc.archPolicies.keys(): + continue + need_append = True + j = 0 + while j < len(uniq_arch): + if archlist[i] in rpmmisc.archPolicies[uniq_arch[j]].split(':'): + need_append = False + break + if uniq_arch[j] in rpmmisc.archPolicies[archlist[i]].split(':'): + if need_append: + uniq_arch[j] = archlist[i] + need_append = False + else: + uniq_arch.remove(uniq_arch[j]) + continue + j += 1 + if need_append: + uniq_arch.append(archlist[i]) + + return uniq_arch + def get_package(pkg, repometadata, arch = None): ver = "" target_repo = None -- 2.7.4