parser_factory
now returns the mtype too
This commit is contained in:
parent
6c29e0eae2
commit
6868f20065
7
main.py
7
main.py
@ -20,9 +20,8 @@ def create_arg_parser():
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def show_meta(filename:str):
|
def show_meta(filename:str):
|
||||||
p = parser_factory.get_parser(filename)
|
p, mtype = parser_factory.get_parser(filename)
|
||||||
if p is None:
|
if p is None:
|
||||||
mtype, _ = mimetypes.guess_type(filename)
|
|
||||||
print("[-] %s's format (%s) is not supported" % (filename, mtype))
|
print("[-] %s's format (%s) is not supported" % (filename, mtype))
|
||||||
return
|
return
|
||||||
for k,v in p.get_meta().items():
|
for k,v in p.get_meta().items():
|
||||||
@ -38,9 +37,9 @@ def main():
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
for f in args.files:
|
for f in args.files:
|
||||||
p = parser_factory.get_parser(f)
|
p, mtype = parser_factory.get_parser(f)
|
||||||
if p is None:
|
if p is None:
|
||||||
print("[-] %s's format (%s) is not supported" % (f, "meh"))
|
print("[-] %s's format (%s) is not supported" % (f, mtype))
|
||||||
continue
|
continue
|
||||||
p.remove_all()
|
p.remove_all()
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
|
|||||||
|
|
||||||
def _clean_internal_file(self, item:zipfile.ZipInfo, temp_folder:str, zin:zipfile.ZipFile, zout:zipfile.ZipFile):
|
def _clean_internal_file(self, item:zipfile.ZipInfo, temp_folder:str, zin:zipfile.ZipFile, zout:zipfile.ZipFile):
|
||||||
zin.extract(member=item, path=temp_folder)
|
zin.extract(member=item, path=temp_folder)
|
||||||
tmp_parser = parser_factory.get_parser(os.path.join(temp_folder, item.filename))
|
tmp_parser, mtype = parser_factory.get_parser(os.path.join(temp_folder, item.filename))
|
||||||
if tmp_parser is None:
|
if tmp_parser is None:
|
||||||
print("%s isn't supported" % item.filename)
|
print("%s's format (%s) isn't supported" % (item.filename, mtype))
|
||||||
return
|
return
|
||||||
tmp_parser.remove_all()
|
tmp_parser.remove_all()
|
||||||
zinfo = zipfile.ZipInfo(item.filename)
|
zinfo = zipfile.ZipInfo(item.filename)
|
||||||
|
@ -15,6 +15,6 @@ def get_parser(filename: str):
|
|||||||
mtype, _ = mimetypes.guess_type(filename)
|
mtype, _ = mimetypes.guess_type(filename)
|
||||||
for c in abstract.AbstractParser.__subclasses__():
|
for c in abstract.AbstractParser.__subclasses__():
|
||||||
if mtype in c.mimetypes:
|
if mtype in c.mimetypes:
|
||||||
return c(filename)
|
return c(filename), mtype
|
||||||
print('factory: %s is not supported' % mtype)
|
print('factory: %s is not supported' % mtype)
|
||||||
return None
|
return None, mtype
|
||||||
|
@ -72,7 +72,7 @@ class TestDeepCleaning(unittest.TestCase):
|
|||||||
for subdir, dirs, files in os.walk(tempdir):
|
for subdir, dirs, files in os.walk(tempdir):
|
||||||
for f in files:
|
for f in files:
|
||||||
complete_path = os.path.join(subdir, f)
|
complete_path = os.path.join(subdir, f)
|
||||||
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))
|
print('[+] %s is clean inside %s' %(complete_path, p.filename))
|
||||||
|
Loading…
Reference in New Issue
Block a user