From c272dcc076d5f4d777ffaca820c7f3a4c4731e24 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Fri, 3 Oct 2008 15:46:01 -1000 Subject: [PATCH] Write getBuildArch() function and correct mkstemp calls. Add the getBuildArch() function which does what this was doing in buildinstall: repoquery -c CONF --qf "%{ARCH}\n" anaconda Also fixed the mkstemp() usage. --- pylorax/__init__.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/pylorax/__init__.py b/pylorax/__init__.py index 8f6e57bc..5bb99a03 100644 --- a/pylorax/__init__.py +++ b/pylorax/__init__.py @@ -106,7 +106,7 @@ def writeYumConf(cachedir=None, repo=None, extrarepos=[], mirrorlist=[]): return None tmpdir = tempfile.gettempdir() - (f, yumconf) = tempfile.mkstemp('XXXXXX', 'yum.conf', tmpdir) + (f, yumconf) = tempfile.mkstemp(prefix='yum.conf', dir=tmpdir) f.write("[main]\n") f.write("cachedir=%s\n" % (cachedir,)) @@ -141,6 +141,48 @@ def writeYumConf(cachedir=None, repo=None, extrarepos=[], mirrorlist=[]): f.close() return yumconf +def getBuildArch(yumconf=None): + """getBuildArch(yumconf=None) + + Query the configured yum repositories to determine our build architecture, + which is the architecture of the anaconda package in the repositories. + + The required argument is yumconf, which is the path to the yum configuration + file to use. + + This function is based on a subset of what repoquery(1) does. + + """ + + uname_arch = os.uname()[4] + + if yumconf == '' or yumconf is None or not os.path.isfile(yumconf): + return uname_arch + + repoq = yum.YumBase() + repoq.doConfigSetup() + + try: + repoq.doRepoSetup() + except yum.Errors.RepoError, e: + sys.stderr.write("ERROR: could not query yum repository for build arch, defaulting to %s\n" % (uname_arch,)) + return uname_arch + + repoq.doSackSetup(rpmUtils.arch.getArchList()) + repoq.doTsSetup() + + ret_arch = None + for pkg in repoq.pkgSack.simplePkgList(): + (n, a, e, v, r) = pkg + if n == 'anaconda': + ret_arch = a + break + + if ret_arch is None: + ret_arch = uname_arch + + return ret_arch + def cleanup(trash=[]): """cleanup(trash)