Commit 00e406b5 authored by dianders@chromium.org's avatar dianders@chromium.org

Update chromite to match the changes in chromiumos's git server.

Review URL: http://codereview.chromium.org/6286160

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@74182 0039d316-1c4b-4281-b951-d872f2087c98
parent 07ab60e2
...@@ -20,58 +20,55 @@ here: ...@@ -20,58 +20,55 @@ here:
http://git.chromium.org/gitweb/?p=chromite.git;a=blob;f=bin/chromite http://git.chromium.org/gitweb/?p=chromite.git;a=blob;f=bin/chromite
Since this script is _copied_, it should remain small and not use internal libs. Since this script is _copied_, it should remain small and not use internal libs.
""" """
# Python imports. # Python imports.
import os import os
import sys import sys
if __name__ == '__main__': def Search(path):
# Look relative to CROS_WORKON_SRCROOT if that variable exists. This is """Return an iterator of lists of places to look for chromite."""
# the "inside the chroot" case.
if 'CROS_WORKON_SRCROOT' in os.environ:
chromite_path = os.path.join(os.environ['CROS_WORKON_SRCROOT'],
'chromite', 'shell', 'main.py')
if os.path.isfile(chromite_path):
# Exec the script, which will never return.
os.execv(chromite_path, sys.argv)
else:
print (
"ERROR: Couldn't find the chromite tool.\n"
"\n"
"You may need to update your chroot. If you need help, see:\n"
" http://www.chromium.org/chromium-os/developer-guide"
)
sys.exit(1)
# Outside the chroot, search upward until the "parent" dir doesn't change if os.path.exists('/etc/debian_chroot'):
# (on Linux, that means we're at '/'). That is an error case. # We're in the chroot. Chromite should be in the python path inside the
dir = os.getcwd() # chroot, so we don't do any searching. NOTE that we purposely don't want
prev_dir = None # CROS_WORKON_SRCROOT in the python path.
while dir != prev_dir: yield []
chromite_path = os.path.join(dir, 'chromite', 'shell', 'main.py') else:
if os.path.isfile(chromite_path): # Look in $CROS_WORKON_SRCROOT first. The idea is that a user would set
# Add the directory above chromite to PYTHONPATH before executing, so # this manually if they wanted to specify a particular version of chromite.
# that "import chromite.abc.xyz" works... if 'CROS_WORKON_SRCROOT' in os.environ:
env = os.environ.copy() yield [os.environ['CROS_WORKON_SRCROOT']]
if 'PYTHONPATH' in env:
env['PYTHONPATH'] += ':%s' % dir
else:
env['PYTHONPATH'] = dir
# Exec the script, which will never return. # Search upward until we either end up with a blank dir or the "parent" dir
os.execve(chromite_path, sys.argv, env) # doesn't change.
prev_path = None
while path and path != prev_path:
yield [path]
path, prev_path = os.path.dirname(path), path
prev_dir = dir
dir = os.path.dirname(dir)
for path in Search(os.getcwd()):
sys.path = path + sys.path
try:
import chromite.shell.main
break
except ImportError, e:
# We've got different modules named chromite in the tree, pulling in the
# wrong one will break the right one. So unload it.
if 'chromite' in sys.modules:
del sys.modules['chromite']
sys.path = sys.path[len(path):]
else:
# TODO(dianders): Should we actually print out the 'repo init' call that # TODO(dianders): Should we actually print out the 'repo init' call that
# the user should use? # the user should use?
print ( sys.stderr.write(
"ERROR: Couldn't find the chromite tool.\n" "ERROR: Couldn't find the chromite tool.\n"
"\n" "\n"
"Please change to a directory inside your Chromium OS source tree\n" "Please change to a directory inside your Chromium OS source tree\n"
"and retry. If you need to setup a Chromium OS source tree, see:\n" "and retry. If you need to setup a Chromium OS source tree, see:\n"
" http://www.chromium.org/chromium-os/developer-guide" " http://www.chromium.org/chromium-os/developer-guide\n")
)
sys.exit(1) sys.exit(1)
chromite.shell.main.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment