1
0
mirror of synced 2024-11-22 09:14:23 +01:00

Improve the cli

- Implement the `-l` option
- The help is now more awesome
This commit is contained in:
jvoisin 2018-04-03 23:57:13 +02:00
parent 1d6559596d
commit afeb3753a8
2 changed files with 21 additions and 7 deletions

15
main.py
View File

@ -44,21 +44,30 @@ def clean_meta(filename:str):
if not __check_file(filename, os.R_OK|os.W_OK):
return
p, mtype = parser_factory.get_parser(f)
p, mtype = parser_factory.get_parser(filename)
if p is None:
print("[-] %s's format (%s) is not supported" % (filename, mtype))
return
p.remove_all()
def main():
args = create_arg_parser().parse_args()
arg_parser = create_arg_parser()
args = arg_parser.parse_args()
if args.show:
for f in args.files:
show_meta(f)
else:
elif args.list:
print('[+] Supported formats:')
for parser in parser_factory._get_parsers():
for mtype in parser.mimetypes:
extensions = ', '.join(mimetypes.guess_all_extensions(mtype))
print(' - %s (%s)' % (mtype, extensions))
elif args.files:
for f in args.files:
clean_meta(f)
else:
arg_parser.print_help()
if __name__ == '__main__':

View File

@ -16,12 +16,17 @@ for module_loader, name, ispkg in pkgutil.walk_packages('.src'):
continue
importlib.import_module(name)
def _get_parsers() -> list:
""" Get all our parsers!"""
def __get_parsers(cls):
return cls.__subclasses__() + \
[g for s in cls.__subclasses__() for g in __get_parsers(s)]
return __get_parsers(abstract.AbstractParser)
def get_parser(filename: str) -> (T, str):
mtype, _ = mimetypes.guess_type(filename)
def get_subclasses(cls):
return cls.__subclasses__() + \
[g for s in cls.__subclasses__() for g in get_subclasses(s)]
for c in get_subclasses(abstract.AbstractParser):
for c in _get_parsers():
if mtype in c.mimetypes:
return c(filename), mtype
return None, mtype