Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/tools.py

    rf806b61 ra45fc7b  
    1111import subprocess
    1212import sys
    13 import tempfile
    1413import time
    1514import types
    1615
    1716from pybin import settings
     17from subprocess import Popen, PIPE, STDOUT
    1818
    1919################################################################################
     
    2727        # if this is a dry_run, only print the commands that would be ran
    2828        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))
    4330                return 0, None
    4431
    4532        with contextlib.ExitStack() as onexit:
    4633                # 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
    4840
    4941                # 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)
    5445
    5546                # run the desired command
     
    5950                                stdin =input,
    6051                                stdout=output,
    61                                 stderr=error,
     52                                stderr=STDOUT,
    6253                                timeout=settings.timeout.single if timeout else None
    6354                        )
     
    8778def is_exe(fname):
    8879        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 file
    93 
    94         if isinstance(file, int):
    95                 return file
    96 
    97         if checkfile and not os.path.isfile(file):
    98                 return None
    99 
    100         file = open(file, mode)
    101         exitstack.push(file)
    102         return file
    10380
    10481# Remove 1 or more files silently
     
    169146    return None
    170147
    171 @contextlib.contextmanager
    172 def tempdir():
    173         cwd = os.getcwd()
    174         with tempfile.TemporaryDirectory() as temp:
    175                 os.chdir(temp)
    176                 try:
    177                         yield temp
    178                 finally:
    179                         os.chdir(cwd)
    180 
    181148################################################################################
    182149#               file handling
     
    279246
    280247def core_info(path):
    281         if not os.path.isfile(path):
    282                 return 1, "ERR Executable path is wrong"
    283 
    284248        cmd   = os.path.join(settings.SRCDIR, "pybin/print-core.gdb")
    285249        if not os.path.isfile(cmd):
    286250                return 1, "ERR Printing format for core dumps not found"
    287251
    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"
    289256
    290257        if not os.path.isfile(core):
Note: See TracChangeset for help on using the changeset viewer.