Gaudi Framework, version v21r4

Home   Generated: 7 Sep 2009

gaudirun.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 #---------------------------------------------------------------------
00004 if __name__ == "__main__":
00005     import os, 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     parser.add_option("--printsequence", action="store_true",
00050                       help="print the sequence")
00051     if not sys.platform.startswith("win"):
00052         # This option can be used only on unix platforms
00053         parser.add_option("-T", "--tcmalloc", action="store_true",
00054                           help="Use the Google malloc replacement. The environment "
00055                                "variable TCMALLOCLIB can be used to specify a different "
00056                                "name for the library (the default is libtcmalloc.so)")
00057     parser.set_defaults(options = [],
00058                         tcmalloc = False)
00059 
00060     opts, args = parser.parse_args() 
00061     
00062     # configure the logging
00063     import logging
00064     from GaudiKernel.ProcessJobOptions import InstallRootLoggingHandler
00065     
00066     if opts.old_opts: prefix = "// "
00067     else: prefix = "# "
00068     level = logging.INFO
00069     if opts.debug:
00070         level = logging.DEBUG
00071     InstallRootLoggingHandler(prefix, level = level)
00072     root_logger = logging.getLogger()
00073     
00074     # tcmalloc support
00075     if opts.tcmalloc:
00076         libname = os.environ.get("TCMALLOCLIB", "libtcmalloc.so")
00077         preload = os.environ.get("LD_PRELOAD", "")
00078         if libname not in preload:
00079             if preload:
00080                 preload += " "
00081             preload += libname
00082             os.environ["LD_PRELOAD"] = preload
00083             logging.info("Restarting with LD_PRELOAD='%s'", preload)
00084             # remove the --tcmalloc option from the arguments
00085             args = [ a for a in sys.argv if a != '-T' and not '--tcmalloc'.startswith(a) ]
00086             os.execv(sys.executable, [sys.executable] + args)
00087         else:
00088             logging.warning("Option --tcmalloc ignored because the library %s is "
00089                             " already in LD_PRELOAD.", libname)
00090     
00091     if opts.pickle_output:
00092         if opts.output:
00093             root_logger.error("Conflicting options: use only --pickle-output or --output")
00094             sys.exit(1)
00095         else:
00096             root_logger.warning("--pickle-output is deprecated, use --output instead")
00097             opts.output = opts.pickle_output
00098     
00099     from Gaudi import gaudimain
00100     c = gaudimain()
00101 
00102     # Prepare the "configuration script" to parse (like this it is easier than
00103     # having a list with files and python commands, with an if statements that
00104     # decides to do importOptions or exec)
00105     options = [ "importOptions(%r)" % f for f in args ]
00106     # The option lines are inserted into the list of commands using their
00107     # position on the command line 
00108     optlines = list(opts.options)
00109     optlines.reverse() # this allows to avoid to have to care about corrections of the positions
00110     for pos, l in optlines:
00111         options.insert(pos,l)
00112     
00113     # "execute" the configuration script generated (if any)
00114     if options:
00115         g = {}
00116         l = {}
00117         exec "from Gaudi.Configuration import *" in g, l
00118         for o in options:
00119             logging.debug(o)
00120             exec o in g, l
00121     
00122     import GaudiKernel.Proxy.Configurable
00123     if opts.no_conf_user_apply:
00124         logging.info("Disabling automatic apply of ConfigurableUser")
00125         # pretend that they have been already applied
00126         GaudiKernel.Proxy.Configurable._appliedConfigurableUsers_ = True
00127     
00128     # This need to be done before dumping
00129     from GaudiKernel.Proxy.Configurable import applyConfigurableUsers
00130     applyConfigurableUsers()
00131     
00132     # Options to be processed after applyConfigurableUsers
00133     if opts.post_options:
00134         g = {}
00135         l = {}
00136         exec "from Gaudi.Configuration import *" in g, l
00137         for o in opts.post_options:
00138             logging.debug(o)
00139             exec o in g, l
00140     
00141     if opts.verbose:
00142         c.printconfig(opts.old_opts, opts.all_opts)
00143     if opts.output:
00144         c.writeconfig(opts.output, opts.all_opts)
00145     if opts.printsequence:
00146         c.printsequence()
00147     if not opts.dry_run:
00148         sys.exit(c.run())

Generated at Mon Sep 7 18:05:34 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004