Updated options with option groups and some other small cleanups.

This commit is contained in:
Joshua Harlow
2012-01-21 20:18:22 -08:00
parent 92df56947e
commit 05ddbd2681
3 changed files with 55 additions and 52 deletions

View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from optparse import OptionParser
from optparse import OptionParser, OptionGroup
from optparse import IndentedHelpFormatter
from devstack import constants
@@ -30,63 +30,62 @@ def parse():
help_formatter = IndentedHelpFormatter(width=HELP_WIDTH)
parser = OptionParser(version=version_str, formatter=help_formatter)
#non-boolean options
base_group = OptionGroup(parser, "Install/uninstall/start/stop options")
known_actions = sorted(constants.ACTIONS)
actions = "(" + ", ".join(known_actions) + ")"
parser.add_option("-a", "--action",
base_group.add_option("-a", "--action",
action="store",
type="string",
dest="action",
metavar="ACTION",
help="action to perform, ie %s" % (actions))
parser.add_option("-d", "--directory",
base_group.add_option("-d", "--directory",
action="store",
type="string",
dest="dir",
metavar="DIR",
help="root DIR for new components or "\
help="empty root DIR for install or "\
"DIR with existing components (ACTION dependent)")
known_components = sorted(constants.COMPONENT_NAMES)
components = "(" + ", ".join(known_components) + ")"
parser.add_option("-c", "--component",
base_group.add_option("-c", "--component",
action="append",
dest="component",
help="stack component, ie %s" % (components))
#boolean options
parser.add_option("-f", "--force",
action="store_true",
dest="force",
help="force ACTION even if no trace found (ACTION dependent)",
default=False)
parser.add_option("-i", "--ignoredeps",
action="store_true",
dest="ignore_deps",
help="ignore dependencies when performing ACTION")
parser.add_option("-e", "--ensuredeps",
help="openstack component, ie %s" % (components))
base_group.add_option("-i", "--ignore-deps",
action="store_false",
dest="ignore_deps",
help="ensure dependencies occur when performing ACTION (the default)",
default=False)
parser.add_option("-s", "--listdeps",
dest="ensure_deps",
help="ignore dependencies when performing ACTION")
base_group.add_option("-e", "--ensure-deps",
action="store_true",
dest="list_deps",
help="show dependencies of COMPONENT",
default=False)
parser.add_option("-r", "--refcomponent",
dest="ensure_deps",
help="ensure dependencies occur when performing ACTION (default: %default)",
default=True)
base_group.add_option("-r", "--ref-component",
action="append",
dest="r_component",
metavar="COMPONENT",
help="stack component which will not have ACTION applied but will be referenced as if it was (ACTION dependent)")
help="component which will not have ACTION applied but will be referenced as if it was (ACTION dependent)")
parser.add_option_group(base_group)
stop_un_group = OptionGroup(parser, "Uninstall/stop options")
stop_un_group.add_option("-f", "--force",
action="store_true",
dest="force",
help="force ACTION even if no trace found",
default=False)
parser.add_option_group(stop_un_group)
dep_group = OptionGroup(parser, "Dependency options")
dep_group.add_option("-s", "--list-deps",
action="store_true",
dest="list_deps",
help="show dependencies of COMPONENT (default: %default)",
default=False)
parser.add_option_group(dep_group)
(options, args) = parser.parse_args()
#extract only what we care about
output = dict()
output['components'] = options.component
@@ -95,6 +94,9 @@ def parse():
output['action'] = options.action
output['list_deps'] = options.list_deps
output['force'] = options.force
output['ignore_deps'] = options.ignore_deps
if(options.ensure_deps):
output['ignore_deps'] = False
else:
output['ignore_deps'] = True
output['extras'] = args
return output

View File

@@ -280,10 +280,15 @@ def param_replace(text, replacements, ignore_missing=False):
return PARAM_SUB_REGEX.sub(replacer, text)
def welcome(program_action):
formatted_action = constants.WELCOME_MAP.get(program_action, "")
def welcome(action):
formatted_action = constants.WELCOME_MAP.get(action, "")
ver_str = version.version_string()
lower = "!%s %s!" % (formatted_action.upper(), ver_str)
lower = "|"
if(formatted_action):
lower += formatted_action.upper()
lower += " "
lower += ver_str
lower += "|"
welcome = r'''
___ ____ _____ _ _ ____ _____ _ ____ _ __
/ _ \| _ \| ____| \ | / ___|_ _|/ \ / ___| |/ /
@@ -292,15 +297,11 @@ def welcome(program_action):
\___/|_| |_____|_| \_|____/ |_/_/ \_\____|_|\_\
'''
#this seems needed, weird...
welcome = " " + welcome.strip()
max_len = 0
for line in welcome.splitlines():
if(len(line) > max_len):
max_len = len(line)
welcome = welcome.strip("\n\r")
max_len = len(max(welcome.splitlines(), key=len))
lower_out = colored(constants.PROG_NICE_NAME, 'green') + \
": " + colored(lower, 'blue')
center_len = (max_len + max_len / 3)
": " + colored(lower, 'blue')
uncolored_lower_len = (len(constants.PROG_NICE_NAME + ": " + lower))
center_len = max_len + (max_len - uncolored_lower_len)
lower_out = string.center(lower_out, center_len)
msg = welcome + os.linesep + lower_out
print(msg)
print((welcome + os.linesep + lower_out))

6
stack
View File

@@ -158,10 +158,10 @@ def run_components(action_name, component_order, components_info, distro, root_d
for c in component_order:
klass = actions.get_action_cls(action_name, c)
component_opts = components_info.get(c, list())
instance = klass(components=set(active_components),
instance = klass(components=set(active_components),
distro=distro,
pkg=pkg_manager,
cfg=config,
pkg=pkg_manager,
cfg=config,
root=root_dir,
component_opts=component_opts)
if(action_name == constants.INSTALL):