From 586867fbb86e0baecd7414fa6402e86af07fe28e Mon Sep 17 00:00:00 2001 From: hwangx Date: Fri, 13 Apr 2012 12:03:03 +0800 Subject: [PATCH] update parse_spec to support normal user --- gitbuildsys/utils.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gitbuildsys/utils.py b/gitbuildsys/utils.py index eb1f439..9e64c3f 100644 --- a/gitbuildsys/utils.py +++ b/gitbuildsys/utils.py @@ -21,6 +21,7 @@ import os import glob import platform import re +import tempfile import msger import runner @@ -101,15 +102,16 @@ def parse_spec(spec_path, macro): if which(rpmb_cmd): # rpmbuild has been installed in system, use it + tmp_dir = tempfile.mkdtemp(dir='/tmp/') rpmb_cmdline = ("%s -bp --nodeps --force " - "tmp.spec --define '_topdir .' " - "--define '_builddir .' " - "--define '_sourcedir .' " - "--define '_rpmdir .' " - "--define '_specdir .' " - "--define '_srcrpmdir .'") % rpmb_cmd - - wf = open('tmp.spec', 'w') + "%s/tmp.spec --define '_topdir %s' " + "--define '_builddir %s' " + "--define '_sourcedir %s' " + "--define '_rpmdir %s' " + "--define '_specdir %s' " + "--define '_srcrpmdir %s'") % (rpmb_cmd, tmp_dir, tmp_dir, tmp_dir, tmp_dir, tmp_dir, tmp_dir, tmp_dir) + + wf = open(os.path.join(tmp_dir, 'tmp.spec'), 'w') with file(spec_path) as f: for line in f: if line.startswith('%prep'): @@ -120,11 +122,9 @@ def parse_spec(spec_path, macro): outs = runner.outs(rpmb_cmdline, catch=3) # clean up - os.unlink('tmp.spec') - if os.path.isdir('BUILDROOT'): + if os.path.exists(tmp_dir): import shutil - shutil.rmtree('BUILDROOT', ignore_errors=True) - + shutil.rmtree(tmp_dir, ignore_errors=True) for line in outs.splitlines(): if line.startswith('+ echo '): return line[7:].rstrip() -- 2.7.4