mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
supybot-plugin-doc: Remove escape option; only used for Plone website
Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
parent
82db19754d
commit
5c2b493509
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
###
|
###
|
||||||
# Copyright (c) 2005, Ali Afshar
|
# Copyright (c) 2005, Ali Afshar
|
||||||
|
# Copyright (c) 2009, James Vega
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -59,7 +60,6 @@ import supybot.log as log
|
|||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
conf.supybot.flush.setValue(False)
|
conf.supybot.flush.setValue(False)
|
||||||
|
|
||||||
import cgi
|
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
@ -71,26 +71,14 @@ import supybot.registry as registry
|
|||||||
world.documenting = True
|
world.documenting = True
|
||||||
|
|
||||||
class PluginDoc(object):
|
class PluginDoc(object):
|
||||||
def __init__(self, mod, escape):
|
def __init__(self, mod):
|
||||||
self.mod = mod
|
self.mod = mod
|
||||||
self.inst = self.mod.Class(None)
|
self.inst = self.mod.Class(None)
|
||||||
self.name = self.mod.Class.__name__
|
self.name = self.mod.Class.__name__
|
||||||
self.escape = escape
|
|
||||||
self.lines = []
|
self.lines = []
|
||||||
|
|
||||||
def appendLine(self, line, indent=0, escaped=False):
|
def appendLine(self, line, indent=0):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if escaped and self.escape:
|
|
||||||
line = cgi.escape(line)
|
|
||||||
if self.escape:
|
|
||||||
sections = line.split("'")
|
|
||||||
slen = len(sections) - 1
|
|
||||||
# Don't want to escape characters inside of single-quoted strings
|
|
||||||
if slen and slen % 2 == 0:
|
|
||||||
for i in xrange(0, 2, slen):
|
|
||||||
sections[i] = sections[i].replace('[', '[')
|
|
||||||
sections[i] = sections[i].replace(']', ']')
|
|
||||||
line = "'".join(sections)
|
|
||||||
indent = ' ' * indent
|
indent = ' ' * indent
|
||||||
lines = textwrap.wrap(line, 79,
|
lines = textwrap.wrap(line, 79,
|
||||||
initial_indent=indent,
|
initial_indent=indent,
|
||||||
@ -104,19 +92,16 @@ class PluginDoc(object):
|
|||||||
self.appendLine('Purpose', 1)
|
self.appendLine('Purpose', 1)
|
||||||
pdoc = getattr(self.mod, '__doc__',
|
pdoc = getattr(self.mod, '__doc__',
|
||||||
'My author didn\'t give me a purpose.')
|
'My author didn\'t give me a purpose.')
|
||||||
self.appendLine(pdoc, 2, escaped=True)
|
self.appendLine(pdoc, 2)
|
||||||
cdoc = getattr(self.mod.Class, '__doc__', None)
|
cdoc = getattr(self.mod.Class, '__doc__', None)
|
||||||
if cdoc is not None:
|
if cdoc is not None:
|
||||||
self.appendLine('Usage', 1)
|
self.appendLine('Usage', 1)
|
||||||
self.appendLine(cdoc, 2, escaped=True)
|
self.appendLine(cdoc, 2)
|
||||||
commands = self.inst.listCommands()
|
commands = self.inst.listCommands()
|
||||||
if len(commands):
|
if len(commands):
|
||||||
self.appendLine('Commands', 1)
|
self.appendLine('Commands', 1)
|
||||||
for command in commands:
|
for command in commands:
|
||||||
log.debug('command: %s', command)
|
log.debug('command: %s', command)
|
||||||
if self.escape:
|
|
||||||
line = '* **%s** ' % command
|
|
||||||
else:
|
|
||||||
line = '* %s ' % command
|
line = '* %s ' % command
|
||||||
command = command.split()
|
command = command.split()
|
||||||
doc = self.inst.getCommandHelp(command)
|
doc = self.inst.getCommandHelp(command)
|
||||||
@ -126,8 +111,8 @@ class PluginDoc(object):
|
|||||||
args = args.split('(', 1)[1]
|
args = args.split('(', 1)[1]
|
||||||
args = args[len(' '.join(command)):].strip()
|
args = args[len(' '.join(command)):].strip()
|
||||||
help = help.split('--', 1)[1].strip()
|
help = help.split('--', 1)[1].strip()
|
||||||
self.appendLine(line + args, 2, escaped=True)
|
self.appendLine(line + args, 2)
|
||||||
self.appendLine(help, 3, escaped=True)
|
self.appendLine(help, 3)
|
||||||
else:
|
else:
|
||||||
self.appendLine('No help associated with this command', 3)
|
self.appendLine('No help associated with this command', 3)
|
||||||
# now the config
|
# now the config
|
||||||
@ -162,17 +147,13 @@ class PluginDoc(object):
|
|||||||
cv = 'is'
|
cv = 'is'
|
||||||
else:
|
else:
|
||||||
cv = 'is not'
|
cv = 'is not'
|
||||||
if self.escape:
|
|
||||||
default = '**%s**' % default
|
|
||||||
self.appendLine('This config variable defaults to %s and %s '
|
self.appendLine('This config variable defaults to %s and %s '
|
||||||
'channel specific.' % (default, cv), indent)
|
'channel specific.' % (default, cv), indent)
|
||||||
if self.escape:
|
|
||||||
help = cgi.escape(help)
|
|
||||||
self.appendLine(help, indent)
|
self.appendLine(help, indent)
|
||||||
self.genConfig(v, indent)
|
self.genConfig(v, indent)
|
||||||
|
|
||||||
def genDoc(m, escape):
|
def genDoc(m):
|
||||||
Plugin = PluginDoc(m, escape)
|
Plugin = PluginDoc(m)
|
||||||
print 'Generating documentation for %s...' % Plugin.name
|
print 'Generating documentation for %s...' % Plugin.name
|
||||||
try:
|
try:
|
||||||
fd = file('%s.stx' % Plugin.name, 'w')
|
fd = file('%s.stx' % Plugin.name, 'w')
|
||||||
@ -195,10 +176,6 @@ if __name__ == '__main__':
|
|||||||
parser.add_option('-c', '--clean', action='store_true', default=False,
|
parser.add_option('-c', '--clean', action='store_true', default=False,
|
||||||
dest='clean', help='Cleans the various data/conf/logs '
|
dest='clean', help='Cleans the various data/conf/logs '
|
||||||
'directories after generating the docs.')
|
'directories after generating the docs.')
|
||||||
parser.add_option('--no-escape',
|
|
||||||
action='store_false', default=True, dest='escape',
|
|
||||||
help='Disables escaping of html entities e.g., < as '
|
|
||||||
'<. This is useful for making offline documentation.')
|
|
||||||
parser.add_option('--plugins-dir',
|
parser.add_option('--plugins-dir',
|
||||||
action='append', dest='pluginsDirs', default=[],
|
action='append', dest='pluginsDirs', default=[],
|
||||||
help='Looks in in the given directory for plugins and '
|
help='Looks in in the given directory for plugins and '
|
||||||
@ -208,7 +185,6 @@ if __name__ == '__main__':
|
|||||||
# This must go before checking for args, of course.
|
# This must go before checking for args, of course.
|
||||||
for pluginDir in options.pluginsDirs:
|
for pluginDir in options.pluginsDirs:
|
||||||
for name in glob.glob(os.path.join(pluginDir, '*')):
|
for name in glob.glob(os.path.join(pluginDir, '*')):
|
||||||
#print '***', name
|
|
||||||
if os.path.isdir(name):
|
if os.path.isdir(name):
|
||||||
args.append(name)
|
args.append(name)
|
||||||
|
|
||||||
@ -234,7 +210,7 @@ if __name__ == '__main__':
|
|||||||
plugins.add(pluginModule)
|
plugins.add(pluginModule)
|
||||||
|
|
||||||
for Plugin in plugins:
|
for Plugin in plugins:
|
||||||
genDoc(Plugin, options.escape)
|
genDoc(Plugin)
|
||||||
|
|
||||||
if options.clean:
|
if options.clean:
|
||||||
shutil.rmtree(conf.supybot.directories.log())
|
shutil.rmtree(conf.supybot.directories.log())
|
||||||
|
Loading…
Reference in New Issue
Block a user