1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
|
#
# $Id: appclass.py,v 1.7 2001/12/16 13:09:24 doughellmann Exp $
#
# Copyright Doug Hellmann 2000
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Doug
# Hellmann not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Command line application class for HappyDoc.
"""
__rcs_info__ = {
#
# Creation Information
#
'module_name' : '$RCSfile: appclass.py,v $',
'rcs_id' : '$Id: appclass.py,v 1.7 2001/12/16 13:09:24 doughellmann Exp $',
'creator' : 'Doug Hellmann <doug@hellfly.net>',
'project' : 'HappyDoc',
'created' : 'Sun, 13-Aug-2000 11:27:00 EDT',
#
# Current Information
#
'author' : '$Author: doughellmann $',
'version' : '$Revision: 1.7 $',
'date' : '$Date: 2001/12/16 13:09:24 $',
}
try:
__version__ = __rcs_info__['version'].split(' ')[1]
except:
__version__ = '0.0'
#
# Import system modules
#
import os
import glob
import sys
import types
import string
import re
import parser
import traceback
#
# Import Local modules
#
import happydoclib
#
# Module
#
True = 1
False = None
class HappyDoc(happydoclib.CommandLineApp.CommandLineApp):
"""
HappyDoc is a documentation generation/extraction tool which does
not depend on being able to import modules.
The data extraction library used by this app is based on the
Demos/parser/example.py module distributed with the Python source
distribution.
"""
shortArgumentsDescription = 'file...'
include_private_names = True
include_comments = True
output_directory = './doc'
output = None
author_name = 'Doug Hellmann <doug@hellfly.net>'
app_home = 'http://HappyDoc.sourceforge.net/'
package_description_file = 'README.txt'
recurse_into_subdirs=True
docset_type = None
docset_title = 'HappyDoc Generated Documentation'
#
# Define the docstring syntaxes supported
#
docstring_syntaxes = happydoclib.docstring.DocStringLoader()
#
# Define the output formats supported
#
supported_formats = happydoclib.formatter.FormatterLoader()
#
# Define the documentation set types supported
#
supported_docset_types = happydoclib.docset.DocSetLoader()
##
## Local methods
##
def appInit(self):
self._app_name = self.__class__.__name__
self._app_version = happydoclib.cvsProductVersion()
self.set_docset_type('MultiFile')
self.set_format('HTMLTable')
self._ignore_dir_patterns = []
self.addIgnoreDirectoryPattern('CVS', 'dist', 'build', 'doc', 'docs')
self.parser_function = happydoclib.parseinfo.getDocs
return
def addIgnoreDirectoryPattern(self, *dirNamePatterns):
"Add one or more directory name patterns to the list which should be ignored."
for dir_name_pattern in dirNamePatterns:
if dir_name_pattern not in self._ignore_dir_patterns:
self._ignore_dir_patterns.append(dir_name_pattern)
self.statusMessage('Ignoring %s' % dir_name_pattern, 2)
return
def ignoreDirectoryTest(self, dirName):
"""Determines whether 'dirName' matches pattern to be ignored.
Arguments
'dirName' -- Full path of the directory to be tested.
Returns true value if 'dirName' should be ignored, false value
otherwise.
"""
dir_base = happydoclib.path.basename(dirName)
if dir_base in self._ignore_dir_patterns:
return 1
else:
return 0
def set_format(self, format):
"Set the formatter to be used."
self.format = format
try:
self.formatter_factory = self.supported_formats[format]
except KeyError:
raise ValueError('format must be one of %s' \
% self.supported_formats.keys(),
format)
return
def set_docset_type(self, docset_type):
"Set the docset to be used."
self.docset_type = docset_type
try:
self.docset_factory = self.supported_docset_types[docset_type]
except KeyError:
raise ValueError('docset_type must be one of %s' % \
self.supported_docset_types.keys(),
docset_type)
return
##
## Override CommandLineApp methods
##
def _showOptionItemsDescription(self, title, items):
items.sort()
for name, obj in items:
if obj.__doc__:
description = str(obj.__doc__).strip()
else:
description = ''
print ' %s %s: %s\n' % (title, name, description)
return
def showVerboseSyntaxHelp(self):
"Overloaded to show supported docset and format types."
happydoclib.CommandLineApp.CommandLineApp.showVerboseSyntaxHelp(self)
print 'SUPPORTED DOCSTRING SYNTAXES:\n'
self._showOptionItemsDescription('SYNTAX TYPE', self.docstring_syntaxes.items())
print
print 'SUPPORTED FORMATS for -F Option:\n'
self._showOptionItemsDescription(
'FORMATTER TYPE', self.supported_formats.items())
print 'SUPPORTED DOCSET TYPES for -T Option:'
print
print ' %s' % happydoclib.happydocset.DocSet.__doc__
print
self._showOptionItemsDescription(
'DOCSET TYPE', self.supported_docset_types.items())
print
print 'PARSER ARGUMENTS:'
print
print ' Parser arguments control the default behavior of the'
print ' documentation extraction parser. Pass the argument'
print ' as an argument on the command line using the syntax:'
print
print ' parser_<argument>=value'
print
print ' Arguments:'
print
print ' docStringFormat -- Name of the docstring converter'
print ' format used in the inline documentation.'
print ' Defaults to "StructuredText".'
print
return
##
## Argument handlers
##
def optionHandler_author(self, authorNameAndEmail):
"""Specify the author identification to be inserted for
references.
"""
self.author_name = authorNameAndEmail
return
def optionHandler_d(self, outputDirectory):
"""Specify an outputDirectory.
Defaults to './doc'."""
self.output_directory = outputDirectory
return
def optionHandler_dia(self):
"""Generate UML diagram in Gnome dia format.
"""
self.set_docset_type("Dia")
self.set_format("Dia")
return
def optionHandler_F(self, format):
"""Specify the output format.
Defaults to 'HTMLTable'."""
self.set_format(format)
return
def optionHandler_i(self, ignoreDirectory):
"""Specify a directory basename to be ignored.
Use just the base name of the directory.
For instance, to ignore all directories
with the name CVS, specify: -i CVS.
Defaults to ignore::
CVS, dist, build, doc, docs.
"""
ignoreDirectory=string.strip(ignoreDirectory)
self.statusMessage('Adding ignore directive for %s' % ignoreDirectory)
self.addIgnoreDirectoryPattern(ignoreDirectory)
return
def optionHandler_no_comments(self):
"""Do not include comment text as though it was
a __doc__ string.
"""
self.include_comments = False
return
def optionHandler_no_private_names(self):
"Do not include names beginning with _."
self.include_private_names = False
return
def optionHandler_o(self):
"Specify that output should go to stdout."
self.set_docset_type('stdout')
return
def optionHandler_p(self, packageDescriptionFile):
"""Specify a file with a description of the package.
The default packageDescriptionFile is README.txt.
"""
self.package_description_file = packageDescriptionFile
return
def optionHandler_r(self):
"Disable recursion into subdirectories."
self.recurse_into_subdirs = False
return
def optionHandler_t(self, title):
"Specify a title for the documentation set."
self.docset_title = title
return
def optionHandler_T(self, docset_type):
"""Specify the documentation set type.
Defaults to 'multifile_docset'."""
self.set_docset_type(docset_type)
return
##
## Main
##
def main(self, *args):
self.statusMessage('%s version %s' % (self._app_name,
self._app_version))
#
# Debug info about where the docsets and formatters come from
#
self.statusMessage('Docstring converters from %s' % \
happydoclib.docstring.__path__[0], 1)
self.statusMessage('Docsets list from %s' % \
happydoclib.docset.__path__[0], 1)
self.statusMessage('Formatters from %s' % \
happydoclib.formatter.__path__[0], 1)
#
# Set default parser params
#
parser_params = {
'docStringFormat':'StructuredText',
}
#
# Find parser arguments
#
self.statusMessage('Looking for parser parameters', 2)
args, user_supplied_parser_params = happydoclib.optiontools.getParameters(
'parser', args)
parser_params.update(user_supplied_parser_params)
self.statusMessage('DEBUG: Parser parameters:', 4)
for p, v in parser_params.items():
self.statusMessage('DEBUG: \t%s:%s' % (p,v), 4)
#
# Find DocSet arguments
#
self.statusMessage('Looking for docset parameters', 2)
args, docset_params = happydoclib.optiontools.getParameters('docset', args)
self.statusMessage('DEBUG: Docset parameters:', 4)
for p, v in docset_params.items():
self.statusMessage('DEBUG: \t%s:%s' % (p,v), 4)
#
# Find Formatter parameters
#
self.statusMessage('Looking for formatter parameters', 2)
args, formatter_params = happydoclib.optiontools.getParameters('formatter', args)
self.statusMessage('DEBUG: Formatter parameters:', 4)
for p, v in formatter_params.items():
self.statusMessage('DEBUG: \t%s:%s' % (p,v), 4)
#
# Get the list of modules to input
#
input_modules = args
if not input_modules:
#
# No files specified, print a help message and exit.
#
self.showHelp('Specify input file(s) to be processed.')
raise self.HelpRequested, 'No input file(s) specified.'
#
# Create output directory
#
if not self.output:
od = self.output_directory
self.statusMessage('Output directory is %s' % self.output_directory, 2)
if (od[0] != '/'):
od = happydoclib.path.join( happydoclib.path.cwd(), od )
self.statusMessage('Setting output directory to %s' % od, 2)
od = happydoclib.path.normpath(od)
self.statusMessage('Creating output directory %s' % od, 2)
happydoclib.path.rmkdir(od)
self.output_directory = od
#
# Create the docset
#
docset_init_params = {
'formatterFactory':self.formatter_factory,
'parserFunc':self.parser_function,
'defaultParserConfigValues':parser_params,
'inputModuleNames':input_modules,
'author':self.author_name,
'outputBaseDirectory':self.output_directory,
'descriptionFilename':self.package_description_file,
'formatterParameters':formatter_params,
'ignoreDirFunc':self.ignoreDirectoryTest,
'includeComments':self.include_comments,
'includePrivateNames':self.include_private_names,
'statusMessageFunc':self.statusMessage,
'title':self.docset_title,
'useRecursion':self.recurse_into_subdirs,
}
docset_init_params.update(docset_params)
parsed_modules = apply( self.docset_factory, (), docset_init_params)
#
# Tell the docset to output its results
#
parsed_modules.write()
#
# Clean up
#
parsed_modules = None
return
|