diff --git a/libmat2/office.py b/libmat2/office.py index 62d0395..4881253 100644 --- a/libmat2/office.py +++ b/libmat2/office.py @@ -19,8 +19,6 @@ from . import abstract, parser_factory assert Set assert Pattern -logging.basicConfig(level=logging.ERROR) - def _parse_xml(full_path: str): """ This function parse XML, with namespace support. """ @@ -96,7 +94,8 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): if self._specific_cleanup(full_path) is False: shutil.rmtree(temp_folder) os.remove(self.output_filename) - logging.info("Something went wrong during deep cleaning of %s", item.filename) + logging.warning("Something went wrong during deep cleaning of %s", + item.filename) return False if item.filename in self.files_to_keep: @@ -110,7 +109,9 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): if not tmp_parser: shutil.rmtree(temp_folder) os.remove(self.output_filename) - logging.info("%s's format (%s) isn't supported", item.filename, mtype) + logging.error("in file %s, element %s's format (%s) " + + "isn't supported", + self.filename, item.filename, mtype) return False tmp_parser.remove_all() os.rename(tmp_parser.output_filename, full_path) diff --git a/libmat2/pdf.py b/libmat2/pdf.py index d3c4698..bc7c8a6 100644 --- a/libmat2/pdf.py +++ b/libmat2/pdf.py @@ -16,8 +16,6 @@ from gi.repository import Poppler, GLib from . import abstract -logging.basicConfig(level=logging.ERROR) - poppler_version = Poppler.get_version() if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover raise ValueError("MAT2 needs at least Poppler version 0.46 to work. \ diff --git a/libmat2/torrent.py b/libmat2/torrent.py index 90f83f8..049807b 100644 --- a/libmat2/torrent.py +++ b/libmat2/torrent.py @@ -3,9 +3,6 @@ from typing import Union, Tuple, Dict from . import abstract -logging.basicConfig(level=logging.ERROR) - - class TorrentParser(abstract.AbstractParser): mimetypes = {'application/x-bittorrent', } whitelist = {b'announce', b'announce-list', b'info'} @@ -123,9 +120,9 @@ class _BencodeHandler(object): try: ret, trail = self.__decode_func[s[0]](s) except (IndexError, KeyError, ValueError) as e: - logging.debug("Not a valid bencoded string: %s", e) + logging.warning("Not a valid bencoded string: %s", e) return None if trail != b'': - logging.debug("Invalid bencoded value (data after valid prefix)") + logging.warning("Invalid bencoded value (data after valid prefix)") return None return ret diff --git a/mat2 b/mat2 index 35b5aee..23792b4 100755 --- a/mat2 +++ b/mat2 @@ -7,6 +7,7 @@ import itertools import mimetypes import argparse import multiprocessing +import logging try: from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS, check_dependencies @@ -38,6 +39,8 @@ def create_arg_parser(): help='list all supported fileformats') parser.add_argument('-c', '--check-dependencies', action='store_true', help='check if MAT2 has all the dependencies it needs') + parser.add_argument('-V', '--verbose', action='store_true', + help='show more verbose status information') info = parser.add_mutually_exclusive_group() @@ -110,6 +113,9 @@ def main(): arg_parser = create_arg_parser() args = arg_parser.parse_args() + if args.verbose: + logging.basicConfig(level=logging.INFO) + if not args.files: if args.list: show_parsers() diff --git a/tests/test_climat2.py b/tests/test_climat2.py index e65e47f..af89c0e 100644 --- a/tests/test_climat2.py +++ b/tests/test_climat2.py @@ -8,12 +8,12 @@ class TestHelp(unittest.TestCase): def test_help(self): proc = subprocess.Popen(['./mat2', '--help'], stdout=subprocess.PIPE) stdout, _ = proc.communicate() - self.assertIn(b'usage: mat2 [-h] [-v] [-l] [-c] [-s | -L] [files [files ...]]', stdout) + self.assertIn(b'usage: mat2 [-h] [-v] [-l] [-c] [-V] [-s | -L] [files [files ...]]', stdout) def test_no_arg(self): proc = subprocess.Popen(['./mat2'], stdout=subprocess.PIPE) stdout, _ = proc.communicate() - self.assertIn(b'usage: mat2 [-h] [-v] [-l] [-c] [-s | -L] [files [files ...]]', stdout) + self.assertIn(b'usage: mat2 [-h] [-v] [-l] [-c] [-V] [-s | -L] [files [files ...]]', stdout) class TestVersion(unittest.TestCase):