Package Ganga :: Package GPIDev :: Package Adapters :: Module StandardJobConfig
[hide private]
[frames] | no frames]

Source Code for Module Ganga.GPIDev.Adapters.StandardJobConfig

  1  ################################################################################ 
  2  # Ganga Project. http://cern.ch/ganga 
  3  # 
  4  # $Id: StandardJobConfig.py,v 1.1 2008-07-17 16:40:52 moscicki Exp $ 
  5  ################################################################################ 
  6   
  7  from Ganga.Utility.logging import getLogger 
  8   
  9  logger = getLogger() 
 10   
11 -class StandardJobConfig:
12 """ 13 StandardJobConfig defines a standard input for many of the handlers: LSF, Localhost,LCG. 14 It corresponds to a simplified JDL definition: specification of executable, arguments and input sandbox. 15 Executable and arguments may be specified either as strings or File objects. In the second case they are 16 automatically added to the input sandbox list. 17 18 If you modify attributes of the StandardJobConfig object after the initialization, the you should 19 do processValues() which perfomes a validation of the attributes and updates internal cache which is 20 used by getter methods. 21 22 """ 23
24 - def __init__(self,exe=None,inputbox=[],args=[],outputbox=[],env={}):
25 """ 26 exe - executable string to be run on the worker node or a File object to be shipped as executable script to the worker node 27 args - list of strings which are passed as arguments to the executable string or File objects which are automatically added to the sandbox 28 inputbox - list of additional File or FileBuffer objects which go to the sandbox 29 outputbox - list of additional files which should be returned by the sandbox 30 env - environment to be set for execution of the job 31 32 The constructor does processValues() automatically so the construction of the object may failed with exceptions raised by that method. 33 Notes for derived classes: 34 - this constructor should be called at the end of the derived constructor. 35 - you may freely add new attributes as long as you they do not start with _ 36 """ 37 self.exe = exe 38 self.inputbox = inputbox[:] 39 self.args = args 40 self.outputbox = outputbox[:] 41 self.env = env 42 43 self.__all_inputbox = [] 44 self.__args_strings = [] 45 self.__exe_string = "" 46 self.__sandbox_check = {} 47 48 self.processValues()
49
50 - def getSandboxFiles(self):
51 '''Get all input sandbox files''' 52 return self.__all_inputbox
53
54 - def getOutputSandboxFiles(self):
55 """Get all output sandbox files. The duplicates are removed. """ 56 from Ganga.Utility.util import unique 57 return unique(self.outputbox)
58
59 - def getExeString(self):
60 '''Get a string which should be used at the worker node to invoke an executable. 61 Note that this string does not necesserily have to be a file name on the worker node''' 62 return self.__exe_string
63
64 - def getArgStrings(self):
65 '''Get a list of strings which correspond to the arguments to the executable on the worker node.''' 66 return self.__args_strings
67
68 - def getExeCmdString(self):
69 '''Get a command string including the quoted arguments which may be passed to os.system(). 70 This method is provided for the convenience''' 71 72 logger.warning('INTERNAL METHOD JobConfig.getExeCmdString() IS OBSOLETED, backend should be updated to use getExeString() and shell=False in a call to subprocess.Popen()') 73 # reduce the args list into the quoted string: "arg1" "arg2" "arg3" 74 # FIXME: quoting should rather be moved to utility functions 75 def quote_arguments(args): 76 quoted = "" 77 for a in args: 78 quoted += '"'+a+'" ' 79 return quoted
80 81 return self.__exe_string+' '+quote_arguments(self.__args_strings)
82
83 - def processValues(self):
84 '''Process original exe,args and inputbox values and extract strings suitable for the further processing. 85 If the exe property is a File then this method will check if it has executable attributes. 86 You do not have to call this method unless you explicitly modify some of the original values. 87 ''' 88 89 90 from Ganga.GPIDev.Lib.File import File 91 92 self.__all_inputbox = self.inputbox[:] 93 self.__args_strings = [] 94 self.__exe_string = "" 95 self.__sandbox_check = {} 96 97 98 99 def _get_path_in_sandbox(f): 100 ''' A helper which checks conflicts in sandbox. 101 If you try to add twice a file object f with the same name, it shows a warning. 102 ''' 103 104 fn = f.getPathInSandbox() 105 if self.__sandbox_check.has_key(fn): 106 logger.warning('File %s already in the sandbox (source=%s). Overriding from source=%s',fn,self.__sandbox_check[fn],f.name) 107 self.__sandbox_check[fn] = f.name 108 return fn
109 110 #to check for double file 111 112 for f in self.inputbox: 113 fn = _get_path_in_sandbox(f) 114 115 # convert all args into strings (some of args may be FileItems) 116 # make an assumption that all File Items go to the sandbox (thus convert to basename) 117 for a in self.args: 118 if type(a) is type(''): 119 self.__args_strings.append(a) 120 else: 121 try: 122 fn = _get_path_in_sandbox(a) 123 self.__args_strings.append(fn) 124 self.__all_inputbox.append(a) 125 except AttributeError,x: 126 s = "cannot process argument %s, it is neither File nor string" % repr(a) 127 logger.error(s) 128 raise ValueError(s) 129 130 if type(self.exe) is type(''): 131 self.__exe_string = self.exe 132 else: 133 try: 134 self.__exe_string = _get_path_in_sandbox(self.exe) 135 if not self.exe.isExecutable(): 136 logger.warning('file %s is not executable, overriding executable permissions in the input sandbox'%self.exe.name) 137 self.exe.executable = True 138 self.__all_inputbox.append(self.exe) 139 except AttributeError,x: 140 s = "cannot process exe property %s, it is neither File nor string (%s)" % (repr(self.exe),str(x)) 141 logger.error(s) 142 raise ValueError(s) 143 144 # 145 # 146 # $Log: not supported by cvs2svn $ 147 # Revision 1.6.4.1 2007/10/30 15:19:47 moscicki 148 # obsoleted jobConfig.getExeCmdString() method 149 # 150 # Revision 1.6 2007/08/24 15:55:02 moscicki 151 # added executable flag to the file, ganga will set the executable mode of the app.exe file (in the sandbox only, the original file is not touched), this is to solve feature request #24452 152 # 153 # Revision 1.5 2006/08/07 12:09:06 moscicki 154 # bug #18271 bug fix from V.Romanovski 155 # 156 # Revision 1.4 2006/02/10 14:19:14 moscicki 157 # added outputsandbox 158 # 159 # Revision 1.3 2005/09/02 12:42:56 liko 160 # Extend StandardJobConfig with outputbox and environment 161 # 162 # Revision 1.2 2005/08/24 08:16:49 moscicki 163 # minor changes 164 # 165 # 166 # 167