~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Tools/pythondoc.py

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Create HTML documentation from FreeCAD's Python modules and classes.
 
2
# (c) 2007 Werner Mayer
 
3
#
 
4
#***************************************************************************
 
5
#*   Copyright (c) 2007 Werner Mayer <werner.wm.mayer@gmx.de>              *
 
6
#*                                                                         *
 
7
#*   This file is part of the FreeCAD CAx development system.              *
 
8
#*                                                                         *
 
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.                                 *
 
14
#*                                                                         *
 
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.                  *
 
19
#*                                                                         *
 
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  *
 
23
#*   USA                                                                   *
 
24
#*                                                                         *
 
25
#***************************************************************************
 
26
 
 
27
import pydoc, pkgutil, sys, os, dircache, zipfile
 
28
 
 
29
def generateDoc():
 
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')
 
37
 
 
38
                # Change to the doc directory
 
39
                cwd = os.getcwd()
 
40
                print 'Change to ' + docpath
 
41
                os.chdir(homepath)
 
42
                if os.path.exists('doc') == False:
 
43
                                os.mkdir('doc')
 
44
                os.chdir('doc')
 
45
 
 
46
                # Add the bin path to the system path
 
47
                if os.name == 'nt':
 
48
                                os.environ['PATH'] = os.environ['PATH'] + ';' + binpath
 
49
                else:
 
50
                                os.environ['PATH'] = os.environ['PATH'] + ':' + binpath
 
51
        
 
52
                # Import FreeCAD module
 
53
                sys.path.append(binpath)
 
54
                print 'Write documentation for module \'FreeCAD\''
 
55
                pydoc.writedoc('FreeCAD')
 
56
                print ''
 
57
        
 
58
                # Module directory
 
59
                ModDirs = dircache.listdir(modpath)
 
60
 
 
61
                # Search for module paths and append them to Python path 
 
62
                #for Dir in ModDirs:
 
63
                #       if (Dir != '__init__.py'):
 
64
                #                       sys.path.append( os.path.join(modpath,Dir) )
 
65
 
 
66
                # Walk through the module paths again and try loading the modules to create HTML files 
 
67
                for Dir in ModDirs:
 
68
                                dest = os.path.join(modpath,Dir)
 
69
                                print 'Write documentation for module \'' + Dir + '\''
 
70
                                if (Dir != '__init__.py'):
 
71
                                                writedocs(dest)
 
72
                                                print ''
 
73
                                                
 
74
                # Now we must create a document and create instances of all Python classes which
 
75
                # cannot be directly created by a module.
 
76
 
 
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'
 
84
                                                                zip.write(file)
 
85
        
 
86
                print 'done.'
 
87
                zip.close()
 
88
        
 
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
 
95
                                                                os.remove(file)
 
96
                
 
97
                os.chdir(cwd)
 
98
                print 'done.'
 
99
 
 
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)
 
107
    return
 
108
 
 
109
if __name__ == "__main__":
 
110
                generateDoc()