#!/usr/bin/env python # -*- coding: utf-8 -*- u"""Converts help facets of command elements into formatted HTML.""" # Copyright (c) 2004-2010 Jeremy Stanley . Permission # to use, copy, modify, and distribute this software is granted under # terms provided in the LICENSE file distributed with this software. from ConfigParser import RawConfigParser from sys import argv def sanitize_html(data): data = data.replace("&", "&") data = data.replace("<", "<") data = data.replace(">", ">") return data def show_command(command): output = "" output += "

\n" output += sanitize_html(command.split(":")[1]) output += " - " output += sanitize_html(commands.get(command, "description")) output += "\n

\n" output += "
\n" output += sanitize_html(commands.get(command, "help")).replace("$(eol)", "
\n") output += "\n
" outputlist = output.split("\n") output = "" for line in outputlist: if line.startswith(" "): counter = 0 for position in line: if position == " ": counter += 1 else: break line = line.replace(" ", " ", counter) output += line + "\n" return output commands = RawConfigParser() commands.read(argv[1]) normal_commands = [] admin_commands = [] for section in commands.sections(): if not section.startswith("__"): if commands.has_option(section, "administrative") and commands.getboolean(section, "administrative"): admin_commands.append(section) else: normal_commands.append(section) print "

\nNormal Commands\n

" normal_commands.sort() for command in normal_commands: print show_command(command) print "
\n

\nAdministrative Commands\n

" admin_commands.sort() for command in admin_commands: print show_command(command)