allow to configure option parser in callback
This commit is contained in:
parent
79c21c3290
commit
d0f4ad7021
1 changed files with 15 additions and 4 deletions
|
|
@ -93,6 +93,16 @@ class BaseApplication(object):
|
||||||
""" Main function """
|
""" Main function """
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def configure_parser(self, parser):
|
||||||
|
"""
|
||||||
|
Frontend parser configuration.
|
||||||
|
Overload this method to add custom options for your parser.
|
||||||
|
Options will be available in the BaseApplication.options variable.
|
||||||
|
|
||||||
|
@param parser [OptionParser] the parser object.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(klass):
|
def run(klass):
|
||||||
app = klass()
|
app = klass()
|
||||||
|
|
@ -100,12 +110,13 @@ class BaseApplication(object):
|
||||||
parser.add_option('-d', '--debug', action='store_true', help='display debug messages')
|
parser.add_option('-d', '--debug', action='store_true', help='display debug messages')
|
||||||
parser.add_option('-q', '--quiet', action='store_true', help='display only error messages')
|
parser.add_option('-q', '--quiet', action='store_true', help='display only error messages')
|
||||||
parser.add_option('-v', '--verbose', action='store_true', help='display info messages')
|
parser.add_option('-v', '--verbose', action='store_true', help='display info messages')
|
||||||
options, args = parser.parse_args(sys.argv)
|
app.configure_parser(parser)
|
||||||
if options.debug:
|
app.options, args = parser.parse_args(sys.argv)
|
||||||
|
if app.options.debug:
|
||||||
level=logging.DEBUG
|
level=logging.DEBUG
|
||||||
elif options.verbose:
|
elif app.options.verbose:
|
||||||
level = logging.INFO
|
level = logging.INFO
|
||||||
elif options.quiet:
|
elif app.options.quiet:
|
||||||
level = logging.ERROR
|
level = logging.ERROR
|
||||||
else:
|
else:
|
||||||
level = logging.WARNING
|
level = logging.WARNING
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue