00001 """
00002 function to gudie the user to useful things
00003 """
00004
00005 __copyright__ = """
00006 Copyright 2008 Sean Ross-Ross
00007 """
00008 __license__ = """
00009 This file is part of SLIMpy .
00010
00011 SLIMpy is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU Lesser General Public License as published by
00013 the Free Software Foundation, either version 3 of the License, or
00014 (at your option) any later version.
00015
00016 SLIMpy is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 GNU Lesser General Public License for more details.
00020
00021 You should have received a copy of the GNU Lesser General Public License
00022 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00023 """
00024
00025
00026 from inspect import ismodule, isclass, isroutine
00027 from itertools import count
00028
00029
00030
00031
00032 def shelp( *names ):
00033 """
00034 some other useful helper functions:
00035 listLinop() -> prints a list of all the linear operator classes
00036 listPlugins() -> print the plugins available ( ie. rsf )
00037 printglobal() -> prints all global variables in 'slimvars'
00038 """
00039 if not names:
00040 print "available help commands:"
00041 for item in globals():
00042
00043 if item.startswith( '_help_' ):
00044 print " ", repr( item[6:].replace( "_", " " ) )
00045 print
00046 print shelp.__doc__
00047
00048
00049 for name in names:
00050 try:
00051 name = str( name ).lower()
00052 name = name.replace( " ", "_" )
00053 _help_func = eval( '_help_%s' %name )
00054 except Exception:
00055 print
00056 print "No help for item,", repr( name ),
00057 print ". call _help() to see all available help commands."
00058 else:
00059 _help_func()
00060
00061
00062 is_slimpy = lambda value: value.__name__.startswith( 'SLIMpy' )
00063 no_ = lambda key: not key.startswith( '_' )
00064
00065 from slimpy_base.Core.User.linop.LinearOperatorType import LinearOperatorType
00066 opers = LinearOperatorType.LinearOperators.keys()
00067
00068 notoper = lambda key: key not in opers
00069
00070 def _help_whats_new():
00071 print
00072 print "This is new"
00073 print
00074
00075 def _help_modules():
00076
00077 print 'SLIMpy modules'
00078 print
00079
00080 key_func = lambda key, value: ismodule( value ) and is_slimpy( value ) and no_( key )
00081
00082 keydo = dict( _helphelper( key_func ) )
00083
00084 _format_keydo( keydo )
00085
00086 def _help_classes():
00087 print "SLIMpy classes:"
00088 print "for linear operator classes please use: listLinop( ) function"
00089 print
00090
00091
00092 key_func = lambda key, val: notoper( key ) and isclass( val ) and no_( key )
00093
00094 keydo = dict( _helphelper( key_func ) )
00095
00096 _format_keydo( keydo )
00097
00098 def _help_functions():
00099 print "list of slimpy functions"
00100
00101
00102
00103 key_func1 = lambda key, val: isroutine( val ) or ( not isclass( val ) and not ismodule( val ) )
00104 key_func = lambda key, val: notoper( key ) and key_func1( key, val ) and no_( key )
00105
00106 keydo = dict( _helphelper( key_func ) )
00107
00108 _format_keydo( keydo )
00109
00110 def _help_other():
00111 pass
00112
00113 def _format_keydo( keydo ):
00114
00115 longest = lambda a, b: len( a ) > len( b ) and a or b
00116 lnst = len( reduce( longest, keydo.keys() , "" ) )
00117 print
00118 for key, doc in keydo.iteritems():
00119 print key +" "+ "." *( lnst-len( key ) ) , "-",
00120 print doc
00121
00122 def _helphelper( key_func ):
00123
00124 import slimpy_base
00125
00126 for key, value in vars( SLIMpy ).iteritems():
00127 if key_func( key, value ):
00128 if value.__doc__ and value.__doc__.strip( "\n \t" ):
00129 doc = value.__doc__.strip( "\n \t" )
00130 ds = doc.splitlines()
00131 if ds > 1:
00132
00133 for i in count():
00134 if ds[i]:
00135 doc = ds[0] + " ..."
00136 break
00137 else:
00138 doc = ""
00139
00140 yield key, doc
00141