Exemple #1
0
 def execv(filename,args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     tdir = nt.environ.get("TEMP",None)
     if tdir:
         tfile = None
         try:
             nt.mkdir(pathjoin(tdir,"esky-slave-procs"))
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir,"esky-slave-procs")):
             flags = nt.O_CREAT|nt.O_EXCL|nt.O_TEMPORARY|nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(),i,)
                 tfilenm = pathjoin(tdir,"esky-slave-procs",tfilenm)
                 try:
                     tfile = nt.open(tfilenm,flags)
                     break
                 except EnvironmentError:
                     raise
                     pass
     if tdir and tfile:
         args.insert(1,tfilenm)
         args.insert(1,"--esky-slave-proc")
     res = spawnv(P_WAIT,filename,args)
     raise SystemExit(res)
Exemple #2
0
 def execv(filename,args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     try:
         tdir = environ["TEMP"]
     except:
         tdir = None
     if tdir:
         try:
             nt.mkdir(pathjoin(tdir,"esky-slave-procs"),0600)
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir,"esky-slave-procs")):
             flags = nt.O_CREAT|nt.O_EXCL|nt.O_TEMPORARY|nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(),i,)
                 tfilenm = pathjoin(tdir,"esky-slave-procs",tfilenm)
                 try:
                     os_open(tfilenm,flags,0600)
                     args.insert(1,tfilenm)
                     args.insert(1,"--esky-slave-proc")
                     break
                 except EnvironmentError:
                     pass
     # Ensure all arguments are quoted (to allow spaces in paths)
     for i, arg in enumerate(args):
         if arg[0] != "\"" and args[-1] != "\"":
             args[i] = "\"{}\"".format(arg)
     res = spawnv(P_WAIT,filename, args)
     _exit_code[0] = res
     raise SystemExit(res)
def launch_ironpython_changing_extensions(test,
                                          add=[],
                                          remove=[],
                                          additionalScriptParams=()):
    final = _get_ip_testmode()
    for param in add:
        if param not in final: final.append(param)

    for param in remove:
        if param in final:
            pos = final.index(param)
            if pos != -1:
                if param in one_arg_params:
                    del final[pos:pos + 2]
                else:
                    del final[pos]

    params = [sys.executable]
    params.extend(final)
    params.append(test)
    params.extend(additionalScriptParams)

    print("Starting process: %s" % params)

    return nt.spawnv(0, sys.executable, params)
Exemple #4
0
 def execv(filename, args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     try:
         tdir = environ["TEMP"]
     except:
         tdir = None
     if tdir:
         try:
             nt.mkdir(pathjoin(tdir, "esky-slave-procs"), 0600)
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir, "esky-slave-procs")):
             flags = nt.O_CREAT | nt.O_EXCL | nt.O_TEMPORARY | nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(), i)
                 tfilenm = pathjoin(tdir, "esky-slave-procs", tfilenm)
                 try:
                     os_open(tfilenm, flags, 0600)
                     args.insert(1, tfilenm)
                     args.insert(1, "--esky-slave-proc")
                     break
                 except EnvironmentError:
                     pass
     # Ensure all arguments are quoted (to allow spaces in paths)
     for i, arg in enumerate(args):
         if arg[0] != '"' and args[-1] != '"':
             args[i] = '"{}"'.format(arg)
     res = spawnv(P_WAIT, filename, args)
     _exit_code[0] = res
     raise SystemExit(res)
Exemple #5
0
 def test_cp15514(self):
     cmd_variation_list = ['%s -c "print(__name__)"' % sys.executable,
                         '"%s -c "print(__name__)" "' % sys.executable,
                         ]
     cmd_cmd = os.path.join(os.environ["windir"], "system32", "cmd")
     for x in cmd_variation_list:
         ec = nt.spawnv(nt.P_WAIT, cmd_cmd , ["cmd", "/C", x])
         self.assertEqual(ec, 0)
Exemple #6
0
def test_cp15514():
    cmd_variation_list = ['%s -c "print __name__"' % sys.executable,
                          '"%s -c "print __name__""' % sys.executable,
                          ]
    cmd_cmd = get_environ_variable("windir") + "\system32\cmd"
    for x in cmd_variation_list:
        ec = nt.spawnv(nt.P_WAIT, cmd_cmd , ["cmd", "/C", 
                                             x])
        AreEqual(ec, 0)
Exemple #7
0
 def test_cp15514(self):
     cmd_variation_list = ['%s -c "print __name__"' % sys.executable,
                         '"%s -c "print __name__""' % sys.executable,
                         ]
     cmd_cmd = os.path.join(os.environ["windir"], "system32", "cmd")
     for x in cmd_variation_list:
         ec = nt.spawnv(nt.P_WAIT, cmd_cmd , ["cmd", "/C", 
                                             x])
         self.assertEqual(ec, 0)
Exemple #8
0
def test_cp15514():
    cmd_variation_list = [
        '%s -c "print __name__"' % sys.executable,
        '"%s -c "print __name__""' % sys.executable,
    ]
    cmd_cmd = get_environ_variable("windir") + "\system32\cmd"
    for x in cmd_variation_list:
        ec = nt.spawnv(nt.P_WAIT, cmd_cmd, ["cmd", "/C", x])
        AreEqual(ec, 0)
Exemple #9
0
    def test_waitpid(self):
        #sanity check
        ping_cmd = os.path.join(os.environ["windir"], "system32", "ping")
        pid = nt.spawnv(nt.P_NOWAIT, ping_cmd ,  ["ping", "-n", "1", "127.0.0.1"])

        new_pid, exit_stat = nt.waitpid(pid, 0)

        #negative cases
        self.assertRaisesMessage(OSError, "[Errno 10] No child processes", nt.waitpid, -1234, 0)

        self.assertRaises(TypeError, nt.waitpid, "", 0)
Exemple #10
0
 def test_waitpid(self):
     #sanity check
     ping_cmd = os.path.join(os.environ["windir"], "system32", "ping")
     pid = nt.spawnv(nt.P_NOWAIT, ping_cmd ,  ["ping", "-n", "1", "127.0.0.1"])
     
     new_pid, exit_stat = nt.waitpid(pid, 0)
     
     #negative cases
     self.assertRaisesMessage(OSError, "[Errno 10] No child processes", nt.waitpid, -1234, 0)
         
     self.assertRaises(TypeError, nt.waitpid, "", 0)
Exemple #11
0
def test_spawnv():
    #sanity check
    ping_cmd = get_environ_variable("windir") + "\system32\ping"
    nt.spawnv(nt.P_WAIT, ping_cmd, ["ping"])
    nt.spawnv(nt.P_WAIT, ping_cmd, ["ping", "127.0.0.1"])
    nt.spawnv(nt.P_WAIT, ping_cmd,
              ["ping", "-n", "5", "-w", "5000", "127.0.0.1"])
Exemple #12
0
def test_waitpid():
    '''
    '''
    #sanity check
    ping_cmd = get_environ_variable("windir") + "\system32\ping"
    pid = nt.spawnv(nt.P_NOWAIT, ping_cmd ,  ["ping", "-n", "5", "-w", "1000", "127.0.0.1"])
    
    new_pid, exit_stat = nt.waitpid(pid, 0)
    
    #negative cases
    AssertErrorWithMessage(OSError, "[Errno 10] No child processes", nt.waitpid, -1234, 0)
        
    AssertError(TypeError, nt.waitpid, "", 0)
Exemple #13
0
def test_waitpid():
    '''
    '''
    #sanity check
    ping_cmd = get_environ_variable("windir") + "\system32\ping"
    pid = nt.spawnv(nt.P_NOWAIT, ping_cmd ,  ["ping", "-n", "5", "-w", "1000", "127.0.0.1"])
    
    new_pid, exit_stat = nt.waitpid(pid, 0)
    
    #negative cases
    AssertErrorWithMessage(OSError, "[Errno 10] No child processes", nt.waitpid, -1234, 0)
        
    AssertError(TypeError, nt.waitpid, "", 0)
def TestCommandLine(args, expected_output, expected_exitcode=0):
    realargs = [batfile]
    realargs.extend(args)
    exitcode = nt.spawnv(0, batfile, realargs)
    cmdline = "ipy " + ' '.join(args)

    print ''
    print '    ', cmdline

    Assert(exitcode == expected_exitcode,
           "'" + cmdline + "' generated unexpected exit code " + str(exitcode))
    if (expected_output != None):
        f = file(tmpfile)
        if isinstance(expected_output, str):
            output = f.read()
        else:
            output = f.readlines()
        f.close()

        # normalize \r\n to \n
        if type(output) == list:
            for i in range(len(output)):
                output[i] = output[i].replace('\r\n', '\n')
        else:
            output = output.replace('\r\n', '\n')

        # then check the output
        if isinstance(expected_output, str):
            Assert(output == expected_output,
                   "'" + cmdline + "' generated unexpected output:\n" + output)
        elif isinstance(expected_output, tuple):
            if expected_output[0] == "firstline":
                Assert(
                    output[0] == expected_output[1], "'" + cmdline +
                    "' generated unexpected first line of output:\n" +
                    repr(output[0]))
            elif expected_output[0] == "lastline":
                Assert(
                    output[-1] == expected_output[1], "'" + cmdline +
                    "' generated unexpected last line of output:\n" +
                    repr(output[-1]))
            elif expected_output[0] == "regexp":
                output = ''.join(output)
                Assert(
                    re.match(expected_output[1], output,
                             re.M | re.S), "'" + cmdline +
                    "' generated unexpected output:\n" + repr(output))
            else:
                Assert(False, "Invalid type for expected_output")
        else:
            Assert(False, "Invalid type for expected_output")
Exemple #15
0
def RunPythonExe(file, *args):
    fullpath = GetFullPath(file)
    temppath = System.IO.Path.Combine(sys.prefix, System.IO.FileInfo(fullpath).Name).ToLower()

    if (fullpath != temppath):
        System.IO.File.Copy(fullpath, temppath, True)

    realargs = [temppath]
    realargs.extend(args)
    try:
        retval = nt.spawnv(0, temppath, realargs)
    except:
        retval = 1

    # hack
    if (fullpath != temppath):
        DeleteFile(temppath)
    Assert(not retval)
Exemple #16
0
def RunPythonExe(file, *args):
    fullpath = GetFullPath(file)
    temppath = System.IO.Path.Combine(
        sys.prefix,
        System.IO.FileInfo(fullpath).Name).ToLower()

    if (fullpath != temppath):
        System.IO.File.Copy(fullpath, temppath, True)

    realargs = [temppath]
    realargs.extend(args)
    try:
        retval = nt.spawnv(0, temppath, realargs)
    except:
        retval = 1

    # hack
    if (fullpath != temppath):
        DeleteFile(temppath)
    Assert(not retval)
Exemple #17
0
def TestCommandLine(args, expected_output, expected_exitcode = 0):
    realargs = [batfile]
    realargs.extend(args)
    exitcode = nt.spawnv(0, batfile, realargs)
    cmdline = "ipy " + ' '.join(args)
    
    print ''
    print '    ', cmdline
    
    Assert(exitcode == expected_exitcode, "'" + cmdline + "' generated unexpected exit code " + str(exitcode))
    if (expected_output != None):
        f = file(tmpfile)
        if isinstance(expected_output, str):
            output = f.read()
        else:
            output = f.readlines()
        f.close()
        
        # normalize \r\n to \n
        if type(output) == list:
            for i in range(len(output)):
                output[i] = output[i].replace('\r\n', '\n')
        else:
            output = output.replace('\r\n', '\n')
        
        # then check the output
        if isinstance(expected_output, str):
            Assert(output == expected_output, "'" + cmdline + "' generated unexpected output:\n" + output)
        elif isinstance(expected_output, tuple):
            if expected_output[0] == "firstline":
                Assert(output[0] == expected_output[1], "'" + cmdline + "' generated unexpected first line of output:\n" + repr(output[0]))
            elif expected_output[0] == "lastline":
                Assert(output[-1] == expected_output[1], "'" + cmdline + "' generated unexpected last line of output:\n" + repr(output[-1]))
            elif expected_output[0] == "regexp":
                output = ''.join(output)
                Assert(re.match(expected_output[1], output, re.M | re.S), "'" + cmdline + "' generated unexpected output:\n" + repr(output))
            else:
                Assert(False, "Invalid type for expected_output")
        else:
            Assert(False, "Invalid type for expected_output")
Exemple #18
0
def launch_ironpython_changing_extensions(test, add=[], remove=[], additionalScriptParams=()):
    final = _get_ip_testmode()
    for param in add:
        if param not in final: final.append(param)
        
    for param in remove:
        if param in final:
            pos = final.index(param)
            if pos != -1:
                if param in one_arg_params:
                    del final[pos:pos+2]
                else :
                    del final[pos]
        
    params = [sys.executable]
    params.extend(final)
    params.append(test)
    params.extend(additionalScriptParams)
    
    print "Starting process: %s" % params
    
    return nt.spawnv(0, sys.executable, params)
Exemple #19
0
#--MAIN------------------------------------------------------------------------
nt.chdir(TEST_DIR)

for test in TESTS:
    #Get the contents of the file
    f = open(test, "r")
    lines = f.readlines()
    f.close()

    #Fix the file
    apply_filters(lines)

    #Check out the file
    try:
        ec = nt.spawnv(nt.P_WAIT, TF_DIR, ["tf", "edit", test])
    except Exception, e:
        print "FAILED: could not check out %s from TFS: %s" % (test, str(e))
        continue

    if ec != 0:
        print "FAILED: could not check out %s from TFS!" % test
        continue

    #Write it back out
    f = open(test, "w")
    f.writelines(lines)
    f.close()

#Cleanup
ec = nt.spawnv(nt.P_WAIT, TFPT_DIR, ["tfpt", "uu", TEST_DIR])
Exemple #20
0
    
#--MAIN------------------------------------------------------------------------
nt.chdir(TEST_DIR)

for test in TESTS:
    #Get the contents of the file
    f = open(test, "r")
    lines = f.readlines()
    f.close()

    #Fix the file
    apply_filters(lines)
    
    #Check out the file
    try:
        ec = nt.spawnv(nt.P_WAIT, TF_DIR, ["tf", "edit", test])
    except Exception, e:
        print "FAILED: could not check out %s from TFS: %s" % (test, str(e))
        continue
    
    if ec!=0:
        print "FAILED: could not check out %s from TFS!" % test
        continue
        
    #Write it back out
    f = open(test, "w")
    f.writelines(lines)
    f.close()
    
    
#Cleanup
Exemple #21
0
def test_spawnv():
    #sanity check
    ping_cmd = get_environ_variable("windir") + "\system32\ping"
    nt.spawnv(nt.P_WAIT, ping_cmd , ["ping"])
    nt.spawnv(nt.P_WAIT, ping_cmd , ["ping","127.0.0.1"])
    nt.spawnv(nt.P_WAIT, ping_cmd, ["ping", "-n", "5", "-w", "5000", "127.0.0.1"])
Exemple #22
0
 def test_spawnv(self):
     #sanity check
     ping_cmd = os.path.join(os.environ["windir"], "system32", "ping")
     nt.spawnv(nt.P_WAIT, ping_cmd , ["ping"])
     nt.spawnv(nt.P_WAIT, ping_cmd , ["ping","127.0.0.1","-n","1"])
Exemple #23
0
def launch(executable, *params):
    l = [executable] + list(params)
    return nt.spawnv(0, executable, l)
Exemple #24
0
def launch(executable, *params):
    l = [ executable ] + list(params)
    return nt.spawnv(0, executable, l)
Exemple #25
0
 def test_spawnv(self):
     #sanity check
     ping_cmd = os.path.join(os.environ["windir"], "system32", "ping")
     nt.spawnv(nt.P_WAIT, ping_cmd, ["ping"])
     nt.spawnv(nt.P_WAIT, ping_cmd, ["ping", "127.0.0.1", "-n", "1"])
Exemple #26
0
def launch(executable, test):
    return nt.spawnv(0, executable, (executable, test))