Gaudi Framework, version v20r4

Generated: 8 Jan 2009

gaudirun.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 #---------------------------------------------------------------------
00004 if __name__ == "__main__":
00005     import sys
00006     from optparse import OptionParser
00007     parser = OptionParser(usage = "%prog [options] <opts_file> ...")
00008     parser.add_option("-n","--dry-run", action="store_true",
00009                       help="do not run the application, just parse option files")
00010     parser.add_option("-p","--pickle-output", action="store", type="string",
00011                       metavar = "FILE",
00012                       help="DEPRECATED: use '--output file.pkl' instead. Write "
00013                            "the parsed options as a pickle file (static option "
00014                            "file)")
00015     parser.add_option("-v","--verbose", action="store_true",
00016                       help="print the parsed options")
00017     parser.add_option("--old-opts", action="store_true",
00018                       help="format printed options in old option files style")
00019     parser.add_option("--all-opts", action="store_true",
00020                       help="print all the option (even if equal to default)")
00021     def option_cb(option, opt, value, parser):
00022         """Add the option line to a list together with its position in the
00023         argument list.
00024         """
00025         parser.values.options.append((len(parser.largs), value))
00026     parser.add_option("--option", action="callback", callback=option_cb,
00027                       type = "string", nargs = 1,
00028                       help="add a single line (Python) option to the configuration." +
00029                            "All options lines are executed, one after the other, in " +
00030                            "the same context.")
00031     parser.add_option("--no-conf-user-apply", action="store_true",
00032                       help="disable the automatic application of configurable "
00033                            "users (for backward compatibility)")
00034     parser.add_option("-o", "--output", action = "store", type = "string",
00035                       help ="dump the configuration to a file. The format of "
00036                             "the options is determined by the extension of the "
00037                             "file name: .pkl = pickle, .py = python, .opts = "
00038                             "old style options. The python format cannot be "
00039                             "used to run the application and it contains the "
00040                             "same dictionary printed with -v")
00041     parser.add_option("--post-option", action="append", type="string",
00042                       dest="post_options",
00043                       help="Python options to be executed after the ConfigurableUser "
00044                            "are applied." 
00045                            "All options lines are executed, one after the other, in " +
00046                            "the same context.")
00047     parser.add_option("--debug", action="store_true",
00048                       help="enable some debug print-out")
00049 
00050     parser.set_defaults(options = [])
00051 
00052     opts, args = parser.parse_args() 
00053     
00054     # configure the logging
00055     import logging
00056     from GaudiKernel.ProcessJobOptions import InstallRootLoggingHandler
00057     
00058     if opts.old_opts: prefix = "// "
00059     else: prefix = "# "
00060     level = logging.INFO
00061     if opts.debug:
00062         level = logging.DEBUG
00063     InstallRootLoggingHandler(prefix, level = level)
00064     root_logger = logging.getLogger()
00065     
00066     if opts.pickle_output:
00067         if opts.output:
00068             root_logger.error("Conflicting options: use only --pickle-output or --output")
00069             sys.exit(1)
00070         else:
00071             root_logger.warning("--pickle-output is deprecated, use --output instead")
00072             opts.output = opts.pickle_output
00073     
00074     from Gaudi import gaudimain
00075     c = gaudimain()
00076 
00077     # Prepare the "configuration script" to parse (like this it is easier than
00078     # having a list with files and python commands, with an if statements that
00079     # decides to do importOptions or exec)
00080     options = [ "importOptions(%r)" % f for f in args ]
00081     # The option lines are inserted into the list of commands using their
00082     # position on the command line 
00083     optlines = list(opts.options)
00084     optlines.reverse() # this allows to avoid to have to care about corrections of the positions
00085     for pos, l in optlines:
00086         options.insert(pos,l)
00087     
00088     # "execute" the configuration script generated (if any)
00089     if options:
00090         g = {}
00091         l = {}
00092         exec "from Gaudi.Configuration import *" in g, l
00093         for o in options:
00094             logging.debug(o)
00095             exec o in g, l
00096     
00097     import GaudiKernel.Proxy.Configurable
00098     if opts.no_conf_user_apply:
00099         logging.info("Disabling automatic apply of ConfigurableUser")
00100         # pretend that they have been already applied
00101         GaudiKernel.Proxy.Configurable._appliedConfigurableUsers_ = True
00102     
00103     # This need to be done before dumping
00104     from GaudiKernel.Proxy.Configurable import applyConfigurableUsers
00105     applyConfigurableUsers()
00106     
00107     # Options to be processed after applyConfigurableUsers
00108     if opts.post_options:
00109         g = {}
00110         l = {}
00111         exec "from Gaudi.Configuration import *" in g, l
00112         for o in opts.post_options:
00113             logging.debug(o)
00114             exec o in g, l
00115     
00116     if opts.verbose:
00117         c.printconfig(opts.old_opts, opts.all_opts)
00118     if opts.output:
00119         c.writeconfig(opts.output, opts.all_opts)
00120     if not opts.dry_run:
00121         sys.exit(c.run())

Generated at Thu Jan 8 17:44:18 2009 for Gaudi Framework, version v20r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004