00001 __copyright__ = """
00002 Copyright 2008 Sean Ross-Ross
00003 """
00004 __license__ = """
00005 This file is part of SLIMpy .
00006
00007 SLIMpy is free software: you can redistribute it and/or modify
00008 it under the terms of the GNU Lesser General Public License as published by
00009 the Free Software Foundation, either version 3 of the License, or
00010 (at your option) any later version.
00011
00012 SLIMpy is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 GNU Lesser General Public License for more details.
00016
00017 You should have received a copy of the GNU Lesser General Public License
00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00019 """
00020
00021 from slimproj_core.builders.BuilderFunctions import DEFAULT_PROFILES
00022
00023 def tracker_emitter( target, source, env):
00024
00025 source.extend(DEFAULT_PROFILES)
00026
00027 return target, source
00028
00029
00030
00031 from hotshot.stats import load
00032 from sys import modules
00033 from os.path import split, splitext
00034 from inspect import ismodule, isclass,isroutine
00035 import pickle
00036
00037 def catigorize( table, obj_name,obj, stats, optional_doc ):
00038
00039 if isclass(obj):
00040 type = 'Class'
00041 mod = modules[obj.__module__]
00042 elif ismodule(obj):
00043 type = 'Module'
00044 mod = obj
00045
00046 dir,file = split( mod.__file__ )
00047 name,ext = splitext( file )
00048
00049
00050
00051
00052 method_tuples, msg = stats.eval_print_amount(name, stats.fcn_list[:], '')
00053
00054
00055 tested_methods = set([ name for file,line,name in method_tuples])
00056
00057
00058 all_methods = set([ key for key,val in obj.__dict__.iteritems() if isroutine(val) ])
00059 tested_methods.intersection_update( all_methods )
00060
00061
00062
00063
00064
00065
00066
00067 section = table.setdefault("%(obj_name)s" %vars() ,{})
00068 section['all_methods'] = all_methods
00069 section['tested_methods'] = tested_methods
00070 section[ 'doc' ] = optional_doc
00071
00072 return
00073
00074 def tracker_builder( target, source, env ):
00075
00076
00077 str_src = [str(src) for src in source ]
00078
00079 table = {}
00080 f = open(str(target[0]), 'w')
00081
00082 if str_src:
00083
00084
00085
00086 stat = load( str_src[0] )
00087 for src in str_src[1:]:
00088 stat.add( load( src ) )
00089
00090 stat.strip_dirs( )
00091 stat.sort_stats( 'module' )
00092
00093
00094
00095
00096 from inspect import isfunction,isclass,ismethod
00097 from sys import modules
00098 import slimpy_base
00099
00100 is_slim_mod = lambda mod : mod.startswith("SLIMpy")
00101
00102 slim_mods = [ mod for key,mod in modules.iteritems() if is_slim_mod(key) ]
00103 profile_classes = { }
00104 class_set = set()
00105
00106 for mod in slim_mods:
00107 for item in dir(mod):
00108 atr = getattr(mod, item)
00109 if isclass(atr) and is_slim_mod(atr.__module__):
00110 class_set.add( atr )
00111
00112 for klass in class_set:
00113 (klass, doc) = profile_classes.setdefault(klass.__name__, (klass, {}) )
00114 for method in klass.__dict__.values():
00115 if hasattr(method, "__note__"):
00116 note = getattr(method, "__note__")
00117
00118 doc[method.__name__] = note
00119
00120
00121
00122 for name, (klass, doc) in profile_classes.iteritems():
00123
00124 catigorize( table,name, klass, stat, doc )
00125
00126
00127
00128 else:
00129 pass
00130
00131 pickle.dump( table, f )
00132
00133
00134 return
00135