summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-06-25 02:07:11 +0000
committerZac Medico <zmedico@gentoo.org>2007-06-25 02:07:11 +0000
commitf34afe9802e1b68e53a2e1084e16d9ec5693c05b (patch)
tree9b7b445ea887527fa0e58cedbd6f3d585cd9e1ec
parent4146e3875105fb4dae02f279395aac94a1fa838a (diff)
downloadportage-f34afe9802e1b68e53a2e1084e16d9ec5693c05b.tar.gz
portage-f34afe9802e1b68e53a2e1084e16d9ec5693c05b.tar.bz2
portage-f34afe9802e1b68e53a2e1084e16d9ec5693c05b.zip
Clean up file_get() to use shlex, varexpand, and spawn.
svn path=/main/trunk/; revision=7014
-rw-r--r--pym/portage/getbinpkg.py35
1 files changed, 13 insertions, 22 deletions
diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py
index 808eb64f9..f1131c2d6 100644
--- a/pym/portage/getbinpkg.py
+++ b/pym/portage/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.process 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