Factorize argparser for debug level

This commit is contained in:
Yann Sionneau 2015-01-28 14:44:15 +01:00 committed by Sebastien Bourdeauducq
parent 906099c978
commit 5ba7218cc1
5 changed files with 23 additions and 5 deletions

View File

@ -10,6 +10,7 @@ from artiq.protocols.file_db import FlatFileDB, SimpleHistory
from artiq.master.scheduler import Scheduler
from artiq.master.rt_results import RTResults
from artiq.master.repository import Repository
from artiq.tools import verbosity_args, init_logger
def get_argparser():
@ -23,12 +24,14 @@ def get_argparser():
parser.add_argument(
"--port-control", default=3251, type=int,
help="TCP port to listen to for control")
verbosity_args(parser)
return parser
def main():
args = get_argparser().parse_args()
init_logger(args)
ddb = FlatFileDB("ddb.pyon")
pdb = FlatFileDB("pdb.pyon")
simplephist = SimpleHistory(30)

View File

@ -4,6 +4,7 @@ import argparse
from artiq.devices.lda.driver import Lda, Ldasim
from artiq.protocols.pc_rpc import simple_server_loop
from artiq.tools import verbosity_args, init_logger
def get_argparser():
@ -16,11 +17,13 @@ def get_argparser():
help="TCP port to listen to")
parser.add_argument('-s', '--serial', default=None,
help="USB serial number of the device")
verbosity_args(parser)
return parser
def main():
args = get_argparser().parse_args()
init_logger(args)
if args.device == "sim":
lda = Ldasim()
else:

View File

@ -9,6 +9,7 @@ from scipy import interpolate
import numpy as np
from artiq.protocols.pc_rpc import Client
from artiq.tools import verbosity_args, init_logger
def get_argparser():
@ -49,11 +50,13 @@ def get_argparser():
action="store_true", help="do reset before")
parser.add_argument("-b", "--bit", default=False,
action="store_true", help="do bit test")
verbosity_args(parser)
return parser
def main():
args = get_argparser().parse_args()
init_logger(args)
dev = Client(args.server, args.port, "pdq2")
dev.init()

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python3
import argparse
import logging
from artiq.devices.pdq2.driver import Pdq2
from artiq.protocols.pc_rpc import simple_server_loop
from artiq.tools import verbosity_args, init_logger
def get_argparser():
@ -19,16 +19,14 @@ def get_argparser():
parser.add_argument(
"-d", "--debug", default=False, action="store_true",
help="debug communications")
verbosity_args(parser)
return parser
def main():
args = get_argparser().parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.WARNING)
init_logger(args)
dev = Pdq2(serial=args.serial)
try:

View File

@ -1,6 +1,7 @@
from operator import itemgetter
import importlib.machinery
import linecache
import logging
def format_run_arguments(arguments):
@ -27,3 +28,13 @@ def file_import(filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
return loader.load_module()
def verbosity_args(parser):
group = parser.add_argument_group("verbosity")
group.add_argument("-v", "--verbose", default=0, action="count")
group.add_argument("-q", "--quiet", default=0, action="count")
def init_logger(args):
logging.basicConfig(logging.INFO + args.quiet*10 - args.verbose*10)