00001 '''
00002 genorate man file for slimproj
00003 '''
00004
00005
00006 __copyright__ = """
00007 Copyright 2008 Sean Ross-Ross
00008 """
00009 __license__ = """
00010 This file is part of SLIMpy .
00011
00012 SLIMpy is free software: you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as published by
00014 the Free Software Foundation, either version 3 of the License, or
00015 (at your option) any later version.
00016
00017 SLIMpy is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 GNU Lesser General Public License for more details.
00021
00022 You should have received a copy of the GNU Lesser General Public License
00023 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00024 """
00025
00026 from string import Template
00027 import sys
00028
00029 man_template = Template("""
00030 .TH SLIMPROJ 1 "${date}"
00031 .SH NAME
00032 slimproj \- SLIMpy tool for scons
00033
00034 .SH SYNOPSIS
00035 ${projec_doc}
00036 To include slinproj in a SCons file use
00037
00038 .ES
00039 from slimproj import *
00040 .EE
00041
00042 .B slimproj
00043 provides the following builder methods:
00044
00045 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
00046 '\" BEGIN GENERATED BUILDER DESCRIPTIONS
00047 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
00048
00049 ${BUILDERS}
00050
00051 .SS Construction Variables
00052
00053 A number of useful construction variables are automatically defined by
00054 scons for each supported platform, and additional construction variables
00055 can be defined by the user. The following is a list of the automatically
00056 defined construction variables:
00057 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
00058 '\" BEGIN GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
00059 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
00060 ${VARIABLES}
00061 """)
00062
00063 func_template = Template("""
00064 .IP ${name}()
00065 .IP env.${name}()
00066 ${doc}
00067 ${params}
00068 ${example}${author}
00069 """
00070 )
00071
00072 example_tem = Template("""
00073 .B Example:
00074
00075 .ES
00076 ${example}
00077 .EE
00078 """ )
00079
00080 authorstr = "\n.B Author:\n%s"
00081 params_tem = Template("\n\n.B PARAMETERS:\n${params}\n\n")
00082
00083 def genorate_man():
00084 '''
00085 genorate_man() -> str
00086 '''
00087 import slimproj
00088 from slimproj_core.builders.CreateBuilders import Default_SLIM_Builders
00089
00090 from slimpy_base import env
00091
00092
00093
00094
00095 slimvars = env['slimvars']
00096
00097 keys = slimvars.slimGlobals.keys()
00098 keys.sort()
00099
00100 manafie = lambda key,doc: """\n.IP %s\n%s""" %(key,doc)
00101
00102 VARIABLES =[]
00103 push = VARIABLES.append
00104 for key in keys:
00105 doc = slimvars.slimdoc.get( key, "No documentation")
00106 item = manafie( key, doc )
00107 push(item)
00108
00109
00110
00111 BUILDERS = []
00112 push = BUILDERS.append
00113 esub = lambda ex: example_tem.substitute( example=ex.replace('\n ','\n').replace('\n','\n ') )
00114
00115 bldr_keys = Default_SLIM_Builders.keys()
00116 bldr_keys.sort()
00117
00118 for key in bldr_keys:
00119 builder = Default_SLIM_Builders[key]
00120 execfunc = builder.action.execfunction
00121
00122 doc = hasattr(execfunc,"__doc__") and execfunc.__doc__ and execfunc.__doc__.strip() or "No Doc\n"
00123 doc = doc.replace('\n ','\n')
00124 doc = doc.replace('\n','\n ')
00125
00126 example = hasattr(execfunc,"__example__") and esub( execfunc.__example__ ) or ""
00127
00128
00129 if hasattr(execfunc, '__additional_dependancies__'):
00130 params = getattr(execfunc, '__additional_dependancies__')
00131 params = ",\n".join(params)
00132 params = params_tem.substitute(params=params)
00133 else:
00134 params= ""
00135
00136 emod = sys.modules[execfunc.__module__]
00137 if hasattr(emod, '__author__'):
00138 author = authorstr %emod.__author__
00139 else:
00140 author = ""
00141
00142 func =func_template.substitute(name=key,example=example,
00143 doc=doc,
00144 author=author,
00145 params=params)
00146
00147 push(func)
00148
00149
00150 mmm = dict()
00151 import time
00152
00153 mmm['date'] = time.strftime( "%m/%y")
00154 mmm['projec_doc'] = slimproj.__doc__
00155 mmm['BUILDERS'] = "\n".join(BUILDERS)
00156 mmm['VARIABLES'] = "\n".join(VARIABLES)
00157
00158 return man_template.substitute( **mmm)
00159