Python – command line arguments
http://docs.python.org/2/howto/argparse.html
parser = argparse.ArgumentParser(description=”Read 1-wire sensors and write to database”)
# argument with argument from type int
parser.add_argument(“-r”, “–read”, help=”get the [READ] last entries from the database”, type=int)
group1 = parser.add_mutually_exclusive_group()
group1.add_argument(“-v”, “–verbose”, default=False,
dest=’verbose’, help=”increase output verbosity”)
group1.add_argument(“-q”, “–quiet”, action=’store_const’, dest=’quiet’,
const=’value-to-store’,help=”no output”)
parser.add_argument(“-d”, “–debug”, action=’store_const’, dest=’debug’,
const=’value-to-store’, help=”show debug messages”)
parser.add_argument(“-n”, “–nodb”, action=’store_const’, dest=’nodb’,
const=’value-to-store’, help=”execute read but do not write into database”)
parser.add_argument(“-w”, “–html_single”, action=’store_const’, dest=’html_single’,
const=’value-to-store’,help=”create web page(html)with last entry”)
parser.add_argument(“-k”, “–kill”, action=’store_const’, dest=’kill’, const=’value-to-store’,help=”kill all entries in database”,)
parser.add_argument(“-s”, “–setup”, action=’store_const’, dest=’setup’,
const=’value-to-store’,help=”create config file”,)
parser.add_argument(‘–version’, action=’version’, version=’%(prog)s 0.1′)
args = parser.parse_args()
if args.setup: setup_level = 1
if args.verbose:
print “verbosity turned on”
verbose_level = 1