From 368da66a317e0804902425d37696a236b3a9e8e1 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 11 Aug 2013 14:05:20 -0700 Subject: [PATCH] Specify the default root dir in opts. Instead of adjusting the default after the options have been parsed its better to just specify the default before opts are even started to be parsed in the first place. Change-Id: I7c23cbfdaa4c70a6662740072791bf98285a40e2 --- anvil/__main__.py | 12 ++---------- anvil/opts.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/anvil/__main__.py b/anvil/__main__.py index 41b7097b..e8990a94 100644 --- a/anvil/__main__.py +++ b/anvil/__main__.py @@ -28,7 +28,6 @@ sys.path.insert(0, os.path.abspath(os.getcwd())) from anvil import actions from anvil import colorizer from anvil import distro -from anvil import env from anvil import exceptions as excp from anvil import log as logging from anvil import opts @@ -69,15 +68,8 @@ def run(args): if not sh.isfile(persona_fn): raise excp.OptionException("Invalid persona file %r specified!" % (persona_fn)) - # Determine + setup the root directory... - # If not provided attempt to locate it via the environment control files - args_root_dir = args.pop("dir") - root_dir = env.get_key('INSTALL_ROOT') - if not root_dir: - root_dir = args_root_dir - if not root_dir: - root_dir = sh.joinpths(sh.gethomedir(), 'openstack') - root_dir = sh.abspth(root_dir) + # Determine the root directory... + root_dir = sh.abspth(args.pop("dir")) (repeat_string, line_max_len) = utils.welcome() print(pprint.center_text("Action Runner", repeat_string, line_max_len)) diff --git a/anvil/opts.py b/anvil/opts.py index 65b3a108..28948694 100644 --- a/anvil/opts.py +++ b/anvil/opts.py @@ -25,6 +25,7 @@ from optparse import OptionParser from optparse import OptionValueError from anvil import actions +from anvil import env from anvil import settings from anvil import shell as sh from anvil import utils @@ -100,6 +101,13 @@ class SmithyHelpFormatter(IndentedHelpFormatter): return buf.getvalue() +def _get_default_dir(): + root_dir = env.get_key('INSTALL_ROOT') + if root_dir: + return root_dir + return sh.joinpths(sh.gethomedir(), 'openstack') + + def parse(previous_settings=None): version_str = "%s v%s" % ('anvil', version.version_string()) @@ -167,7 +175,8 @@ def parse(previous_settings=None): type="string", dest="dir", metavar="DIR", - help=("empty root DIR or DIR with existing components")) + default=_get_default_dir(), + help=("empty root DIR or DIR with existing components (default: %default)")) parser.add_option_group(base_group) suffixes = ("Known suffixes 'K' (kilobyte, 1024),"