add '-q/--quiet' option
This commit is contained in:
@@ -63,6 +63,8 @@ def main():
|
|||||||
config.load(*args.yamlfiles, format="yaml", strict=True)
|
config.load(*args.yamlfiles, format="yaml", strict=True)
|
||||||
for key, value in args.options:
|
for key, value in args.options:
|
||||||
config.set(key, value)
|
config.set(key, value)
|
||||||
|
if args.loglevel >= logging.ERROR:
|
||||||
|
config.set(("output", "mode"), "null")
|
||||||
|
|
||||||
if args.list_modules:
|
if args.list_modules:
|
||||||
for module_name in extractor.modules:
|
for module_name in extractor.modules:
|
||||||
|
|||||||
@@ -140,6 +140,11 @@ def build_parser():
|
|||||||
"--list-modules", dest="list_modules", action="store_true",
|
"--list-modules", dest="list_modules", action="store_true",
|
||||||
help="Print a list of available modules/supported sites",
|
help="Print a list of available modules/supported sites",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-q", "--quiet", dest="loglevel", action="store_const",
|
||||||
|
const=logging.ERROR, default=logging.INFO,
|
||||||
|
help="Activate quiet mode",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", "--verbose", dest="loglevel", action="store_const",
|
"-v", "--verbose", dest="loglevel", action="store_const",
|
||||||
const=logging.DEBUG, default=logging.INFO,
|
const=logging.DEBUG, default=logging.INFO,
|
||||||
|
|||||||
@@ -13,22 +13,23 @@ from . import config
|
|||||||
|
|
||||||
|
|
||||||
def select():
|
def select():
|
||||||
"""Automatically select a suitable printer class"""
|
"""Automatically select a suitable output class"""
|
||||||
pdict = {
|
pdict = {
|
||||||
"default": Printer,
|
"default": PipeOutput,
|
||||||
"pipe": Printer,
|
"pipe": PipeOutput,
|
||||||
"term": TerminalPrinter,
|
"term": TerminalOutput,
|
||||||
"terminal": TerminalPrinter,
|
"terminal": TerminalOutput,
|
||||||
"color": ColorPrinter,
|
"color": ColorOutput,
|
||||||
|
"null": NullOutput,
|
||||||
}
|
}
|
||||||
omode = config.get(("output", "mode"), "auto").lower()
|
omode = config.get(("output", "mode"), "auto").lower()
|
||||||
if omode in pdict:
|
if omode in pdict:
|
||||||
return pdict[omode]()
|
return pdict[omode]()
|
||||||
elif omode == "auto":
|
elif omode == "auto":
|
||||||
if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
|
if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
|
||||||
return ColorPrinter() if ANSI else TerminalPrinter()
|
return ColorOutput() if ANSI else TerminalOutput()
|
||||||
else:
|
else:
|
||||||
return Printer()
|
return PipeOutput()
|
||||||
else:
|
else:
|
||||||
raise Exception("invalid output mode: " + omode)
|
raise Exception("invalid output mode: " + omode)
|
||||||
|
|
||||||
@@ -43,26 +44,31 @@ def safeprint(txt, **kwargs):
|
|||||||
print(txt, **kwargs)
|
print(txt, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Printer():
|
class NullOutput():
|
||||||
|
|
||||||
def start(self, path):
|
def start(self, path):
|
||||||
"""Print a message indicating the start of a download"""
|
"""Print a message indicating the start of a download"""
|
||||||
pass
|
|
||||||
|
|
||||||
def skip(self, path):
|
def skip(self, path):
|
||||||
"""Print a message indicating that a download has been skipped"""
|
"""Print a message indicating that a download has been skipped"""
|
||||||
print(CHAR_SKIP, path, sep="", flush=True)
|
|
||||||
|
|
||||||
def success(self, path, tries):
|
def success(self, path, tries):
|
||||||
"""Print a message indicating the completion of a download"""
|
"""Print a message indicating the completion of a download"""
|
||||||
print(path, flush=True)
|
|
||||||
|
|
||||||
def error(self, path, error, tries, max_tries):
|
def error(self, path, error, tries, max_tries):
|
||||||
"""Print a message indicating an error during download"""
|
"""Print a message indicating an error during download"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TerminalPrinter(Printer):
|
class PipeOutput(NullOutput):
|
||||||
|
|
||||||
|
def skip(self, path):
|
||||||
|
print(CHAR_SKIP, path, sep="", flush=True)
|
||||||
|
|
||||||
|
def success(self, path, tries):
|
||||||
|
print(path, flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
class TerminalOutput(NullOutput):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.short = config.get(("output", "shorten"), True)
|
self.short = config.get(("output", "shorten"), True)
|
||||||
@@ -99,7 +105,7 @@ class TerminalPrinter(Printer):
|
|||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
|
||||||
class ColorPrinter(TerminalPrinter):
|
class ColorOutput(TerminalOutput):
|
||||||
|
|
||||||
def start(self, path):
|
def start(self, path):
|
||||||
print(self.shorten(path), end="", flush=True)
|
print(self.shorten(path), end="", flush=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user