00001 """
00002 define callbacks for the option parser
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 slimpy_base.Core.Runners.dotRunner import dotRunner
00027 from slimpy_base.Core.Runners.dottestRunner import dottestRunner
00028 from slimpy_base.Core.Runners.multicorerunner import MultiCoreRunner
00029 from slimpy_base.Environment.InstanceManager import InstanceManager
00030
00031 from optparse import OptionValueError
00032 from sys import modules
00033 from pdb import set_trace
00034
00035 __env__ = InstanceManager()
00036
00037
00038 def runner_callback( option, opt_str, value, parser ):
00039 """
00040 callback for option parser to set the runner class used by the graphmgr
00041 """
00042
00043 from slimpy_base.setup.default_options import options
00044
00045 if option == options['dot']:
00046 runner = dotRunner()
00047 parser.saw_dot = True
00048 elif option == options['dottest']:
00049 runner = dottestRunner()
00050
00051 elif option == options['multicore']:
00052 parser.values.jobs = int(value)
00053
00054 hosts = ['localhost']*int(value)
00055 __env__['slimvars']['NODELIST'] = hosts
00056 parser.values.NODELIST = hosts
00057
00058 runner = MultiCoreRunner()
00059 elif option == options['dist']:
00060
00061 __env__['slimvars']['NODEFILE'] = value
00062 parser.values.NODEFILE = value
00063 runner = MultiCoreRunner()
00064
00065 elif option == options['scons']:
00066 raise OptionValueError( "scons runner no longer supported" )
00067 else:
00068 raise OptionValueError( "unknown SLImpy runner for option parser use one of [dot,scons,dottest,jobs]" )
00069
00070 __env__['graphmgr'].setRunner( runner )
00071
00072 def builder_callback( option, opt_str, value, parser ):
00073 '''
00074 callback to set the builder
00075 '''
00076 from slimpy_base.Core.Builders.PipeBuilder import PipeBuilder
00077 __env__['graphmgr'].set_builder( PipeBuilder(chain=False) )
00078
00079 def opts_callback( option, opt_str, value, parser ):
00080 '''
00081 print options and exit
00082 '''
00083 main = modules['__main__']
00084 if hasattr(main, "options"):
00085 main_options = getattr(main, "options")
00086 for opt in main_options:
00087 print opt
00088 raise SystemExit
00089
00090
00091 def optest( option, opt_str, value, parser ):
00092 """
00093 run tests and exit
00094 """
00095 from slimpy_base.test_SLIMpy import test
00096 test()
00097 raise SystemExit, "tests completed"