LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
run.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 #
4 # LSST Data Management System
5 # Copyright 2008, 2009, 2010 LSST Corporation.
6 #
7 # This product includes software developed by the
8 # LSST Project (http://www.lsst.org/).
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the LSST License Statement and
21 # the GNU General Public License along with this program. If not,
22 # see <http://www.lsstcorp.org/LegalNotices/>.
23 #
24 
25 
26 from __future__ import with_statement
27 import re, sys, os
28 
29 import lsst.pex.exceptions as pexExcept
30 from lsst.pex.logging import Log
31 from lsst.pex.policy import Policy
32 
33 msglev = { "silent": -30,
34  "quiet": -10,
35  "info": 0,
36  "trace": 1,
37  "verb1": 1,
38  "verb2": 2,
39  "verb3": 3,
40  "debug": 10,
41  "policy": None,
42  "none": None }
43 
44 pkgdirvar = "PEX_HARNESS_DIR"
45 
47  """
48  An error occurred while processing user input or environment at the
49  initial stages of the execution of a script.
50  """
51  pass
52 
54  """
55  An error occurred while processing the scripts command-line arguments.
56  Typically, when this exception is caught, the message is printed along
57  with the script usage line, and then the script exits.
58  """
59  pass
60 
61 
62 def addVerbosityOption(clparser, shortopt="L", dest="verbosity"):
63  """
64  add a command-line option that control message verbosity
65  """
66  clparser.add_option("-"+shortopt, "--log-verbosity", type="str",
67  action="store", dest=dest, default=None,
68  metavar="lev",
69  help="string or integer message verbosity level level for the pipeline: silent=-21, quiet=-10, info=0, trace=1, verb1=1, verb2=2, verb3=3, debug=10, policy=consult policy")
70 
71 def addAllVerbosityOptions(clparser, shortopt="L", dest="verbosity"):
72  """
73  add command-line options that control message verbosity. This adds the
74  --log-verbosity option (via addVerbosityOption()) along with several extra
75  convenience options (-v, -q, -s, -d)
76  """
77  addVerbosityOption(clparser, shortopt, dest)
78  clparser.add_option("-d", "--debug", action="store_const", const='debug',
79  dest=dest, help="print maximum amount of messages")
80  clparser.add_option("-v", "--verbose", action="store_const", const='verb3',
81  dest=dest,
82  help="print extra messages (same as -L verb3)")
83  clparser.add_option("-q", "--quiet", action="store_const", const='quiet',
84  dest=dest, help="print only warning & error messages")
85  clparser.add_option("-s", "--silent", action="store_const", const='silent',
86  dest=dest, help="print nothing (if possible)")
87 
88 
89 def verbosity2threshold(level, defthresh=None):
90  """convert the requested verbosity level into a logging threshold.
91  The input level can be given as a logical name or an integer. An integer
92  verbosity level is the negative of the required threshold.
93  """
94  if level is None: return defthresh
95 
96  if isinstance(level, str):
97  level = level.lower()
98  if msglev.has_key(level):
99  level = msglev[level]
100  else:
101  try:
102  level = int(level)
103  except:
104  msg = """Unrecognized verbosity level: %s
105  Give integer or one of (silent,quiet,info,trace,verb1,verb2,verb3,debug)"""
106  raise UsageError(msg % level)
107 
108  elif not isinstance(level, int):
109  raise UsageError, "Verbosity level is not an integer or string"
110 
111  if level is None:
112  return defthresh
113 
114  return -1 * level
115 
116 def createLog():
117  log = Log(Log.getDefaultLog(), "harness.run.launchPipeline")
118  return log
119 
120 
121 def launchPipeline(policyFile, runid, workerid=None, name=None, verbosity=None, logdir=None):
122  if not os.environ.has_key(pkgdirvar):
123  raise RuntimeError(pkgdirvar + " env. var not setup")
124 
125  logger = createLog()
126 
127  logger.log(Log.INFO, "policyFile " + policyFile)
128  logger.log(Log.INFO, "runid " + runid)
129 
130  if(workerid == None):
131  logger.log(Log.INFO, "workerid is None")
132  else:
133  logger.log(Log.INFO, "workerid " + workerid)
134 
135  if(name == None):
136  logger.log(Log.INFO, "name is None")
137  else:
138  logger.log(Log.INFO, name)
139 
140  if(verbosity == None):
141  logger.log(Log.INFO, "verbosity is None")
142  else:
143  logger.log(Log.INFO, verbosity)
144 
145  clineOptions = ""
146  if name is not None:
147  clineOptions += " -n %s" % name
148 
149  if verbosity is not None:
150  clineOptions += " -V %s" % verbosity
151 
152  if workerid is not None:
153  clineOptions += " -w %s" % workerid
154 
155  clineOptions += " -g %s" % logdir
156 
157  cmd = "runPipelin.sh.py %s %s %s" % \
158  (clineOptions, policyFile, runid)
159 
160  logger.log(Log.INFO, "CMD to execute:")
161  logger.log(Log.INFO, cmd)
162 
163  os.execvp("runPipeline.py", cmd.split())
164 
165  raise RuntimeError("Failed to exec runPipeline.py")
166 
167 
def verbosity2threshold
Definition: run.py:89
a place to record messages and descriptions of the state of processing.
Definition: Log.h:154
def addVerbosityOption
Definition: run.py:62
def addAllVerbosityOptions
Definition: run.py:71