diff options
| author | dkg | 2018-09-01 05:14:32 -0700 |
|---|---|---|
| committer | jvoisin | 2018-09-01 05:14:32 -0700 |
| commit | e2634f7a5052f0507b245b30e2f2bc25963f863f (patch) | |
| tree | ec8b62ae6a726751f34e74efbce7afbbc3ccc5ef | |
| parent | aba9b72d2c9defc253f954d30dfeb3ae3e46d2cc (diff) | |
Logging cleanup
| -rw-r--r-- | libmat2/office.py | 9 | ||||
| -rw-r--r-- | libmat2/pdf.py | 2 | ||||
| -rw-r--r-- | libmat2/torrent.py | 7 | ||||
| -rwxr-xr-x | mat2 | 6 | ||||
| -rw-r--r-- | tests/test_climat2.py | 4 |
5 files changed, 15 insertions, 13 deletions
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 | |||
| 19 | assert Set | 19 | assert Set |
| 20 | assert Pattern | 20 | assert Pattern |
| 21 | 21 | ||
| 22 | logging.basicConfig(level=logging.ERROR) | ||
| 23 | |||
| 24 | def _parse_xml(full_path: str): | 22 | def _parse_xml(full_path: str): |
| 25 | """ This function parse XML, with namespace support. """ | 23 | """ This function parse XML, with namespace support. """ |
| 26 | 24 | ||
| @@ -96,7 +94,8 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 96 | if self._specific_cleanup(full_path) is False: | 94 | if self._specific_cleanup(full_path) is False: |
| 97 | shutil.rmtree(temp_folder) | 95 | shutil.rmtree(temp_folder) |
| 98 | os.remove(self.output_filename) | 96 | os.remove(self.output_filename) |
| 99 | logging.info("Something went wrong during deep cleaning of %s", item.filename) | 97 | logging.warning("Something went wrong during deep cleaning of %s", |
| 98 | item.filename) | ||
| 100 | return False | 99 | return False |
| 101 | 100 | ||
| 102 | if item.filename in self.files_to_keep: | 101 | if item.filename in self.files_to_keep: |
| @@ -110,7 +109,9 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 110 | if not tmp_parser: | 109 | if not tmp_parser: |
| 111 | shutil.rmtree(temp_folder) | 110 | shutil.rmtree(temp_folder) |
| 112 | os.remove(self.output_filename) | 111 | os.remove(self.output_filename) |
| 113 | logging.info("%s's format (%s) isn't supported", item.filename, mtype) | 112 | logging.error("in file %s, element %s's format (%s) " + |
| 113 | "isn't supported", | ||
| 114 | self.filename, item.filename, mtype) | ||
| 114 | return False | 115 | return False |
| 115 | tmp_parser.remove_all() | 116 | tmp_parser.remove_all() |
| 116 | os.rename(tmp_parser.output_filename, full_path) | 117 | 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 | |||
| 16 | 16 | ||
| 17 | from . import abstract | 17 | from . import abstract |
| 18 | 18 | ||
| 19 | logging.basicConfig(level=logging.ERROR) | ||
| 20 | |||
| 21 | poppler_version = Poppler.get_version() | 19 | poppler_version = Poppler.get_version() |
| 22 | if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover | 20 | if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover |
| 23 | raise ValueError("MAT2 needs at least Poppler version 0.46 to work. \ | 21 | 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 | |||
| 3 | 3 | ||
| 4 | from . import abstract | 4 | from . import abstract |
| 5 | 5 | ||
| 6 | logging.basicConfig(level=logging.ERROR) | ||
| 7 | |||
| 8 | |||
| 9 | class TorrentParser(abstract.AbstractParser): | 6 | class TorrentParser(abstract.AbstractParser): |
| 10 | mimetypes = {'application/x-bittorrent', } | 7 | mimetypes = {'application/x-bittorrent', } |
| 11 | whitelist = {b'announce', b'announce-list', b'info'} | 8 | whitelist = {b'announce', b'announce-list', b'info'} |
| @@ -123,9 +120,9 @@ class _BencodeHandler(object): | |||
| 123 | try: | 120 | try: |
| 124 | ret, trail = self.__decode_func[s[0]](s) | 121 | ret, trail = self.__decode_func[s[0]](s) |
| 125 | except (IndexError, KeyError, ValueError) as e: | 122 | except (IndexError, KeyError, ValueError) as e: |
| 126 | logging.debug("Not a valid bencoded string: %s", e) | 123 | logging.warning("Not a valid bencoded string: %s", e) |
| 127 | return None | 124 | return None |
| 128 | if trail != b'': | 125 | if trail != b'': |
| 129 | logging.debug("Invalid bencoded value (data after valid prefix)") | 126 | logging.warning("Invalid bencoded value (data after valid prefix)") |
| 130 | return None | 127 | return None |
| 131 | return ret | 128 | return ret |
| @@ -7,6 +7,7 @@ import itertools | |||
| 7 | import mimetypes | 7 | import mimetypes |
| 8 | import argparse | 8 | import argparse |
| 9 | import multiprocessing | 9 | import multiprocessing |
| 10 | import logging | ||
| 10 | 11 | ||
| 11 | try: | 12 | try: |
| 12 | from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS, check_dependencies | 13 | from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS, check_dependencies |
| @@ -38,6 +39,8 @@ def create_arg_parser(): | |||
| 38 | help='list all supported fileformats') | 39 | help='list all supported fileformats') |
| 39 | parser.add_argument('-c', '--check-dependencies', action='store_true', | 40 | parser.add_argument('-c', '--check-dependencies', action='store_true', |
| 40 | help='check if MAT2 has all the dependencies it needs') | 41 | help='check if MAT2 has all the dependencies it needs') |
| 42 | parser.add_argument('-V', '--verbose', action='store_true', | ||
| 43 | help='show more verbose status information') | ||
| 41 | 44 | ||
| 42 | 45 | ||
| 43 | info = parser.add_mutually_exclusive_group() | 46 | info = parser.add_mutually_exclusive_group() |
| @@ -110,6 +113,9 @@ def main(): | |||
| 110 | arg_parser = create_arg_parser() | 113 | arg_parser = create_arg_parser() |
| 111 | args = arg_parser.parse_args() | 114 | args = arg_parser.parse_args() |
| 112 | 115 | ||
| 116 | if args.verbose: | ||
| 117 | logging.basicConfig(level=logging.INFO) | ||
| 118 | |||
| 113 | if not args.files: | 119 | if not args.files: |
| 114 | if args.list: | 120 | if args.list: |
| 115 | show_parsers() | 121 | 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): | |||
| 8 | def test_help(self): | 8 | def test_help(self): |
| 9 | proc = subprocess.Popen(['./mat2', '--help'], stdout=subprocess.PIPE) | 9 | proc = subprocess.Popen(['./mat2', '--help'], stdout=subprocess.PIPE) |
| 10 | stdout, _ = proc.communicate() | 10 | stdout, _ = proc.communicate() |
| 11 | self.assertIn(b'usage: mat2 [-h] [-v] [-l] [-c] [-s | -L] [files [files ...]]', stdout) | 11 | self.assertIn(b'usage: mat2 [-h] [-v] [-l] [-c] [-V] [-s | -L] [files [files ...]]', stdout) |
| 12 | 12 | ||
| 13 | def test_no_arg(self): | 13 | def test_no_arg(self): |
| 14 | proc = subprocess.Popen(['./mat2'], stdout=subprocess.PIPE) | 14 | proc = subprocess.Popen(['./mat2'], stdout=subprocess.PIPE) |
| 15 | stdout, _ = proc.communicate() | 15 | stdout, _ = proc.communicate() |
| 16 | self.assertIn(b'usage: mat2 [-h] [-v] [-l] [-c] [-s | -L] [files [files ...]]', stdout) | 16 | self.assertIn(b'usage: mat2 [-h] [-v] [-l] [-c] [-V] [-s | -L] [files [files ...]]', stdout) |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | class TestVersion(unittest.TestCase): | 19 | class TestVersion(unittest.TestCase): |
