00001
00002
00003 """
00004
00005 """
00006
00007 __copyright__ = """
00008 Copyright 2008 Sean Ross-Ross
00009 """
00010 __license__ = """
00011 This file is part of SLIMpy.
00012
00013 SLIMpy is free software: you can redistribute it and/or modify
00014 it under the terms of the GNU Lesser General Public License as published by
00015 the Free Software Foundation, either version 3 of the License, or
00016 (at your option) any later version.
00017
00018 SLIMpy is distributed in the hope that it will be useful,
00019 but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021 GNU Lesser General Public License for more details.
00022
00023 You should have received a copy of the GNU Lesser General Public License
00024 along with SLIMpy. If not, see <http://www.gnu.org/licenses/>.
00025 """
00026
00027 from optparse import Option,OptionParser
00028 from pickle import load
00029 import SLIMpy
00030 from slimpy_base.Core.Runners.dotRunner import dotRunner
00031 from slimpy_base.utils.Filters import DebugFilter,VerbosityFilter
00032 import re
00033
00034
00035 parser = OptionParser(usage="%prog [options] logfile")
00036
00037
00038 v_opt = Option( '-v' ,
00039 type=int,
00040 default=0,
00041 dest='verb' )
00042
00043
00044
00045
00046 allow_opt = Option('-a' ,
00047 dest='debug',
00048 action='append',
00049 )
00050
00051 node_opt = Option('-n' ,
00052 dest='node',
00053 action='append',
00054 )
00055
00056 proc_opt = Option('-p' ,
00057 dest='proc',
00058 type=int,
00059 action='append',
00060 )
00061
00062 dot_opt = Option( '--dot',
00063 action='store_true'
00064 )
00065
00066 list_opt = Option( '-l','--list',
00067 action='store_true'
00068 )
00069
00070 abr_opt = Option( '-b','--abridge',
00071 action='store_true',
00072 dest='abridge',
00073 default=False,
00074 )
00075
00076 time_opt = Option('-t','--time',
00077 action='store_true',
00078 )
00079
00080 cmd_opt = Option('--cmd',
00081 action='store_true',)
00082
00083 parser.add_option( v_opt )
00084
00085 parser.add_option( list_opt )
00086 parser.add_option( allow_opt )
00087 parser.add_option( node_opt )
00088 parser.add_option( proc_opt )
00089 parser.add_option( dot_opt )
00090 parser.add_option( abr_opt )
00091
00092 _re_kw = re.compile('(.*?)=(.*)')
00093 def split_args(args):
00094 p = []
00095 kw = {}
00096 for arg in args:
00097 items = _re_kw.findall(arg)
00098 if items:
00099 kw.update( items )
00100 else:
00101 p.append(arg)
00102
00103 return p,kw
00104
00105
00106 if __name__ == '__main__':
00107
00108 options, args = parser.parse_args()
00109
00110 p,kw = split_args(args)
00111
00112 if not p:
00113 parser.error("need file")
00114 file = p[0]
00115
00116 record = load( open(file) )
00117
00118 if options.list:
00119 record.print_filter_list()
00120
00121 elif options.dot:
00122 record._init_env()
00123 runner = dotRunner(record.command_records)
00124 runner.set_graph( record.graph )
00125 print runner.printDot( )
00126 else:
00127 vfilt = VerbosityFilter( options.verb )
00128 dfilt = DebugFilter( options.debug or set( ) )
00129
00130
00131 record.set_abridge( options.abridge )
00132
00133 record.add_filter( vfilt )
00134 record.add_filter( dfilt )
00135
00136 record.set_filter_type( 'any' )
00137
00138 record.print_log( )
00139
00140
00141
00142
00143
00144