From 950e958474fd86fec31c8f64e5a488abdb1afb59 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 2 Feb 2012 13:20:59 -0800 Subject: [PATCH] Moved util programs to utils... --- devstack/opts.py | 18 +---- run_checks.sh | 4 +- stack | 15 +--- devstack/progs/deps.py => utils/deps_list.py | 47 ++++++++++++ {devstack/progs => utils}/describe.py | 37 ++++++++++ utils/env_gen.py | 77 ++++++++++++++++++++ utils/extract_json.py | 3 +- 7 files changed, 168 insertions(+), 33 deletions(-) rename devstack/progs/deps.py => utils/deps_list.py (59%) rename {devstack/progs => utils}/describe.py (73%) create mode 100644 utils/env_gen.py diff --git a/devstack/opts.py b/devstack/opts.py index 9292d8c9..7633e5ce 100644 --- a/devstack/opts.py +++ b/devstack/opts.py @@ -83,29 +83,13 @@ def parse(): default=True) parser.add_option_group(stop_un_group) - misc_group = OptionGroup(parser, "Miscellaneous options") - misc_group.add_option("--list-deps", - action="store_true", - dest="list_deps", - help="show dependencies of COMPONENT (default: %default)", - default=False) - misc_group.add_option("--describe-components", - action="store_true", - dest="describe_comp", - help="describe COMPONENT (default: %default)", - default=False) - parser.add_option_group(misc_group) - - (options, args) = parser.parse_args() - #extract only what we care about + (options, args) = parser.parse_args() output = dict() output['components'] = options.component output['dir'] = options.dir output['ref_components'] = options.r_component output['action'] = options.action - output['list_deps'] = options.list_deps - output['describe_comp'] = options.describe_comp output['force'] = options.force if options.ensure_deps: output['ignore_deps'] = False diff --git a/run_checks.sh b/run_checks.sh index d84b1f59..01c36dc6 100755 --- a/run_checks.sh +++ b/run_checks.sh @@ -36,7 +36,7 @@ done function run_pep8 { echo "Running pep8 ..." - srcfiles=`find devstack -type f | grep "py\$"` + srcfiles=`find devstack utils -type f | grep "py\$"` srcfiles+=" stack" pep_ignores="E202,E501" tee_fn="pep8.log" @@ -53,7 +53,7 @@ function run_pep8 { function run_pylint { echo "Running pylint ..." - srcfiles=`find devstack -type f | grep "py\$"` + srcfiles=`find devstack utils -type f | grep "py\$"` srcfiles+=" stack" tee_fn="pylint.log" pylint_opts="--rcfile=$pylintrc_fn" diff --git a/stack b/stack index b5ecb343..f07b80b2 100755 --- a/stack +++ b/stack @@ -26,7 +26,7 @@ import traceback #this needs to happen immediately (or thats what it seems) log_fn = os.getenv('LOG_FILE') if(log_fn == None): - log_fn = os.path.join("conf", 'logging.ini') + log_fn = os.path.normpath(os.path.join("conf", 'logging.ini')) logging.config.fileConfig(log_fn) #this handles our option parsing @@ -35,23 +35,12 @@ from devstack import utils #these are the program runtimes that actually do the running from devstack.progs import actions -from devstack.progs import describe -from devstack.progs import deps def main(): - #parse and get it done! args = opts.parse() - #figure out what to do - module = None - if args.get('describe_comp'): - module = describe - elif args.get('list_deps'): - module = deps - else: - module = actions try: - ran_ok = module.run(args) + ran_ok = actions.run(args) if not ran_ok: me = utils.color_text((os.path.basename(sys.argv[0])), "red", True) me += " " + utils.color_text('--help', 'red') diff --git a/devstack/progs/deps.py b/utils/deps_list.py similarity index 59% rename from devstack/progs/deps.py rename to utils/deps_list.py index d9bcd279..77c1e525 100644 --- a/devstack/progs/deps.py +++ b/utils/deps_list.py @@ -14,6 +14,22 @@ # License for the specific language governing permissions and limitations # under the License. +import logging +import logging.config +import optparse +import os +import sys + +POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +sys.path.insert(0, POSSIBLE_TOPDIR) + +log_fn = os.getenv('LOG_FILE') +if(log_fn == None): + log_fn = os.path.normpath(os.path.join("conf", 'logging.ini')) +logging.config.fileConfig(log_fn) + from devstack import settings from devstack import utils @@ -62,3 +78,34 @@ def run(args): (rep, maxlen) = utils.welcome(PROG_NAME) _run_dep_comps(args, rep, maxlen) return True + + +def main(): + parser = optparse.OptionParser() + known_components = sorted(settings.COMPONENT_NAMES) + components = "(" + ", ".join(known_components) + ")" + parser.add_option("-c", "--component", + action="append", + dest="component", + help="openstack component, ie %s" % (components)) + known_actions = sorted(settings.ACTIONS) + actions = "(" + ", ".join(known_actions) + ")" + parser.add_option("-a", "--action", + action="store", + type="string", + dest="action", + metavar="ACTION", + help="action to perform, ie %s" % (actions)) + (options, args) = parser.parse_args() + opts = dict() + opts['components'] = options.component + opts['action'] = options.action + utils.welcome(PROG_NAME) + result = run(opts) + if not result: + return 1 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/devstack/progs/describe.py b/utils/describe.py similarity index 73% rename from devstack/progs/describe.py rename to utils/describe.py index 0696e9a3..71cb5d12 100644 --- a/devstack/progs/describe.py +++ b/utils/describe.py @@ -14,7 +14,23 @@ # License for the specific language governing permissions and limitations # under the License. +import logging +import logging.config +import optparse +import os import re +import sys + +POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +sys.path.insert(0, POSSIBLE_TOPDIR) + +log_fn = os.getenv('LOG_FILE') +if(log_fn == None): + log_fn = os.path.normpath(os.path.join("conf", 'logging.ini')) +logging.config.fileConfig(log_fn) + from devstack import settings from devstack import utils @@ -74,3 +90,24 @@ def run(args): (rep, maxlen) = utils.welcome(PROG_NAME) _run_describe_comps(args, rep, maxlen) return True + + +def main(): + parser = optparse.OptionParser() + known_components = sorted(settings.COMPONENT_NAMES) + components = "(" + ", ".join(known_components) + ")" + parser.add_option("-c", "--component", + action="append", + dest="component", + help="openstack component, ie %s" % (components)) + (options, args) = parser.parse_args() + opts = dict() + opts['components'] = options.component + result = run(opts) + if not result: + return 1 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/utils/env_gen.py b/utils/env_gen.py new file mode 100644 index 00000000..07f3cfec --- /dev/null +++ b/utils/env_gen.py @@ -0,0 +1,77 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging +import logging.config +import optparse +import os +import sys + +POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +sys.path.insert(0, POSSIBLE_TOPDIR) + +log_fn = os.getenv('LOG_FILE') +if(log_fn == None): + log_fn = os.path.normpath(os.path.join("conf", 'logging.ini')) +logging.config.fileConfig(log_fn) + +from devstack import cfg +from devstack import utils +from devstack.progs import common + + +PROG_NAME = "Env. file generator" + +CFG_MAKE = { + 'ADMIN_PASSWORD': ('passwords', 'horizon_keystone_admin'), + 'MYSQL_PASSWORD': ('passwords', 'sql'), + 'RABBIT_PASSWORD': ('passwords', 'rabbit'), + 'SERVICE_TOKEN': ('passwords', 'service_token'), + 'FLAT_INTERFACE': ('nova', 'flat_interface'), +} + +DEF_FN = 'localrc' + + +def write_line(text, fh): + fh.write(text) + fh.write(os.linesep) + + +def main(): + opts = optparse.OptionParser() + opts.add_option("-o", "--output", dest="filename", + help="write output to FILE", metavar="FILE") + (options, args) = opts.parse_args() + fn = options.filename + if not fn: + fn = DEF_FN + utils.welcome(PROG_NAME) + cfg = common.get_config() + with open(fn, "w") as fh: + for (out_name, cfg_data) in CFG_MAKE.items(): + section = cfg_data[0] + key = cfg_data[1] + value = cfg.get(section, key) + write_line("%s=%s" % (out_name, value), fh) + print("Check file \"%s\" for your environment configuration." % (os.path.normpath(fn))) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/utils/extract_json.py b/utils/extract_json.py index e89bda17..a2df6764 100644 --- a/utils/extract_json.py +++ b/utils/extract_json.py @@ -1,7 +1,8 @@ import json import os import sys - + + if __name__ == "__main__": me = os.path.basename(sys.argv[0]) if len(sys.argv) == 1: