From f1ca0e56fa470a03d655d82c90e87a9953af42c3 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 25 Jun 2007 02:11:43 +0000 Subject: [PATCH] Clean up file_get() to use shlex, varexpand, and spawn. (trunk r7014) svn path=/main/branches/2.1.2/; revision=7015 --- pym/getbinpkg.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/pym/getbinpkg.py b/pym/getbinpkg.py index a506f4a13..c3bd0b5ee 100644 --- a/pym/getbinpkg.py +++ b/pym/getbinpkg.py @@ -366,28 +366,19 @@ def file_get(baseurl,dest,conn=None,fcmd=None): if not fcmd: return file_get_lib(baseurl,dest,conn) - fcmd = fcmd.replace("${DISTDIR}",dest) - fcmd = fcmd.replace("${URI}", baseurl) - fcmd = fcmd.replace("${FILE}", os.path.basename(baseurl)) - mysplit = fcmd.split() - mycmd = mysplit[0] - myargs = [os.path.basename(mycmd)]+mysplit[1:] - mypid=os.fork() - if mypid == 0: - try: - os.execv(mycmd,myargs) - except OSError: - pass - sys.stderr.write("!!! Failed to spawn fetcher.\n") - sys.stderr.flush() - os._exit(1) - retval=os.waitpid(mypid,0)[1] - if (retval & 0xff) == 0: - retval = retval >> 8 - else: - sys.stderr.write("Spawned processes caught a signal.\n") - sys.exit(1) - if retval != 0: + variables = { + "DISTDIR": dest, + "URI": baseurl, + "FILE": os.path.basename(baseurl) + } + import shlex, StringIO + from portage_util import varexpand + from portage_exec import spawn + lexer = shlex.shlex(StringIO.StringIO(fcmd), posix=True) + lexer.whitespace_split = True + myfetch = [varexpand(x, mydict=variables) for x in lexer] + retval = spawn(myfetch, env=os.environ.copy()) + if retval != os.EX_OK: sys.stderr.write("Fetcher exited with a failure condition.\n") return 0 return 1 -- 2.26.2