test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
crabWrapper.py
Go to the documentation of this file.
1 import sys
2 import os
3 import subprocess
4 from TkAlExceptions import AllInOneError
5 
6 # script which needs to be sourced for use of crab
7 crabSourceScript = '/afs/cern.ch/cms/ccs/wm/scripts/Crab/crab.sh'
8 
9 # source the environment variables needed for crab
10 sourceStr = ( 'cd $CMSSW_BASE/src;'
11  'source /afs/cern.ch/cms/LCG/LCG-2/UI/cms_ui_env.sh;'
12  'eval `scramv1 runtime -sh`;'
13  'source ' + crabSourceScript + ' && env' )
14 sourceCmd = ['bash', '-c', sourceStr ]
15 sourceProc = subprocess.Popen(sourceCmd, stdout = subprocess.PIPE)
16 for line in sourceProc.stdout:
17  (key, _, value) = line.partition("=")
18  os.environ[key] = value.replace("\n","")
19 sourceProc.communicate()
20 
21 # source variables from crab wrapper script
22 crabFile = open('/'.join([os.environ["CRABPYTHON"],'crab']))
23 theLines = crabFile.readlines()
24 theLine = []
25 for line in theLines:
26  if ( line[0] == '#' ) or \
27  ( line == ' python $CRABPYTHON/crab.py $*\n' ):
28  continue
29  theLine.append( line )
30 tempFilePath = "tempCrab"
31 tempFile = open( tempFilePath, "w" )
32 tempFile.write( ''.join(theLine) )
33 tempFile.close()
34 crabStr = ('source tempCrab && env' )
35 crabCmd = ['bash', '-c', crabStr ]
36 crabProc = subprocess.Popen(crabCmd, stdout = subprocess.PIPE)
37 for line in crabProc.stdout:
38  (key, _, value) = line.partition("=")
39  os.environ[key] = value.replace("\n","")
40 crabProc.communicate()
41 os.remove( tempFilePath )
42 
43 # add sourced paths to search path of python
44 sys.path.extend( os.environ["PYTHONPATH"].split( ':' ) )
45 
46 import crab
47 import crab_exceptions
48 
50  def __init__( self ):
51  pass
52 
53  def run( self, options ):
54  theCrab = crab.Crab()
55  try:
56  theCrab.initialize_( options )
57  theCrab.run()
58  except crab_exceptions.CrabException as e:
59  raise AllInOneError( str( e ) )
60  del theCrab
61 
62 
63 if __name__ == "__main__":
64  theCrab = CrabWrapper()
65  theCrabOptions = {"-create":"",
66  "-cfg":"TkAlOfflineValidation.shiftPlots.crab.cfg"}
67  theCrab.run( theCrabOptions )
68 
69  theCrabOptions = {"-submit":""}
70  theCrab.run( theCrabOptions )
71 
72  theCrabOptions = {"-status":""}
73  theCrab.run( theCrabOptions )
74 
75  theCrabOptions = {"-getoutput":""}
76  try:
77  theCrab.run( theCrabOptions )
78  except AllInOneError as e:
79  print "crab: ", e
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139