Make the homedir check a bit simpler.

Rather than using split, we can just use os.path.basename(path) to get
the username from the homedir name. This is a bit simpler.

I've also added a comment which I missed in my last commit.

TEST=Ran ./parallel_emerge, verified the new method of getting
PORTAGE_USERNAME gets the right username.
BUG=none

Review URL: http://codereview.chromium.org/3056002
This commit is contained in:
David James 2010-08-02 21:21:17 -07:00
parent f968285d63
commit 98c52bdea2

View File

@ -60,9 +60,9 @@ import urllib2
# encounter this case unless they have an old chroot or blow away the # encounter this case unless they have an old chroot or blow away the
# environment by running sudo without the -E specifier. # environment by running sudo without the -E specifier.
if "PORTAGE_USERNAME" not in os.environ: if "PORTAGE_USERNAME" not in os.environ:
homedir = os.environ["HOME"] homedir = os.environ.get("HOME")
if homedir.startswith("/home/"): if homedir:
os.environ["PORTAGE_USERNAME"] = homedir.split("/")[2] os.environ["PORTAGE_USERNAME"] = os.path.basename(homedir)
# Portage doesn't expose dependency trees in its public API, so we have to # Portage doesn't expose dependency trees in its public API, so we have to
# make use of some private APIs here. These modules are found under # make use of some private APIs here. These modules are found under
@ -1050,6 +1050,8 @@ def EmergeWorker(task_queue, done_queue, emerge, package_db):
opts, spinner = emerge.opts, emerge.spinner opts, spinner = emerge.opts, emerge.spinner
opts["--nodeps"] = True opts["--nodeps"] = True
while True: while True:
# Wait for a new item to show up on the queue. This is a blocking wait,
# so if there's nothing to do, we just sit here.
target = task_queue.get() target = task_queue.get()
print "Emerging", target print "Emerging", target
db_pkg = package_db[target] db_pkg = package_db[target]