1
0
mirror of synced 2024-11-06 01:18:51 +01:00

Improve the main.py file

This commit is contained in:
jvoisin 2018-04-02 19:12:10 +02:00
parent 23bd22b305
commit 0cc7e1e680

37
main.py
View File

@ -1,3 +1,4 @@
import os
import sys import sys
import mimetypes import mimetypes
from shutil import copyfile from shutil import copyfile
@ -5,6 +6,14 @@ import argparse
from src import parser_factory from src import parser_factory
def __check_file(filename:str, mode=os.R_OK) -> bool:
if not os.path.isfile(filename):
print("[-] %s is not a regular file." % filename)
return False
elif not os.access(filename, mode):
print("[-] %s is not readable and writeable." % filename)
return False
return True
def create_arg_parser(): def create_arg_parser():
parser = argparse.ArgumentParser(description='Metadata anonymisation toolkit 2') parser = argparse.ArgumentParser(description='Metadata anonymisation toolkit 2')
@ -20,30 +29,38 @@ def create_arg_parser():
return parser return parser
def show_meta(filename:str): def show_meta(filename:str):
if not __check_file(filename):
return
p, mtype = parser_factory.get_parser(filename) p, mtype = parser_factory.get_parser(filename)
if p is None: if p is None:
print("[-] %s's format (%s) is not supported" % (filename, mtype)) print("[-] %s's format (%s) is not supported" % (filename, mtype))
return return
print("[+] Metadata for %s:" % filename)
for k,v in p.get_meta().items(): for k,v in p.get_meta().items():
print(" %s: %s" % (k, v)) print(" %s: %s" % (k, v))
def clean_meta(filename:str):
if not __check_file(filename, os.R_OK|os.W_OK):
return
p, mtype = parser_factory.get_parser(f)
if p is None:
print("[-] %s's format (%s) is not supported" % (filename, mtype))
return
p.remove_all()
def main(): def main():
argparser = create_arg_parser() args = create_arg_parser().parse_args()
args = argparser.parse_args()
if args.show: if args.show:
for f in args.files: for f in args.files:
show_meta(f) show_meta(f)
return 0 else:
for f in args.files: for f in args.files:
p, mtype = parser_factory.get_parser(f) clean_meta(f)
if p is None:
print("[-] %s's format (%s) is not supported" % (f, mtype))
continue
p.remove_all()
if __name__ == '__main__': if __name__ == '__main__':
main() main()