Remove print
from libmat, and use the logging
module instead
This should close #28
This commit is contained in:
parent
d5861e4653
commit
5a7c7f35f7
@ -4,7 +4,9 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import datetime
|
import datetime
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import logging
|
||||||
from typing import Dict, Set, Pattern
|
from typing import Dict, Set, Pattern
|
||||||
|
|
||||||
try: # protect against DoS
|
try: # protect against DoS
|
||||||
from defusedxml import ElementTree as ET # type: ignore
|
from defusedxml import ElementTree as ET # type: ignore
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -17,6 +19,8 @@ from . import abstract, parser_factory
|
|||||||
assert Set
|
assert Set
|
||||||
assert Pattern
|
assert Pattern
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.ERROR)
|
||||||
|
|
||||||
def _parse_xml(full_path: str):
|
def _parse_xml(full_path: str):
|
||||||
""" This function parse XML with namespace support. """
|
""" This function parse XML with namespace support. """
|
||||||
def parse_map(f): # etree support for ns is a bit rough
|
def parse_map(f): # etree support for ns is a bit rough
|
||||||
@ -98,7 +102,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
|
|||||||
if self._specific_cleanup(full_path) is False:
|
if self._specific_cleanup(full_path) is False:
|
||||||
shutil.rmtree(temp_folder)
|
shutil.rmtree(temp_folder)
|
||||||
os.remove(self.output_filename)
|
os.remove(self.output_filename)
|
||||||
print("Something went wrong during deep cleaning of %s" % item.filename)
|
logging.info("Something went wrong during deep cleaning of %s", item.filename)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if item.filename in self.files_to_keep:
|
if item.filename in self.files_to_keep:
|
||||||
@ -112,7 +116,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
|
|||||||
if not tmp_parser:
|
if not tmp_parser:
|
||||||
shutil.rmtree(temp_folder)
|
shutil.rmtree(temp_folder)
|
||||||
os.remove(self.output_filename)
|
os.remove(self.output_filename)
|
||||||
print("%s's format (%s) isn't supported" % (item.filename, mtype))
|
logging.info("%s's format (%s) isn't supported", item.filename, mtype)
|
||||||
return False
|
return False
|
||||||
tmp_parser.remove_all()
|
tmp_parser.remove_all()
|
||||||
os.rename(tmp_parser.output_filename, full_path)
|
os.rename(tmp_parser.output_filename, full_path)
|
||||||
|
@ -16,7 +16,7 @@ from gi.repository import Poppler, GLib
|
|||||||
|
|
||||||
from . import abstract
|
from . import abstract
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.ERROR)
|
||||||
|
|
||||||
poppler_version = Poppler.get_version()
|
poppler_version = Poppler.get_version()
|
||||||
if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover
|
if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover
|
||||||
|
@ -3,6 +3,8 @@ from typing import Union, Tuple, Dict
|
|||||||
|
|
||||||
from . import abstract
|
from . import abstract
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.ERROR)
|
||||||
|
|
||||||
|
|
||||||
class TorrentParser(abstract.AbstractParser):
|
class TorrentParser(abstract.AbstractParser):
|
||||||
mimetypes = {'application/x-bittorrent', }
|
mimetypes = {'application/x-bittorrent', }
|
||||||
|
@ -195,7 +195,6 @@ class TestDeepCleaning(unittest.TestCase):
|
|||||||
inside_p, _ = parser_factory.get_parser(complete_path)
|
inside_p, _ = parser_factory.get_parser(complete_path)
|
||||||
if inside_p is None:
|
if inside_p is None:
|
||||||
continue
|
continue
|
||||||
print('[+] %s is clean inside %s' %(complete_path, p.filename))
|
|
||||||
self.assertEqual(inside_p.get_meta(), {})
|
self.assertEqual(inside_p.get_meta(), {})
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(tempdir)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user