diff options
| author | jvoisin | 2018-07-10 21:30:38 +0200 |
|---|---|---|
| committer | jvoisin | 2018-07-10 21:30:38 +0200 |
| commit | 5a7c7f35f7d526a8c0ed49da12e4efc5e9dd6582 (patch) | |
| tree | e9af668c60f2b6b16641f5bbd106b9ff7d27b3b9 /libmat2 | |
| parent | d5861e46537f3e94abd26f63a3a7ad5b69d25e77 (diff) | |
Remove `print` from libmat, and use the `logging` module instead
This should close #28
Diffstat (limited to 'libmat2')
| -rw-r--r-- | libmat2/office.py | 8 | ||||
| -rw-r--r-- | libmat2/pdf.py | 2 | ||||
| -rw-r--r-- | libmat2/torrent.py | 2 |
3 files changed, 9 insertions, 3 deletions
diff --git a/libmat2/office.py b/libmat2/office.py index b3fde7e..1ececdf 100644 --- a/libmat2/office.py +++ b/libmat2/office.py | |||
| @@ -4,7 +4,9 @@ import shutil | |||
| 4 | import tempfile | 4 | import tempfile |
| 5 | import datetime | 5 | import datetime |
| 6 | import zipfile | 6 | import zipfile |
| 7 | import logging | ||
| 7 | from typing import Dict, Set, Pattern | 8 | from typing import Dict, Set, Pattern |
| 9 | |||
| 8 | try: # protect against DoS | 10 | try: # protect against DoS |
| 9 | from defusedxml import ElementTree as ET # type: ignore | 11 | from defusedxml import ElementTree as ET # type: ignore |
| 10 | except ImportError: | 12 | except ImportError: |
| @@ -17,6 +19,8 @@ from . import abstract, parser_factory | |||
| 17 | assert Set | 19 | assert Set |
| 18 | assert Pattern | 20 | assert Pattern |
| 19 | 21 | ||
| 22 | logging.basicConfig(level=logging.ERROR) | ||
| 23 | |||
| 20 | def _parse_xml(full_path: str): | 24 | def _parse_xml(full_path: str): |
| 21 | """ This function parse XML with namespace support. """ | 25 | """ This function parse XML with namespace support. """ |
| 22 | def parse_map(f): # etree support for ns is a bit rough | 26 | def parse_map(f): # etree support for ns is a bit rough |
| @@ -98,7 +102,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 98 | if self._specific_cleanup(full_path) is False: | 102 | if self._specific_cleanup(full_path) is False: |
| 99 | shutil.rmtree(temp_folder) | 103 | shutil.rmtree(temp_folder) |
| 100 | os.remove(self.output_filename) | 104 | os.remove(self.output_filename) |
| 101 | print("Something went wrong during deep cleaning of %s" % item.filename) | 105 | logging.info("Something went wrong during deep cleaning of %s", item.filename) |
| 102 | return False | 106 | return False |
| 103 | 107 | ||
| 104 | if item.filename in self.files_to_keep: | 108 | if item.filename in self.files_to_keep: |
| @@ -112,7 +116,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 112 | if not tmp_parser: | 116 | if not tmp_parser: |
| 113 | shutil.rmtree(temp_folder) | 117 | shutil.rmtree(temp_folder) |
| 114 | os.remove(self.output_filename) | 118 | os.remove(self.output_filename) |
| 115 | print("%s's format (%s) isn't supported" % (item.filename, mtype)) | 119 | logging.info("%s's format (%s) isn't supported", item.filename, mtype) |
| 116 | return False | 120 | return False |
| 117 | tmp_parser.remove_all() | 121 | tmp_parser.remove_all() |
| 118 | os.rename(tmp_parser.output_filename, full_path) | 122 | os.rename(tmp_parser.output_filename, full_path) |
diff --git a/libmat2/pdf.py b/libmat2/pdf.py index be02442..053a768 100644 --- a/libmat2/pdf.py +++ b/libmat2/pdf.py | |||
| @@ -16,7 +16,7 @@ from gi.repository import Poppler, GLib | |||
| 16 | 16 | ||
| 17 | from . import abstract | 17 | from . import abstract |
| 18 | 18 | ||
| 19 | logging.basicConfig(level=logging.DEBUG) | 19 | logging.basicConfig(level=logging.ERROR) |
| 20 | 20 | ||
| 21 | poppler_version = Poppler.get_version() | 21 | poppler_version = Poppler.get_version() |
| 22 | if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover | 22 | if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover |
diff --git a/libmat2/torrent.py b/libmat2/torrent.py index ca7715a..90f83f8 100644 --- a/libmat2/torrent.py +++ b/libmat2/torrent.py | |||
| @@ -3,6 +3,8 @@ 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 | |||
| 6 | 8 | ||
| 7 | class TorrentParser(abstract.AbstractParser): | 9 | class TorrentParser(abstract.AbstractParser): |
| 8 | mimetypes = {'application/x-bittorrent', } | 10 | mimetypes = {'application/x-bittorrent', } |
