Changes in src/tests/pybin/tools.py [552f5cb:ed45af6]
- File:
-
- 1 edited
-
src/tests/pybin/tools.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/pybin/tools.py
r552f5cb red45af6 9 9 import stat 10 10 import sys 11 import fileinput12 11 13 12 from pybin import settings … … 34 33 out, err = proc.communicate() 35 34 return proc.returncode, out 36 37 def is_ascii(fname):38 if not os.path.isfile(fname):39 return False40 41 code, out = sh("file %s" % fname, print2stdout = False)42 if code != 0:43 return False44 45 match = re.search(".*: (.*)", out)46 47 if not match:48 return False49 50 return match.group(1) == "ASCII text"51 35 52 36 # Remove 1 or more files silently … … 121 105 # helper function to replace patterns in a file 122 106 def file_replace(fname, pat, s_after): 123 file = fileinput.FileInput(fname, inplace=True, backup='.bak') 124 for line in file: 125 print(line.replace(pat, s_after), end='') 126 file.close() 107 # first, see if the pattern is even in the file. 108 with open(fname) as f: 109 if not any(re.search(pat, line) for line in f): 110 return # pattern does not occur in file so we are done. 111 112 # pattern is in the file, so perform replace operation. 113 with open(fname) as f: 114 out_fname = fname + ".tmp" 115 out = open(out_fname, "w") 116 for line in f: 117 out.write(re.sub(pat, s_after, line)) 118 out.close() 119 os.rename(out_fname, fname) 127 120 128 121 # helper function to check if a files contains only a specific string … … 147 140 # transform path to canonical form 148 141 def canonicalPath(path): 149 abspath = os.path.abspath(__main__.__file__) 150 dname = os.path.dirname(abspath) 151 return os.path.join(dname, os.path.normpath(path) ) 142 return os.path.join('.', os.path.normpath(path) ) 152 143 153 144 # compare path even if form is different … … 160 151 for name in names: 161 152 path = os.path.join(dirname, name) 153 162 154 op( path ) 163 155 164 156 # Start the walk 165 abspath = os.path.abspath(__main__.__file__) 166 dname = os.path.dirname(abspath) 167 os.path.walk(dname, step, '') 157 os.path.walk('.', step, '') 168 158 169 159 ################################################################################ 170 160 # system 171 161 ################################################################################ 162 163 # parses the Makefile to find the machine type (32-bit / 64-bit) 164 def getMachineType(): 165 sh('echo "void ?{}(int&a,int b){}int main(){return 0;}" > .dummy.c') 166 ret, out = make('.dummy', silent = True) 167 168 if ret != 0: 169 print("Failed to identify architecture:") 170 print(out) 171 print("Stopping") 172 rm( (".dummy.c",".dummy") ) 173 sys.exit(1) 174 175 _, out = sh("file .dummy", print2stdout=False) 176 rm( (".dummy.c",".dummy") ) 177 178 if settings.dry_run : 179 return 'x64' 180 181 return re.search(r"[^,]+,([^,]+),", out).group(1).strip() 182 172 183 # count number of jobs to create 173 184 def jobCount( options, tests ): … … 233 244 else: 234 245 print(text) 246 247 settings.set_machine_default( getMachineType )
Note:
See TracChangeset
for help on using the changeset viewer.