Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Unified Diff: bin/chromite

Issue 6334039: chromite: Switch from execve to import. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/chromite.git@master
Patch Set: Remove try: tower. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/chromite
diff --git a/bin/chromite b/bin/chromite
index 4e9e49fc5d67046e5d93c09119cc2b9400a46422..772520a139a48256846906f81acfd7e886756c9f 100755
--- a/bin/chromite
+++ b/bin/chromite
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -20,58 +20,45 @@ 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 places to look for chromite."""
diandersAtChromium 2011/02/03 00:44:22 Please make it so that if chromite is already in t
Kenneth Waters 2011/02/03 18:16:41 jrbarnette wanted it this way.
diandersAtChromium 2011/02/03 18:36:01 Talked to jrbarnette. You can push this CL as is.
- # 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
+ # Look in $CROS_WORKON_SRCROOT first.
+ yield os.environ.get('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)
+sys.path.insert(0, '')
diandersAtChromium 2011/02/03 00:44:22 Please don't add ever '' into the path. This make
Kenneth Waters 2011/02/03 18:16:41 I was partially confused by by what interactive py
+for path in Search(os.getcwd()):
+ sys.path[0] = path
+ try:
+ import chromite.shell.main
+ break
+ except ImportError:
+ pass
+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()
+sys.exit(0)
diandersAtChromium 2011/02/03 00:44:22 Can we remove this sys.exit(0)? ...if not, can yo
Kenneth Waters 2011/02/03 18:16:41 legacy. removed.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698