2015-01-17 19:38:20 +08:00
|
|
|
from operator import itemgetter
|
2014-12-08 16:11:31 +08:00
|
|
|
import importlib.machinery
|
2015-01-07 18:14:52 +08:00
|
|
|
import linecache
|
2015-01-28 21:44:15 +08:00
|
|
|
import logging
|
2014-12-08 16:11:31 +08:00
|
|
|
|
|
|
|
|
2015-01-17 19:38:20 +08:00
|
|
|
def format_run_arguments(arguments):
|
|
|
|
fmtargs = []
|
|
|
|
for k, v in sorted(arguments.items(), key=itemgetter(0)):
|
|
|
|
fmtargs.append(k + "=" + str(v))
|
|
|
|
if fmtargs:
|
|
|
|
return " ".join(fmtargs)
|
|
|
|
else:
|
|
|
|
return "-"
|
|
|
|
|
|
|
|
|
2014-12-08 16:11:31 +08:00
|
|
|
def file_import(filename):
|
2015-01-07 18:14:52 +08:00
|
|
|
linecache.checkcache(filename)
|
|
|
|
|
2014-12-08 16:11:31 +08:00
|
|
|
modname = filename
|
|
|
|
i = modname.rfind("/")
|
|
|
|
if i > 0:
|
|
|
|
modname = modname[i+1:]
|
|
|
|
i = modname.find(".")
|
|
|
|
if i > 0:
|
|
|
|
modname = modname[:i]
|
|
|
|
modname = "file_import_" + modname
|
|
|
|
|
|
|
|
loader = importlib.machinery.SourceFileLoader(modname, filename)
|
|
|
|
return loader.load_module()
|
2015-01-28 21:44:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
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):
|
2015-01-30 19:02:27 +08:00
|
|
|
logging.basicConfig(level=logging.WARNING + args.quiet*10 - args.verbose*10)
|