use logging module for output, fixes #26

This commit is contained in:
iElectric
2009-07-08 23:57:15 +02:00
parent 67af81806d
commit 1c166845f8
16 changed files with 91 additions and 45 deletions

View File

@@ -2,10 +2,12 @@
import sys
import inspect
import logging
from optparse import OptionParser, BadOptionError
from migrate.versioning.base import *
from migrate.versioning import api, exceptions
from migrate.versioning.base import *
from migrate.versioning.util import asbool
alias = dict(
@@ -50,10 +52,14 @@ class PassiveOptionParser(OptionParser):
del rargs[0]
def main(argv=None, **kwargs):
"""kwargs are default options that can be overriden with passing
--some_option to cmdline
"""
"""Shell interface to :mod:`migrate.versioning.api`.
kwargs are default options that can be overriden with passing
--some_option as command line option
:param logging: Let migrate configure logging
:type logging: bool
"""
argv = argv or list(sys.argv[1:])
commands = list(api.__all__)
commands.sort()
@@ -138,6 +144,17 @@ def main(argv=None, **kwargs):
# apply overrides
kwargs.update(override_kwargs)
# configure logging
if asbool(kwargs.pop('logging', True)):
logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(message)s")
ch = logging.StreamHandler(sys.stdout)
ch.setFormatter(formatter)
logger.addHandler(ch)
log = logging.getLogger(__name__)
# check if all args are given
try:
num_defaults = len(f_defaults)
@@ -153,7 +170,7 @@ def main(argv=None, **kwargs):
try:
ret = command_func(**kwargs)
if ret is not None:
print ret
log.info(ret)
except (exceptions.UsageError, exceptions.KnownError), e:
parser.error(e.args[0])