Changeset 4415

Show
Ignore:
Timestamp:
03/29/09 20:01:14 (4 years ago)
Author:
nopper
Message:

Added documentation to PM. Thanks to luis for the patch :)

Location:
branch/PacketManipulator
Files:
4 added
1 modified

Legend:

Unmodified
Added
Removed
  • branch/PacketManipulator/setup.py

    r3693 r4415  
    1919# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
    2020 
     21import re 
    2122import sys 
    2223import glob 
    23 import os, os.path 
     24 
     25import os 
     26import os.path 
    2427 
    2528from distutils.core import setup, Extension 
    2629from distutils.command.install import install 
     30from distutils.command.build import build 
    2731from PM.Core.Const import PM_VERSION, PM_SITE 
     32 
     33BASE_DOCS_DIR = os.path.join('share', 'doc', 'PacketManipulator-%s' % PM_VERSION) 
     34DOCS_DIR = os.path.join('generated-doc', 'html') 
    2835 
    2936def getoutput(cmd): 
     
    123130    targetpath = os.path.dirname(os.path.join("share/locale",lang)) 
    124131    mo_files.append((targetpath, [filepath])) 
     132 
     133class pm_build(build): 
     134    def build_html_doc(self): 
     135        """Build the html documentation.""" 
     136 
     137        try: 
     138            import sphinx 
     139        except ImportError: 
     140            self.warn("sphinx not found, documentation won't be build.") 
     141            return 
     142 
     143        sphinx_ver = sphinx.__version__ 
     144        def digits(x): 
     145            res = re.match('\d+', x) 
     146            if res is None: 
     147                return 0 
     148            else: 
     149                return int(res.group()) 
     150        if map(digits, sphinx_ver.split('.')) < [0, 5, 1]: 
     151            self.warn("Sphinx's version is too old (%s, expected at least " 
     152                      "0.5.1, documentation won't be build." % sphinx_ver) 
     153            return 
     154 
     155        # Build the documentation just like it is done through the Makefile 
     156        sphinx.main([__file__, 
     157            "-b", "html", 
     158            "-d", os.path.join("PM", "share", "doc", "doctrees"), 
     159            os.path.join("PM", "share", "doc", "src"), DOCS_DIR]) 
     160     
     161    def run(self): 
     162        self.build_html_doc() 
     163        build.run(self) 
    125164 
    126165class pm_install(install): 
     
    221260                      'PM.higwidgets' 
    222261                     ], 
    223       data_files   = [('share/pixmaps/umit', glob.glob("PM/share/pixmaps/umit/*"))] + mo_files,  
     262      data_files   = [('share/pixmaps/umit', 
     263                       glob.glob("PM/share/pixmaps/umit/*")), 
     264                      (BASE_DOCS_DIR, glob.glob(DOCS_DIR + "/*/*")), 
     265                     ] + mo_files,  
    224266      scripts      = ['PM/PacketManipulator'], 
    225267      ext_modules  = modules, 
    226       cmdclass     = {'install' : pm_install} 
     268      cmdclass     = {'install' : pm_install, 
     269                      'build' : pm_build} 
    227270)