Script xalt_generate_linkdata_in_py
[hide private]
[frames] | no frames]

Source Code for Script script-xalt_generate_linkdata_in_py

  1  # -*- python -*- 
  2  # 
  3  # Git Version: @git@ 
  4   
  5  #----------------------------------------------------------------------- 
  6  # XALT: A tool that tracks users jobs and environments on a cluster. 
  7  # Copyright (C) 2013-2014 University of Texas at Austin 
  8  # Copyright (C) 2013-2014 University of Tennessee 
  9  #  
 10  # This library is free software; you can redistribute it and/or modify 
 11  # it under the terms of the GNU Lesser General Public License as 
 12  # published by the Free Software Foundation; either version 2.1 of  
 13  # the License, or (at your option) any later version.  
 14  # 
 15  # This library 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 GNU 
 18  # Lesser  General Public License for more details.  
 19  # 
 20  # You should have received a copy of the GNU Lesser General Public 
 21  # License along with this library; if not, write to the Free 
 22  # Software Foundation, Inc., 59 Temple Place, Suite 330, 
 23  # Boston, MA 02111-1307 USA 
 24  #----------------------------------------------------------------------- 
 25   
 26  from __future__                import print_function 
 27  import os, sys, re, json, subprocess 
 28   
 29  dirNm, execName = os.path.split(os.path.realpath(sys.argv[0])) 
 30  sys.path.insert(1,os.path.realpath(os.path.join(dirNm, "../libexec"))) 
 31  sys.path.insert(1,os.path.realpath(os.path.join(dirNm, "../site"))) 
 32   
 33  from xalt_util                 import * 
 34  from xalt_transmission_factory import XALT_transmission_factory 
 35  from xalt_global               import * 
 36   
 37  logger    = config_logger() 
 38  parenPat  = re.compile(r'.*\((.*)\).*') 
 39  tmpObjPat = re.compile(r'/tmp/[_a-zA-Z0-9-]+.o') 
 40   
41 -def cleanup(xaltobj, fn):
42 """ 43 cleanup the output of ld --trace 44 @param xaltobj: The name of the XALT object file. 45 @param fn: The file path that contains the ld --trace output. 46 """ 47 f = open(fn,"r") 48 lines = f.readlines() 49 d = {} 50 for s in lines: 51 52 # remove lines with ':' 53 if (s.find(":") != -1): 54 continue 55 56 # remove line with the xalt.o file 57 if (s.find(xaltobj) != -1): 58 continue 59 60 # remove a file that is something like: /tmp/ccT33qQt.o 61 m = tmpObjPat.search(s) 62 if (m): 63 continue 64 65 # Capture the library name in the parens: 66 # -lgcc_s (/usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so) 67 m = parenPat.search(s) 68 if (m): 69 s = os.path.realpath(m.group(1)) 70 d[s] = True 71 continue 72 73 # Save everything else 74 idx = s.find("\n") 75 if (idx != -1): 76 s = s[:idx] 77 78 s = os.path.realpath(s) 79 d[s] = True 80 81 # make the list unique 82 sA = d.keys() 83 84 sA = sorted(sA) 85 86 sB = [] 87 for lib in sA: 88 hash_line = capture(['sha1sum', lib]) 89 if (hash_line.find("No such file or directory") != -1): 90 continue 91 else: 92 v = hash_line.split()[0] 93 sB.append([lib, v]) 94 95 return sB
96
97 -def main():
98 """ 99 Built a json output of the ld --trace data. 100 """ 101 User = os.environ.get("USER", "unknown") 102 Host = os.environ.get("HOSTNAME","unknown") 103 # push User, host and command line on to XALT_Stack 104 XALT_Stack.push("User: " + User) 105 XALT_Stack.push("Host: " + Host) 106 sA = [] 107 sA.append("CommandLine:") 108 for v in sys.argv: 109 sA.append('"'+v+'"') 110 111 s = " ".join(sA) 112 XALT_Stack.push(s) 113 114 try: 115 uuid = sys.argv[ 1] 116 status = sys.argv[ 2] 117 wd = sys.argv[ 3] 118 syshost = sys.argv[ 4] 119 pstree = sys.argv[ 5] 120 execname = sys.argv[ 6] 121 xaltobj = sys.argv[ 7] 122 build_epoch = sys.argv[ 8] 123 linklineFn = sys.argv[ 9] 124 resultFn = sys.argv[10] 125 126 if (execname.find("conftest") != -1): 127 return 1 128 129 hash_line = capture(['sha1sum', execname]) 130 if (hash_line.find("No such file or directory") != -1): 131 return 1 132 hash_id = hash_line.split()[0] 133 134 # Step one clean up linkline data 135 sA = cleanup(xaltobj, linklineFn) 136 137 resultT = {} 138 resultT['uuid'] = uuid 139 resultT['link_program'] = extract_compiler(pstree) 140 resultT['build_user'] = User 141 resultT['exit_code'] = status 142 resultT['build_epoch'] = build_epoch 143 resultT['exec_path'] = os.path.abspath(execname) 144 resultT['hash_id'] = hash_id 145 resultT['wd'] = wd 146 resultT['build_syshost'] = syshost 147 resultT['linkA'] = sA 148 149 xfer = XALT_transmission_factory.build(XALT_TRANSMISSION_STYLE, 150 syshost, "link", resultFn) 151 xfer.save(resultT) 152 153 except Exception as e: 154 print("XALT_EXCEPTION(xalt_generate_linkdata.py): ",e) 155 logger.exception("XALT_EXCEPTION:xalt_generate_linkdata"+XALT_Stack.contents()) 156 157 return 0
158 159 if ( __name__ == '__main__'): 160 iret = main() 161 sys.exit(iret) 162