forked from M-Labs/artiq
Factorize argparser for debug level
This commit is contained in:
parent
906099c978
commit
5ba7218cc1
|
@ -10,6 +10,7 @@ from artiq.protocols.file_db import FlatFileDB, SimpleHistory
|
||||||
from artiq.master.scheduler import Scheduler
|
from artiq.master.scheduler import Scheduler
|
||||||
from artiq.master.rt_results import RTResults
|
from artiq.master.rt_results import RTResults
|
||||||
from artiq.master.repository import Repository
|
from artiq.master.repository import Repository
|
||||||
|
from artiq.tools import verbosity_args, init_logger
|
||||||
|
|
||||||
|
|
||||||
def get_argparser():
|
def get_argparser():
|
||||||
|
@ -23,12 +24,14 @@ def get_argparser():
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--port-control", default=3251, type=int,
|
"--port-control", default=3251, type=int,
|
||||||
help="TCP port to listen to for control")
|
help="TCP port to listen to for control")
|
||||||
|
verbosity_args(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = get_argparser().parse_args()
|
args = get_argparser().parse_args()
|
||||||
|
|
||||||
|
init_logger(args)
|
||||||
ddb = FlatFileDB("ddb.pyon")
|
ddb = FlatFileDB("ddb.pyon")
|
||||||
pdb = FlatFileDB("pdb.pyon")
|
pdb = FlatFileDB("pdb.pyon")
|
||||||
simplephist = SimpleHistory(30)
|
simplephist = SimpleHistory(30)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import argparse
|
||||||
|
|
||||||
from artiq.devices.lda.driver import Lda, Ldasim
|
from artiq.devices.lda.driver import Lda, Ldasim
|
||||||
from artiq.protocols.pc_rpc import simple_server_loop
|
from artiq.protocols.pc_rpc import simple_server_loop
|
||||||
|
from artiq.tools import verbosity_args, init_logger
|
||||||
|
|
||||||
|
|
||||||
def get_argparser():
|
def get_argparser():
|
||||||
|
@ -16,11 +17,13 @@ def get_argparser():
|
||||||
help="TCP port to listen to")
|
help="TCP port to listen to")
|
||||||
parser.add_argument('-s', '--serial', default=None,
|
parser.add_argument('-s', '--serial', default=None,
|
||||||
help="USB serial number of the device")
|
help="USB serial number of the device")
|
||||||
|
verbosity_args(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = get_argparser().parse_args()
|
args = get_argparser().parse_args()
|
||||||
|
init_logger(args)
|
||||||
if args.device == "sim":
|
if args.device == "sim":
|
||||||
lda = Ldasim()
|
lda = Ldasim()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -9,6 +9,7 @@ from scipy import interpolate
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from artiq.protocols.pc_rpc import Client
|
from artiq.protocols.pc_rpc import Client
|
||||||
|
from artiq.tools import verbosity_args, init_logger
|
||||||
|
|
||||||
|
|
||||||
def get_argparser():
|
def get_argparser():
|
||||||
|
@ -49,11 +50,13 @@ def get_argparser():
|
||||||
action="store_true", help="do reset before")
|
action="store_true", help="do reset before")
|
||||||
parser.add_argument("-b", "--bit", default=False,
|
parser.add_argument("-b", "--bit", default=False,
|
||||||
action="store_true", help="do bit test")
|
action="store_true", help="do bit test")
|
||||||
|
verbosity_args(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = get_argparser().parse_args()
|
args = get_argparser().parse_args()
|
||||||
|
init_logger(args)
|
||||||
dev = Client(args.server, args.port, "pdq2")
|
dev = Client(args.server, args.port, "pdq2")
|
||||||
dev.init()
|
dev.init()
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
|
||||||
|
|
||||||
from artiq.devices.pdq2.driver import Pdq2
|
from artiq.devices.pdq2.driver import Pdq2
|
||||||
from artiq.protocols.pc_rpc import simple_server_loop
|
from artiq.protocols.pc_rpc import simple_server_loop
|
||||||
|
from artiq.tools import verbosity_args, init_logger
|
||||||
|
|
||||||
|
|
||||||
def get_argparser():
|
def get_argparser():
|
||||||
|
@ -19,16 +19,14 @@ def get_argparser():
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-d", "--debug", default=False, action="store_true",
|
"-d", "--debug", default=False, action="store_true",
|
||||||
help="debug communications")
|
help="debug communications")
|
||||||
|
verbosity_args(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = get_argparser().parse_args()
|
args = get_argparser().parse_args()
|
||||||
|
|
||||||
if args.debug:
|
init_logger(args)
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
else:
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
|
||||||
|
|
||||||
dev = Pdq2(serial=args.serial)
|
dev = Pdq2(serial=args.serial)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
import linecache
|
import linecache
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
def format_run_arguments(arguments):
|
def format_run_arguments(arguments):
|
||||||
|
@ -27,3 +28,13 @@ def file_import(filename):
|
||||||
|
|
||||||
loader = importlib.machinery.SourceFileLoader(modname, filename)
|
loader = importlib.machinery.SourceFileLoader(modname, filename)
|
||||||
return loader.load_module()
|
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)
|
||||||
|
|
Loading…
Reference in New Issue