Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes bug 756105 - update to latest configman #607

Merged
merged 1 commit into from May 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements/prod.txt
@@ -1,5 +1,5 @@
# configman moves too fast for pypi right now
git+git://github.com/mozilla/configman@9c29f7830a4d1d6e1222fb80114f558f95d25e5c#egg=configman
git+git://github.com/mozilla/configman@501365977c4321ca40f53e2f56cce6bded013dac#egg=configman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're going to need to figure out how to solve the problem with make virtualenv where this doesn't get upgraded even though the hash is different.

configobj==4.7.2
hbase-thrift==0.20.4
isodate==0.4.7
Expand Down
131 changes: 77 additions & 54 deletions socorro/app/generic_app.py
Expand Up @@ -25,65 +25,83 @@ def __init__(self, config):
#--------------------------------------------------------------------------
def main(self): # pragma: no cover
"""derived classes must override this function with business logic"""
raise NotImplementedError("A definition of 'main' in a derived class"
"is required")
raise NotImplementedError(
"A definition of 'main' in a derived class is required"
)


#------------------------------------------------------------------------------
def logging_required_config(app_name):
lc = Namespace()
lc.add_option('syslog_host',
doc='syslog hostname',
default='localhost')
lc.add_option('syslog_port',
doc='syslog port',
default=514)
lc.add_option('syslog_facility_string',
doc='syslog facility string ("user", "local0", etc)',
default='user')
lc.add_option('syslog_line_format_string',
doc='python logging system format for syslog entries',
default='%s (pid {process}): '
'{asctime} {levelname} - {threadName} - '
'{message}' % app_name)
lc.add_option('syslog_error_logging_level',
doc='logging level for the log file (10 - DEBUG, 20 '
'- INFO, 30 - WARNING, 40 - ERROR, 50 - CRITICAL)',
default=40)
lc.add_option('stderr_line_format_string',
doc='python logging system format for logging to stderr',
default='{asctime} {levelname} - {threadName} - '
'{message}')
lc.add_option('stderr_error_logging_level',
doc='logging level for the logging to stderr (10 - '
'DEBUG, 20 - INFO, 30 - WARNING, 40 - ERROR, '
'50 - CRITICAL)',
default=10)
lc.add_option(
'syslog_host',
doc='syslog hostname',
default='localhost'
)
lc.add_option(
'syslog_port',
doc='syslog port',
default=514
)
lc.add_option(
'syslog_facility_string',
doc='syslog facility string ("user", "local0", etc)',
default='user'
)
lc.add_option(
'syslog_line_format_string',
doc='python logging system format for syslog entries',
default='%s (pid {process}): '
'{asctime} {levelname} - {threadName} - '
'{message}' % app_name
)
lc.add_option(
'syslog_error_logging_level',
doc='logging level for the log file (10 - DEBUG, 20 '
'- INFO, 30 - WARNING, 40 - ERROR, 50 - CRITICAL)',
default=40
)
lc.add_option(
'stderr_line_format_string',
doc='python logging system format for logging to stderr',
default='{asctime} {levelname} - {threadName} - '
'{message}'
)
lc.add_option(
'stderr_error_logging_level',
doc='logging level for the logging to stderr (10 - '
'DEBUG, 20 - INFO, 30 - WARNING, 40 - ERROR, '
'50 - CRITICAL)',
default=10
)
return lc


#------------------------------------------------------------------------------

def setup_logger(app_name, config, local_unused, args_unused):
logger = logging.getLogger(app_name)
logger.setLevel(logging.DEBUG)
stderr_log = logging.StreamHandler()
stderr_log.setLevel(config.stderr_error_logging_level)
stderr_log_formatter = logging.Formatter(
_convert_format_string(config.stderr_line_format_string))
_convert_format_string(config.stderr_line_format_string)
)
stderr_log.setFormatter(stderr_log_formatter)
logger.addHandler(stderr_log)

syslog = logging.handlers.SysLogHandler(
facility=config.syslog_facility_string)
facility=config.syslog_facility_string
)
syslog.setLevel(config.syslog_error_logging_level)
syslog_formatter = logging.Formatter(
_convert_format_string(config.syslog_line_format_string))
_convert_format_string(config.syslog_line_format_string)
)
syslog.setFormatter(syslog_formatter)
logger.addHandler(syslog)
return logger


#------------------------------------------------------------------------------
def _convert_format_string(s):
"""return '%(foo)s %(bar)s' if the input is '{foo} {bar}'"""
return re.sub('{(\w+)}', r'%(\1)s', s)
Expand All @@ -103,13 +121,13 @@ def main(initial_app, values_source_list=None):
# parameters. For a module to be acceptable, it must have a main
# function that accepts a DotDict derivative as its input parameter.
app_definition = Namespace()
app_definition.admin = admin = Namespace()
admin.add_option('application',
doc='the fully qualified module or class of the '
'application',
default=initial_app,
from_string_converter=class_converter
)
app_definition.add_option(
'application',
doc='the fully qualified module or class of the '
'application',
default=initial_app,
from_string_converter=class_converter
)
try:
app_name = initial_app.app_name # this will be used as the default
# b
Expand All @@ -118,19 +136,24 @@ def main(initial_app, values_source_list=None):
except AttributeError, x:
raise AppDetailMissingError(str(x))

app_definition.add_aggregation('logger',
functools.partial(setup_logger,
app_name))

definitions = (app_definition,
logging_required_config(app_name))

config_manager = ConfigurationManager(definitions,
app_name=app_name,
app_version=app_version,
app_description=app_description,
values_source_list=values_source_list,
)
app_definition.add_aggregation(
'logger',
functools.partial(setup_logger,
app_name)
)

definitions = (
app_definition,
logging_required_config(app_name)
)

config_manager = ConfigurationManager(
definitions,
app_name=app_name,
app_version=app_version,
app_description=app_description,
values_source_list=values_source_list,
)

with config_manager.context() as config:
config_manager.log_config(config.logger)
Expand All @@ -140,7 +163,7 @@ def main(initial_app, values_source_list=None):
# it might not always be that way. The user always has the ability
# to specify on the command line a new app class that will override
# 'initial_app'.
app = config.admin.application
app = config.application

if isinstance(app, type):
# invocation of the app if the app_object was a class
Expand Down