Package Ganga :: Package Core :: Package Sandbox :: Module WNSandbox
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Core.Sandbox.WNSandbox

  1  """ 
  2  Sandbox functions used in the job wrapper script on the worker node. 
  3  The text of this module is sourced into the job wrapper script. 
  4  It therefore may use ###TAGS###  which are expanded in the wrapper script. 
  5  """ 
  6   
  7  INPUT_TARBALL_NAME = '_input_sandbox.tgz' 
  8  OUTPUT_TARBALL_NAME = '_output_sandbox.tgz' 
  9  PYTHON_DIR = '_python' 
 10   
11 -def getPackedInputSandbox(tarpath,dest_dir='.'):
12 """Get all sandbox_files from tarball and write them to the workdir. 13 This function is called by wrapper script at the run time. 14 Arguments: 15 'tarpath': a path to the tarball 16 'dest_dir': a destination directory 17 """ 18 19 #tgzfile = os.path.join(src_dir,INPUT_TARBALL_NAME) 20 tgzfile = tarpath 21 22 # 23 ## Curent release with os module 24 # 25 if os.system("tar -C %s -xzf %s"%(dest_dir,tgzfile)) != 0: 26 raise Exception('cannot upack tarball %s with InputSandbox'%tgzfile)
27 28 # 29 ## Future release with tarfile module 30 # 31 # tf = tarfile.open(tgzfile,"r:gz") 32 # 33 # [tf.extract(tarinfo,dest_dir) for tarinfo in tf] 34 # 35 # tf.close() 36 37 38 39 40
41 -def getInputSandbox(src_dir,dest_dir='.'):
42 """Get all input sandbox_files from tarball and write them to the workdir. 43 This function is called by wrapper script at the run time. 44 Arguments: 45 'src_dir': a source directory with InputSandbox files. 46 'dest_dir': a destination directory 47 """ 48 49 cmd = "tar chf - -C %s . | tar xf - -C %s" %(src_dir,dest_dir) 50 if os.system(cmd) != 0: 51 raise Exception("getInputSandbox() failed to execute command: %s"%cmd)
52 53
54 -def createOutputSandbox(output_patterns,filter,dest_dir):
55 """Get all files matching output patterns except filtered with filter and 56 write them to the destination directory. 57 This function is called by wrapper script at the run time. 58 Arguments: 59 'output_patterns': list of filenames or patterns. 60 'filter': function to filter files (return True to except) 61 'dest_dir': destination directory for output files 62 """ 63 64 from Ganga.Utility.files import multi_glob,recursive_copy 65 66 for f in multi_glob(output_patterns,filter): 67 try: 68 recursive_copy(f,dest_dir) 69 except Exception,x: 70 print "ERROR: (job ###JOBID### createOutput )",x
71 72
73 -def createPackedOutputSandbox(output_patterns,filter,dest_dir):
74 """Get all files matching output patterns except filtered with filter and 75 put them to the Sandbox tarball in destination directory. 76 This function is called by wrapper script at the run time. 77 Arguments: 78 'output_patterns': list of filenames or patterns. 79 'filter': function to filter files (return True to except) 80 'dest_dir': destination directory for tarball 81 """ 82 83 tgzfile = os.path.join(dest_dir,OUTPUT_TARBALL_NAME) 84 85 from Ganga.Utility.files import multi_glob,recursive_copy 86 outputlist = multi_glob(output_patterns,filter) 87 88 # 89 ## Curent release with os module 90 # 91 92 if len(outputlist) > 0: 93 if os.system("tar czf %s %s"%(tgzfile," ".join(outputlist))) != 0: 94 print "ERROR: (job ###JOBID### createPackedOutput ) can't creat tarball"
95 96 # 97 ## Future release with tarball module 98 # 99 # tf = tarfile.open(tgzfile,"w:gz") 100 # tf.dereference=True 101 # [tf.add(f) for f in outputlist] 102 # tf.close() 103