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
This commit is contained in:
parent
929d86d7f0
commit
368da66a31
@ -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))
|
||||
|
@ -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),"
|
||||
|
Loading…
Reference in New Issue
Block a user