From 442acf0c7d716ca3406ecd82e3f8f8c0845fac3f Mon Sep 17 00:00:00 2001 From: Matthew Treinish <mtreinish@kortar.org> Date: Tue, 22 Sep 2015 19:51:57 -0400 Subject: [PATCH] Fix verbose option inialization The verbose config option is defined in the set of cli opts defined for each of the subunit2sql cli commands. When those are called the options are registered with the global CONF object. However, if the db api is invoked directly there is no guarantee that the config option registration has occured. This commit addresses this issue by changing how the option is created and registered. It is moved into the db api module to ensure that it always exists before it is used. The option is then imported into all the cli commands that were previously registering it. Change-Id: Id5f45fa8a6d8f2f2f2eebe7e2ac4623cac0f7f10 --- subunit2sql/analysis/graph.py | 3 +-- subunit2sql/db/api.py | 5 ++++- subunit2sql/migrations/cli.py | 3 +-- subunit2sql/shell.py | 3 +-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/subunit2sql/analysis/graph.py b/subunit2sql/analysis/graph.py index 2c3c0b7..0c95536 100755 --- a/subunit2sql/analysis/graph.py +++ b/subunit2sql/analysis/graph.py @@ -27,6 +27,7 @@ import subunit2sql.analysis.run_time from subunit2sql import shell CONF = cfg.CONF +CONF.import_opt('verbose', 'subunit2sql.db.api') SHELL_OPTS = [ cfg.StrOpt('title', short='t', help='Optional title to use for the graph ' @@ -41,8 +42,6 @@ SHELL_OPTS = [ cfg.StrOpt('stop-date', short='s', help='Stop date for the graph only data from before this date ' 'will be used. Uses ISO 8601 format: 1914-06-28'), - cfg.BoolOpt('verbose', short='v', - help='Verbose output including logging of SQL statements'), ] diff --git a/subunit2sql/db/api.py b/subunit2sql/db/api.py index 75486a2..5c66eda 100644 --- a/subunit2sql/db/api.py +++ b/subunit2sql/db/api.py @@ -27,6 +27,9 @@ from subunit2sql import exceptions from subunit2sql import read_subunit CONF = cfg.CONF +CONF.register_cli_opt(cfg.BoolOpt('verbose', short='v', default=False, + help='Verbose output including logging of ' + 'SQL statements')) DAY_SECONDS = 60 * 60 * 24 @@ -59,7 +62,7 @@ def get_session(autocommit=True, expire_on_commit=False): # if --verbose was specified, turn on SQL logging # note that this is done after the session has been initialized so that # we can override the default sqlalchemy logging - if CONF.verbose: + if CONF.get('verbose', False): logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) diff --git a/subunit2sql/migrations/cli.py b/subunit2sql/migrations/cli.py index 7da86c6..2289efa 100644 --- a/subunit2sql/migrations/cli.py +++ b/subunit2sql/migrations/cli.py @@ -41,13 +41,12 @@ MIGRATION_OPTS = [ "out the microseconds from the timestamps this will skip " "converting the microsecond field from the timestamps " "into a separate column"), - cfg.BoolOpt('verbose', short='v', - help='Verbose output including logging of SQL statements'), ] CONF = cfg.CONF CONF.register_cli_opts(options.database_opts, group='database') CONF.register_cli_opts(MIGRATION_OPTS) +CONF.import_opt('verbose', 'subunit2sql.db.api') def do_alembic_command(config, cmd, *args, **kwargs): diff --git a/subunit2sql/shell.py b/subunit2sql/shell.py index 3876c47..5b99d47 100644 --- a/subunit2sql/shell.py +++ b/subunit2sql/shell.py @@ -25,6 +25,7 @@ from subunit2sql import exceptions from subunit2sql import read_subunit as subunit CONF = cfg.CONF +CONF.import_opt('verbose', 'subunit2sql.db.api') SHELL_OPTS = [ cfg.MultiStrOpt('subunit_files', positional=True, @@ -41,8 +42,6 @@ SHELL_OPTS = [ cfg.StrOpt('attr_regex', default='\[(.*)\]', help='The regex to use to extract the comma separated list of ' 'test attributes from the test_id'), - cfg.BoolOpt('verbose', short='v', - help='Verbose output including logging of SQL statements'), ] _version_ = version.VersionInfo('subunit2sql').version_string()