Changes in tests/pybin/tools.py [f806b61:a45fc7b]
- File:
-
- 1 edited
-
tests/pybin/tools.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/tools.py
rf806b61 ra45fc7b 11 11 import subprocess 12 12 import sys 13 import tempfile14 13 import time 15 14 import types 16 15 17 16 from pybin import settings 17 from subprocess import Popen, PIPE, STDOUT 18 18 19 19 ################################################################################ … … 27 27 # if this is a dry_run, only print the commands that would be ran 28 28 if settings.dry_run : 29 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 30 if output and not isinstance(output, int): 31 cmd += " > " 32 cmd += output 33 34 if error and not isinstance(error, int): 35 cmd += " 2> " 36 cmd += error 37 38 if input and not isinstance(input, int) and os.path.isfile(input): 39 cmd += " < " 40 cmd += input 41 42 print(cmd) 29 print("cmd: %s" % ' '.join(cmd)) 43 30 return 0, None 44 31 45 32 with contextlib.ExitStack() as onexit: 46 33 # add input redirection if needed 47 input = openfd(input, 'r', onexit, True) 34 if input and input != subprocess.DEVNULL: 35 if os.path.isfile(input): 36 input = open(input) 37 onexit.push(input) 38 else: 39 input = None 48 40 49 41 # add output redirection if needed 50 output = openfd(output, 'w', onexit, False) 51 52 # add error redirection if needed 53 error = openfd(error, 'w', onexit, False) 42 if output and output != subprocess.DEVNULL and output != subprocess.PIPE: 43 output = open(output, 'w') 44 onexit.push(output) 54 45 55 46 # run the desired command … … 59 50 stdin =input, 60 51 stdout=output, 61 stderr= error,52 stderr=STDOUT, 62 53 timeout=settings.timeout.single if timeout else None 63 54 ) … … 87 78 def is_exe(fname): 88 79 return os.path.isfile(fname) and os.access(fname, os.X_OK) 89 90 def openfd(file, mode, exitstack, checkfile):91 if not file:92 return file93 94 if isinstance(file, int):95 return file96 97 if checkfile and not os.path.isfile(file):98 return None99 100 file = open(file, mode)101 exitstack.push(file)102 return file103 80 104 81 # Remove 1 or more files silently … … 169 146 return None 170 147 171 @contextlib.contextmanager172 def tempdir():173 cwd = os.getcwd()174 with tempfile.TemporaryDirectory() as temp:175 os.chdir(temp)176 try:177 yield temp178 finally:179 os.chdir(cwd)180 181 148 ################################################################################ 182 149 # file handling … … 279 246 280 247 def core_info(path): 281 if not os.path.isfile(path):282 return 1, "ERR Executable path is wrong"283 284 248 cmd = os.path.join(settings.SRCDIR, "pybin/print-core.gdb") 285 249 if not os.path.isfile(cmd): 286 250 return 1, "ERR Printing format for core dumps not found" 287 251 288 core = os.path.join(os.getcwd(), "core" ) 252 dname = os.path.dirname(path) 253 core = os.path.join(dname, "core" ) 254 if not os.path.isfile(path): 255 return 1, "ERR Executable path is wrong" 289 256 290 257 if not os.path.isfile(core):
Note:
See TracChangeset
for help on using the changeset viewer.