| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Wapper for the chromite shell. | 6 """Wrapper for the chromite shell. |
| 7 | 7 |
| 8 This script is intended to run in several ways: | 8 This script is intended to run in several ways: |
| 9 - Outside the chroot, it should be _copied_ to someplace that is in the | 9 - Outside the chroot, it should be _copied_ to someplace that is in the |
| 10 path (like depot_tools). It will search for the right chromite by looking | 10 path (like depot_tools). It will search for the right chromite by looking |
| 11 for a file 'chromite/shell/main.py' upward based on the CWD. | 11 for a file 'chromite/shell/main.py' upward based on the CWD. |
| 12 - Inside the chroot, it might be _either_ copied to someplace in the path (since | 12 - Inside the chroot, it might be _either_ copied to someplace in the path (since |
| 13 depot_tools is in the path in the chroot) or it might run from chromite/bin | 13 depot_tools is in the path in the chroot) or it might run from chromite/bin |
| 14 directly, which should be in the PATH. In any case, we'll look for the | 14 directly, which should be in the PATH. In any case, we'll look for the |
| 15 real 'chromite/shell/main.py' based on the environment variable | 15 real 'chromite/shell/main.py' based on the environment variable |
| 16 CROS_WORKON_SRCROOT, so it doesn't matter what the CWD is. | 16 CROS_WORKON_SRCROOT, so it doesn't matter what the CWD is. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 # Outside the chroot, search upward until we either end up with a blank dir | 41 # Outside the chroot, search upward until we either end up with a blank dir |
| 42 # or the "parent" dir doesn't change. Either of those is an error case. | 42 # or the "parent" dir doesn't change. Either of those is an error case. |
| 43 dir = os.getcwd() | 43 dir = os.getcwd() |
| 44 prev_dir = None | 44 prev_dir = None |
| 45 while dir and dir != prev_dir: | 45 while dir and dir != prev_dir: |
| 46 chromite_path = os.path.join(dir, 'chromite', 'shell', 'main.py') | 46 chromite_path = os.path.join(dir, 'chromite', 'shell', 'main.py') |
| 47 if os.path.isfile(chromite_path): | 47 if os.path.isfile(chromite_path): |
| 48 # Add the directory above chromite to PYTHONPATH before executing, so | 48 # Add the directory above chromite to PYTHONPATH before executing, so |
| 49 # that "import chromite.abc.xyz" works... | 49 # that "import chromite.abc.xyz" works... |
| 50 env = dict(os.environ) | 50 env = os.environ.copy() |
| 51 if 'PYTHONPATH' in env: | 51 if 'PYTHONPATH' in env: |
| 52 env['PYTHONPATH'] = "%s:%s" % (env['PYTHONPATH'], dir) | 52 env['PYTHONPATH'] += ':%s' % dir |
| 53 else: | 53 else: |
| 54 env['PYTHONPATH'] = dir | 54 env['PYTHONPATH'] = dir |
| 55 | 55 |
| 56 # Exec the script, which will never return; note that python will | 56 # Exec the script, which will never return; note that python will |
| 57 # replace argv[0] with chromite_path when called, so we'll lose | 57 # replace argv[0] with chromite_path when called, so we'll lose |
| 58 # the name of / path to this wrapper. | 58 # the name of / path to this wrapper. |
| 59 os.execve(chromite_path, sys.argv, env) | 59 os.execve(chromite_path, sys.argv, env) |
| 60 | 60 |
| 61 prev_dir = dir | 61 prev_dir = dir |
| 62 dir = os.path.dirname(dir) | 62 dir = os.path.dirname(dir) |
| 63 | 63 |
| 64 # TODO(dianders): Should we actually print out the 'repo init' call that | 64 # TODO(dianders): Should we actually print out the 'repo init' call that |
| 65 # the user should use? | 65 # the user should use? |
| 66 print ( | 66 print ( |
| 67 "ERROR: Couldn't find the chromite tool.\n" | 67 "ERROR: Couldn't find the chromite tool.\n" |
| 68 "\n" | 68 "\n" |
| 69 "Please change to a directory inside your Chromium OS source tree\n" | 69 "Please change to a directory inside your Chromium OS source tree\n" |
| 70 "and retry. If you need to setup a Chromium OS source tree, see:\n" | 70 "and retry. If you need to setup a Chromium OS source tree, see:\n" |
| 71 " http://www.chromium.org/chromium-os/developer-guide" | 71 " http://www.chromium.org/chromium-os/developer-guide" |
| 72 ) | 72 ) |
| OLD | NEW |