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

Unified Diff: mojo/devtools/common/devtoolslib/shell_config.py

Issue 1268403002: Automatically discover the mojoconfig file. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 4 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 | « mojo/devtools/common/devtoolslib/shell_arguments.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/devtools/common/devtoolslib/shell_config.py
diff --git a/mojo/devtools/common/devtoolslib/shell_config.py b/mojo/devtools/common/devtoolslib/shell_config.py
index 702be64d76da173cb3cba15049fbdda1c86e7f1a..b3ccad83a01cf4a3bd4592e466218901db177961 100644
--- a/mojo/devtools/common/devtoolslib/shell_config.py
+++ b/mojo/devtools/common/devtoolslib/shell_config.py
@@ -90,6 +90,9 @@ def add_shell_arguments(parser):
'file.')
config_file_group.add_argument('--config-file', type=file,
help='Path of the configuration file to use.')
+ config_file_group.add_argument('--no-config-file', action='store_true',
+ help='Pass to skip automatic discovery of the '
+ 'mojoconfig file.')
# Arguments allowing to indicate the build directory we are targeting when
# running within a Chromium-like checkout (e.g. Mojo checkout). These will go
@@ -109,6 +112,13 @@ def add_shell_arguments(parser):
choices=['x64', 'x86', 'arm'])
+def _discover_config_file():
+ config_file_path = paths.find_within_ancestors('mojoconfig')
+ if not config_file_path:
+ return None
+ return open(config_file_path)
+
+
def _read_config_file(config_file, aliases):
spec = config_file.read()
for alias_pattern, alias_value in aliases:
@@ -151,22 +161,28 @@ def get_shell_config(script_args):
shell_config.origin = inferred_paths['build_dir_path']
# Read the mojoconfig file.
- if script_args.config_file:
+ config_file = script_args.config_file
+ if not script_args.no_config_file:
+ config_file = config_file or _discover_config_file()
+
+ if config_file:
qsr 2015/08/05 11:50:59 Can you use: with config_file: inside the if (to n
ppi 2015/08/05 11:55:44 Seems to be working fine, done.
config_file_aliases = []
if inferred_paths['build_dir_path']:
config_file_aliases.append(('@{BUILD_DIR}',
inferred_paths['build_dir_path']))
- mojoconfig = None
+ config = None
try:
- mojoconfig = _read_config_file(script_args.config_file,
- config_file_aliases)
+ if script_args.verbose:
+ print 'Reading config file from: ' + config_file.name
+ config = _read_config_file(config_file, config_file_aliases)
+ config_file.close()
except SyntaxError:
raise ShellConfigurationException('Failed to parse the mojoconfig file.')
- if 'dev_servers' in mojoconfig:
+ if 'dev_servers' in config:
try:
- for dev_server_spec in mojoconfig['dev_servers']:
+ for dev_server_spec in config['dev_servers']:
dev_server_config = DevServerConfig()
dev_server_config.host = dev_server_spec['host']
dev_server_config.mappings = []
« no previous file with comments | « mojo/devtools/common/devtoolslib/shell_arguments.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698