Yet another color updates. This time before welcome happens print should be used and not logging.

This commit is contained in:
Joshua Harlow 2012-01-26 00:34:20 -08:00
parent 31e2e5b112
commit 017b47cfc6
5 changed files with 32 additions and 33 deletions

View File

@ -13,6 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
#requires http://pypi.python.org/pypi/termcolor
#but the colors make it worth it :-)
from termcolor import colored, cprint
from devstack import cfg
from devstack import date
from devstack import exceptions as excp
@ -144,8 +148,8 @@ def _check_root(action, rootdir):
if sh.isdir(rootdir):
dir_list = sh.listdir(rootdir)
if len(dir_list) > 0:
LOG.error("Root directory [%s] already exists (and it's not empty)! "\
"Please remove it or uninstall components!" % (rootdir))
cprint("Root directory [%s] already exists (and it's not empty)! "\
"Please remove it or uninstall components!" % (rootdir), "red")
return False
return True
@ -326,23 +330,25 @@ def _run_components(action_name, component_order, components, distro, root_dir,
def _run_action(args):
components = settings.parse_components(args.pop("components"))
if not components:
LOG.error("No components specified!")
cprint("No components specified!", "red")
return False
action = _clean_action(args.pop("action"))
if not action:
LOG.error("No valid action specified!")
cprint("No valid action specified!", "red")
return False
rootdir = args.pop("dir")
if not _check_root(action, rootdir):
LOG.error("No valid root directory specified!")
cprint("No valid root directory specified!", "red")
return False
#ensure os/distro is known
(distro, platform) = utils.determine_distro()
if distro is None:
LOG.error("Unsupported platform: %s" % (platform))
print("Unsupported platform " + colored(platform, "red") + "!")
return False
#start it
utils.welcome(_WELCOME_MAP.get(action))
(rep, maxlen) = utils.welcome(_WELCOME_MAP.get(action))
header = utils.center_text("Action Runner", rep, maxlen)
print(header)
#need to figure out dependencies for components (if any)
ignore_deps = args.pop('ignore_deps', False)
if not ignore_deps:

View File

@ -19,7 +19,6 @@ import re
#but the colors make it worth it :-)
from termcolor import colored, cprint
from devstack import log as logging
from devstack import settings
from devstack import utils
@ -36,7 +35,6 @@ from devstack.components import quantum
from devstack.components import rabbit
from devstack.components import swift
LOG = logging.getLogger("devstack.progs.misc")
PROG_NAME = "MISC"
_DESCR_MAP = {
@ -82,17 +80,19 @@ def _run_describe_comps(args):
components = settings.parse_components(args.get("components"), True)
c_keys = sorted(components.keys())
for c in c_keys:
print(colored(c, "green", attrs=['bold']) + " description:")
print("Name: " + colored(c, "green", attrs=['bold']) + "")
describer = _DESCR_MAP.get(c)
print(describer(components.get(c)))
def run(args):
sep = utils.welcome(PROG_NAME)
(rep, maxlen) = utils.welcome(PROG_NAME)
if args.get('list_deps'):
header = utils.center_text("Dependencies", rep, maxlen)
print(header)
_run_list_deps(args)
print(sep)
if args.get('describe_comp'):
header = utils.center_text("Descriptions", rep, maxlen)
print(header)
_run_describe_comps(args)
print(sep)
return True

View File

@ -276,9 +276,7 @@ def parse_components(components, assume_all=False):
mtch = EXT_COMPONENT.match(c)
if mtch:
component_name = mtch.group(1).lower().strip()
if component_name not in COMPONENT_NAMES:
LOG.warn("Unknown component named %s" % (component_name))
else:
if component_name in COMPONENT_NAMES:
component_opts = mtch.group(2)
components_opts_cleaned = list()
if not component_opts:
@ -290,8 +288,6 @@ def parse_components(components, assume_all=False):
if cleaned_opt:
components_opts_cleaned.append(cleaned_opt)
adjusted_components[component_name] = components_opts_cleaned
else:
LOG.warn("Unparseable component %s" % (c))
#should we adjust them to be all the components?
if not adjusted_components and assume_all:
all_components = dict()

View File

@ -301,6 +301,4 @@ def welcome(ident):
centered_str = center_text(uncolored_footer, " ", max_line_len)
footer = centered_str.replace(uncolored_footer, footer)
print((welcome_header + os.linesep + footer))
tail_end = "-" * max_line_len
print(tail_end)
return tail_end
return ("-", max_line_len)

23
stack
View File

@ -19,13 +19,15 @@ import logging
import logging.config
import sys
#requires http://pypi.python.org/pypi/termcolor
#but the colors make it worth it :-)
from termcolor import colored, cprint
#this needs to happen immediately (or thats what it seems)
def setupLogging():
logfn = os.getenv('LOG_FILE')
if(logfn == None):
logfn = os.path.join("conf", 'logging.ini')
logging.config.fileConfig(logfn)
setupLogging()
logfn = os.getenv('LOG_FILE')
if(logfn == None):
logfn = os.path.join("conf", 'logging.ini')
logging.config.fileConfig(logfn)
#this handles our option parsing
from devstack import opts
@ -34,26 +36,23 @@ from devstack import opts
from devstack.progs import actions
from devstack.progs import misc
LOG = logging.getLogger("devstack")
def main():
#parse and get it done!
args = opts.parse()
run_ok = False
#figure out what to do
if args.get('list_deps') or args.get('describe_comp'):
run_ok = misc.run(args)
else:
run_ok = actions.run(args)
#now do it
if run_ok:
return 0
else:
LOG.info("Perhaps you should try %s --help" % (os.path.basename(sys.argv[0])))
me = colored((os.path.basename(sys.argv[0])), "red", attrs=['bold'])
me += " " + colored('--help', 'red')
print("Perhaps you should try %s" % (me))
return 1