def generate_man(project, project_dir): """Generate man page rst docs for a project's installed scripts. This assumes that all the files in the 'bin' directory under the main project root are targeted scripts. """ docdir = os.path.join(project_dir, 'doc') gendir = os.path.join(docdir, 'generated') try: os.mkdir(gendir) except OSError as e: if e.errno != errno.EEXIST: raise print("Generating files for {} man pages in '{}'".format(project, gendir)) scripts = os.listdir(os.path.abspath(os.path.join(project_dir, 'bin'))) # Replace '-' with '_' due to python namespace contraints. generated_man_pages = [('%s.scripts.' % (project) + s.replace('-', '_'), s) for s in scripts] for module, script in generated_man_pages: rst = script + '.rst' # generate missing, generic man page rst docs if not os.path.isfile(os.path.join(docdir, 'man', rst)): with open(os.path.join(gendir, rst), 'w') as f: f.write( textwrap.dedent("""\ {header} {script} {header} .. include:: {script}/main_synopsis.rst .. include:: {script}/main_description.rst .. include:: {script}/main_options.rst """.format(header=('=' * len(script)), script=script))) force_symlink(os.path.join(gendir, rst), os.path.join(docdir, 'man', rst)) force_symlink(os.path.join(gendir, script), os.path.join(docdir, 'man', script)) ManConverter.regen_if_needed(gendir, module, out_name=script) _generate_custom(project, docdir, gendir)
def generate_man(project, project_dir): """Generate man page rst docs for a project's installed scripts. This assumes that all the files in the 'bin' directory under the main project root are targeted scripts. """ docdir = os.path.join(project_dir, 'doc') gendir = os.path.join(docdir, 'generated') print("Generating files for {} man pages in '{}'".format(project, gendir)) try: os.mkdir(gendir) except OSError as e: if e.errno != errno.EEXIST: raise scripts = os.listdir(os.path.abspath(os.path.join(project_dir, 'bin'))) # Replace '-' with '_' due to python namespace contraints. generated_man_pages = [ ('%s.scripts.' % (project) + s.replace('-', '_'), s) for s in scripts ] for module, script in generated_man_pages: rst = script + '.rst' # generate missing, generic man page rst docs if not os.path.isfile(os.path.join(docdir, 'man', rst)): with open(os.path.join(gendir, rst), 'w') as f: f.write(textwrap.dedent("""\ {header} {script} {header} .. include:: {script}/main_synopsis.rst .. include:: {script}/main_description.rst .. include:: {script}/main_options.rst """.format(header=('=' * len(script)), script=script))) os.symlink(os.path.join(gendir, rst), os.path.join(docdir, 'man', rst)) if not os.path.exists(os.path.join(docdir, 'man', script)): os.symlink(os.path.join(gendir, script), os.path.join(docdir, 'man', script)) ManConverter.regen_if_needed(gendir, module, out_name=script)
def generate_man(): print('Generating option and synopsis files for man pages') try: os.mkdir('generated') except OSError as e: if e.errno == errno.EEXIST: return raise bin_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'bin') scripts = os.listdir(bin_path) # Note that filter-env is specially specified, since the command is installed # as 'filter-env', but due to python namespace contraints, it uses a '_' # instead. generated_man_pages = [ ('pkgcore.scripts.' + s.replace('-', '_'), s) for s in scripts ] # generate man page option docs for module, script in generated_man_pages: os.symlink(os.path.join(os.pardir, 'generated', script), os.path.join('man', script)) ManConverter.regen_if_needed('generated', module, out_name=script)