1
0
Fork 0

Logging cleanup

This commit is contained in:
dkg 2018-09-01 05:14:32 -07:00 committed by jvoisin
parent aba9b72d2c
commit e2634f7a50
5 changed files with 15 additions and 13 deletions

View File

@ -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)

View File

@ -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. \

View File

@ -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

6
mat2
View File

@ -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()

View File

@ -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):