Improve the cli
- Implement the `-l` option - The help is now more awesome
This commit is contained in:
parent
1d6559596d
commit
afeb3753a8
15
main.py
15
main.py
@ -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__':
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user