1
# Create HTML documentation from FreeCAD's Python modules and classes.
2
# (c) 2007 Werner Mayer
4
#***************************************************************************
5
#* Copyright (c) 2007 Werner Mayer <werner.wm.mayer@gmx.de> *
7
#* This file is part of the FreeCAD CAx development system. *
9
#* This program is free software; you can redistribute it and/or modify *
10
#* it under the terms of the GNU General Public License (GPL) *
11
#* as published by the Free Software Foundation; either version 2 of *
12
#* the License, or (at your option) any later version. *
13
#* for detail see the LICENCE text file. *
15
#* FreeCAD is distributed in the hope that it will be useful, *
16
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
17
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18
#* GNU Library General Public License for more details. *
20
#* You should have received a copy of the GNU Library General Public *
21
#* License along with FreeCAD; if not, write to the Free Software *
22
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
25
#***************************************************************************
27
import pydoc, pkgutil, sys, os, dircache, zipfile
30
# Get the path to the FreeCAD module relative to this directory
31
toolspath = os.path.dirname(__file__)
32
homepath = toolspath + '/../../'
33
homepath = os.path.realpath(homepath)
34
binpath = os.path.join(homepath, 'bin')
35
docpath = os.path.join(homepath, 'doc')
36
modpath = os.path.join(homepath, 'Mod')
38
# Change to the doc directory
40
print 'Change to ' + docpath
42
if os.path.exists('doc') == False:
46
# Add the bin path to the system path
48
os.environ['PATH'] = os.environ['PATH'] + ';' + binpath
50
os.environ['PATH'] = os.environ['PATH'] + ':' + binpath
52
# Import FreeCAD module
53
sys.path.append(binpath)
54
print 'Write documentation for module \'FreeCAD\''
55
pydoc.writedoc('FreeCAD')
59
ModDirs = dircache.listdir(modpath)
61
# Search for module paths and append them to Python path
63
# if (Dir != '__init__.py'):
64
# sys.path.append( os.path.join(modpath,Dir) )
66
# Walk through the module paths again and try loading the modules to create HTML files
68
dest = os.path.join(modpath,Dir)
69
print 'Write documentation for module \'' + Dir + '\''
70
if (Dir != '__init__.py'):
74
# Now we must create a document and create instances of all Python classes which
75
# cannot be directly created by a module.
77
# Create a ZIP archive from all HTML files
78
print 'Creating ZIP archive \'docs.zip\'...'
79
zip = zipfile.ZipFile('docs.zip', 'w')
80
for file in os.listdir('.'):
81
if not os.path.isdir(file):
82
if file.find('.html') > 0:
83
print ' Adding file ' + file + ' to archive'
89
# Remove all HTML files
90
print 'Cleaning up HTML files...'
91
for file in os.listdir('.'):
92
if not os.path.isdir(file):
93
if file.find('.html') > 0:
94
print ' Removing ' + file
100
def writedocs(dir, pkgpath='', done=None):
101
"""Write out HTML documentation for all modules in a directory tree."""
102
if done is None: done = {}
103
for importer, modname, ispkg in pkgutil.walk_packages([dir], pkgpath):
104
# Ignore all debug modules
105
if modname[-2:] != '_d':
106
pydoc.writedoc(modname)
109
if __name__ == "__main__":