[mythtv-users] How to check if a tuner is in use
Aaron Pelly
aaron at pelly.co
Wed Oct 15 23:34:26 UTC 2014
On 16/10/14 12:18, Hika van den Hoven wrote:
> How do I add an argument to the parser, that
> doesn't need a value, but is just a toggle? I want to add --verbose to
> print output to the screen, but it complains. I tried giving it an
> empty metavar and a default of 1, but it keeps complaining about
> expecting one argument. Also can you add a short to the long version,
> like --help and -h.
>
I'm no expert either, but here's a snippit from something I've been
working on.
maybe action='store_true' for a boolean.
parser = OptionParser(version='%prog ' + str(VERSION))
parser.set_defaults(debug=False)
parser.add_option('-d', '--debug', action='store_true',
help='output debugging information.')
parser.add_option('-v', '--verbose', action='store_true',
help='output verbose information.')
parser.add_option('-c', '--config', action='store', metavar='FILE',
help='use configuration FILE instead of "'+config_file+'".')
parser.add_option('--configure', action='store_true',
help='create initial configuration file "'+config_file+'".')
(options, args) = parser.parse_args()
if options.verbose:
log.setLevel(logging.INFO)
if options.debug:
log.setLevel(logging.DEBUG)
if options.config:
config_file = options.config
log.info('Using config file "%s" ', options.config)
More information about the mythtv-users
mailing list