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
This commit is contained in:
Matthew Treinish 2015-09-22 19:51:57 -04:00
parent dafc36a4ca
commit 442acf0c7d
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
4 changed files with 7 additions and 7 deletions

View File

@ -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'),
]

View File

@ -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)

View File

@ -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):

View File

@ -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()