Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/tools/docs/issue_finder.py
Views: 11768
import os1import sys2import argparse3import datetime45try:6import glob7except ImportError:8print("Please install glob package")9sys.exit()1011if sys.version_info[0] < 3:12raise Exception("Must be using Python 3")1314parser = argparse.ArgumentParser(description='This script identifies issues with module documentation, including missing documentation, and incorrect file names. Output is in markdown format.',15prefix_chars='--', )16parser.add_argument('-m', '--modules', type=str, default='auxiliary/scanner', help='Choose the modules category to work with. Respect the module category names as in metasploit-framework. Only one category should be passed, e.g. "auxiliary/admin", "exploits/android/browser" or "encoders" are valid entries.')17parser.add_argument('--show_all', action="store_true", default=False, help='Show the complete list of items. In default mode, modules with documentation are marked "[x]" and modules without are marked "[ ]". In issues mode, documentation files without module are marked "[ ]" and documentation files with module are marked "[x]".')18parser.add_argument('--show_issues', action="store_true", default=False, help='Show the list of documentation files without modules instead of modules without documentation file.')19parser.add_argument('-o', '--output', help="Writes to a file.")20args = parser.parse_args()2122module_type = args.modules23show_all = args.show_all24show_issues = args.show_issues2526modules = []27docs = []28path = os.path.abspath(os.path.join(os.path.realpath(__file__),"..","..",".."))2930if os.path.exists(os.path.join(path, 'modules', module_type)):31list_docs = glob.glob(os.path.join(path,'documentation/modules', module_type, '**/*.md'), recursive=True)32list_modules = glob.glob(os.path.join(path, 'modules', module_type, '**/*.*'),recursive=True)33else:34print("Path doesn't exist. Maybe you have passed a wrong module category or maybe there isn't any documentation file yet.")35sys.exit()3637for doc in list_docs:38docs.append(doc.split('.')[0].replace('/documentation/','/'))39for module in list_modules:40# skip compiled python code, and python internal use files41if module.split('.')[1] == 'pyc': continue42if '/_' in module.split('.')[0]: continue43modules.append(module.split('.')[0])4445missings = 046problems = 047count = 048root = 'metasploit-framework'49url_root = 'https://github.com/rapid7/metasploit-framework/blob/master/modules/'5051if args.output:52o = open(args.output, 'w')5354def print_or_write(line):55if args.output:56o.write("%s\n" %(line))57return58print(line)5960def make_link(line):61# first we wenat to get the extension back62for m in list_modules:63if "%s." %(line) in m:64ext = m65break66link = ext.split("/modules")[1]67#link = ext.replace("/modules", url_root)68return "[%s%s](%s%s)" %(root, line, url_root, link)6970print_or_write('# Documentation Issue Finder\n')71print_or_write('Generated: %s\n' %(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))7273if not (show_all):74if not (show_issues):75print_or_write('## Modules Without Documentation\n')76for i in sorted(modules):77if i not in docs:78missings += 179print_or_write('+ [ ] %s' %(make_link(i.split('metasploit-framework')[1])))80print_or_write('\n%s modules have no documentation.' %(missings))81else:82print_or_write('## Docs Without Modules\n')83for i in sorted(docs):84if i not in modules:85problems += 186print_or_write('+ [ ] %s' %(make_link(i.split('metasploit-framework')[1])))87print_or_write('\n%s doc files do not correspond to any module.' %(problems))88else:89count = 090if not (show_issues):91print_or_write('## Modules Without Documentation\n')92for i in sorted(modules):93if i in docs:94print_or_write('+ [x] %s' %(make_link(i.split('metasploit-framework')[1])))95else:96print_or_write('+ [ ] %s' %(make_link(i.split('metasploit-framework')[1])))97count += 198print_or_write('\n%s modules out of %s (%d%%) have no documentation.' %(count, len(modules), float(count)/len(modules) * 100.0))99else:100print_or_write('## Docs Without Modules\n')101for i in sorted(docs):102if i in modules:103print_or_write('+ [x] %s' %(make_link(i.split('metasploit-framework')[1])))104else:105print_or_write('+ [ ] %s' %(make_link(i.split('metasploit-framework')[1])))106count += 1107print_or_write('\n%s doc files out of %s do not correspond to any module.' %(count, len(docs)))108109if args.output:110o.close()111112113