discovery: handle deletion of 'wireproto' module
Mercurial commit b4d85bc122bd. deleted the wireproto module and its
contents are now in various other modules, so we can not even do
unchecked imports of it now.
#!/usr/bin/env pythonimportreimportosimportos.pathasopimportsysINDEX='''Mercurial tests===============.. toctree:: :maxdepth: 1'''ignored_patterns=[re.compile('^#if'),re.compile('^#else'),re.compile('^#endif'),re.compile('#rest-ignore$'),]defrstify(orig,name):newlines=[]code_block_mode=Falsesphinx_directive_mode=Falseforlineinorig.splitlines():# Emtpy lines doesn't change outputifnotline:newlines.append(line)code_block_mode=Falsesphinx_directive_mode=Falsecontinueignored=Falseforpatterninignored_patterns:ifpattern.search(line):ignored=Truebreakifignored:continue# Sphinx directives modeifline.startswith(' .. '):# Insert a empty line to makes sphinx happynewlines.append("")# And unindent the directiveline=line[2:]sphinx_directive_mode=True# Code modecodeline=line.startswith(' ')ifcodelineandnotsphinx_directive_mode:ifcode_block_modeisFalse:newlines.extend(['::',''])code_block_mode=Truenewlines.append(line)return"\n".join(newlines)defmain(base):ifos.path.isdir(base):one_dir(base)else:one_file(base)defone_dir(base):index=INDEX# doc = lambda x: op.join(op.dirname(__file__), 'docs', x)forfninsorted(os.listdir(base)):ifnotfn.endswith('.t'):continuename=os.path.splitext(fn)[0]content=one_file(op.join(base,fn))target=op.join(base,name+'.rst')# with file(doc(name + '.rst'), 'w') as f:withopen(target,'w')asf:f.write(content)index+='\n '+name# with file(doc('index.rst'), 'w') as f:# f.write(index)defone_file(path):name=os.path.basename(path)[:-2]returnrstify(open(path).read(),name)if__name__=='__main__':iflen(sys.argv)!=2:print('Please supply a path to tests dir as parameter')sys.exit()main(sys.argv[1])