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:
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.
"""
# Python imports.
import os
import sys
if __name__ == '__main__':
# Look relative to CROS_WORKON_SRCROOT if that variable exists. This is
# 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)
def Search(path):
"""Return an iterator of lists of places to look for chromite."""
# Outside the chroot, search upward until the "parent" dir doesn't change
# (on Linux, that means we're at '/'). That is an error case.
dir = os.getcwd()
prev_dir = None
while dir != prev_dir:
chromite_path = os.path.join(dir, 'chromite', 'shell', 'main.py')
if os.path.isfile(chromite_path):
# Add the directory above chromite to PYTHONPATH before executing, so
# that "import chromite.abc.xyz" works...
env = os.environ.copy()
if 'PYTHONPATH' in env:
env['PYTHONPATH'] += ':%s' % dir
else:
env['PYTHONPATH'] = dir
if os.path.exists('/etc/debian_chroot'):
# We're in the chroot. Chromite should be in the python path inside the
# chroot, so we don't do any searching. NOTE that we purposely don't want
# CROS_WORKON_SRCROOT in the python path.
yield []
else:
# Look in $CROS_WORKON_SRCROOT first. The idea is that a user would set
# this manually if they wanted to specify a particular version of chromite.
if 'CROS_WORKON_SRCROOT' in os.environ:
yield [os.environ['CROS_WORKON_SRCROOT']]
# Exec the script, which will never return.
os.execve(chromite_path, sys.argv, env)
# Search upward until we either end up with a blank dir or the "parent" dir
# 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
# the user should use?
print (
sys.stderr.write(
"ERROR: Couldn't find the chromite tool.\n"
"\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"
" http://www.chromium.org/chromium-os/developer-guide"
)
" http://www.chromium.org/chromium-os/developer-guide\n")
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