summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-02-18 15:51:50 +0900
committerGitLab <gitlab@gitlab.com>2017-02-18 17:13:45 +0000
commit374386d081c0cc10649962b4939573037a774170 (patch)
tree736e1eab52f6917590aa3a7aa32c39b280c468e1
parent2cad7d3a0b104a98f17a3f596adbcf6b488ce492 (diff)
downloadybd-tristan/mode-option.tar.gz
Added -m/--mode command line argument.tristan/mode-option
If specified, the mode argument will override whatever mode was loaded in the YBD installation configuration. This is especially useful when you have one YBD installation that you use accomplish multiple tasks, you may want to just create a manifest and then later build; without having to modify a configuration file.
-rwxr-xr-xybd/__main__.py12
-rw-r--r--ybd/app.py24
-rw-r--r--ybd/pots.py7
3 files changed, 28 insertions, 15 deletions
diff --git a/ybd/__main__.py b/ybd/__main__.py
index 15688fa..272eb6e 100755
--- a/ybd/__main__.py
+++ b/ybd/__main__.py
@@ -30,6 +30,7 @@ import cache
from release_note import do_release_note
import sandbox
import sandboxlib
+import argparse
import yaml
@@ -51,7 +52,16 @@ if not os.path.exists('./VERSION'):
if os.path.isdir(os.path.join(os.getcwd(), '..', 'definitions')):
os.chdir(os.path.join(os.getcwd(), '..', 'definitions'))
-setup(sys.argv, original_cwd)
+description = 'Build and manipulate YAML build definitions'
+parser = argparse.ArgumentParser(description=description)
+parser.add_argument('-m', '--mode', type=str, default=None,
+ choices=['parse-only', 'keys-only', 'no-build', 'normal'],
+ help='Operation mode')
+parser.add_argument('target', help='The target definition')
+parser.add_argument('arch', help='The target architecture')
+args = parser.parse_args()
+
+setup(sys.argv[0], args.target, args.arch, args.mode, original_cwd)
cleanup(config['tmp'])
with timer('TOTAL'):
diff --git a/ybd/app.py b/ybd/app.py
index 3000847..d106d60 100644
--- a/ybd/app.py
+++ b/ybd/app.py
@@ -128,20 +128,17 @@ def warning_handler(message, category, filename, lineno, file=None, line=None):
return 'WARNING: %s\n' % (message)
-def setup(args, original_cwd=""):
+def setup(program, target, arch, mode, original_cwd=""):
os.environ['LANG'] = 'en_US.UTF-8'
config['start-time'] = datetime.datetime.now()
- config['program'] = os.path.basename(args[0])
+ config['program'] = os.path.basename(program)
config['my-version'] = get_version(os.path.dirname(__file__))
log('SETUP', '%s version is' % config['program'], config['my-version'])
- if len(args) != 3:
- sys.stdout.write("\nUsage: %s DEFINITION_FILE ARCH\n\n" % sys.argv[0])
- sys.exit(1)
-
- log('SETUP', 'Running %s in' % args[0], os.getcwd())
- config['arg'] = args[1]
- config['target'] = os.path.basename(os.path.splitext(args[1])[0])
- config['arch'] = args[2]
+
+ log('SETUP', 'Running %s in' % program, os.getcwd())
+ config['filename'] = os.path.basename(target)
+ config['target'] = os.path.basename(os.path.splitext(target)[0])
+ config['arch'] = arch
config['sandboxes'] = []
config['overlaps'] = []
config['new-overlaps'] = []
@@ -164,8 +161,13 @@ def setup(args, original_cwd=""):
os.path.join(os.path.dirname(__file__), '..', 'ybd.conf'),
os.path.join(os.path.dirname(__file__), 'config', 'ybd.conf')])
+ # After loading configuration, override the 'mode' configuration only
+ # if it was specified on the command line
+ if mode is not None:
+ config['mode'] = mode
+
if not os.geteuid() == 0 and config.get('mode') == 'normal':
- log('SETUP', '%s needs root permissions' % sys.argv[0], exit=True)
+ log('SETUP', '%s needs root permissions' % program, exit=True)
if config.get('kbas-url', 'http://foo.bar/') == 'http://foo.bar/':
config.pop('kbas-url')
diff --git a/ybd/pots.py b/ybd/pots.py
index c2dc6d6..ec11d94 100644
--- a/ybd/pots.py
+++ b/ybd/pots.py
@@ -34,9 +34,10 @@ class ExplicitDumper(yaml.SafeDumper):
class Pots(object):
def __init__(self, directory='.'):
- if config['arg'].endswith('yml'):
- log('DEFINITIONS', 'Loading all definitions from', config['arg'])
- self._data = self._load_pots(config['arg'])
+ if config['filename'].endswith('yml'):
+ log('DEFINITIONS', 'Loading all definitions from',
+ config['filename'])
+ self._data = self._load_pots(config['filename'])
else:
log('DEFINITIONS', 'Loading definitions from morph files')
self._data = Morphs()._data