コード例 #1
0
def create_linklet_json(rkt_file_name=""):
    # uses expander's extract to turn it into a linklet
    # gets the bytecodes and uses zo-expand to turn it into a json
    # and loads and instantiates it
    import os
    from pycket.util import os_get_env_var
    from rpython.rlib.rfile import create_popen_file
    PLTHOME = os_get_env_var("PLTHOME")
    EXPANDER_DIR = os.path.join(
        PLTHOME, os.path.join("racket", os.path.join("src", "expander")))

    # FIXME: error check
    # prep_cmd = "raco make -v %s/bootstrap-run.rkt" % EXPANDER_DIR
    # pipe1 = create_popen_file(prep_cmd, "r")
    # pipe1.read()
    # pipe1.close()
    extract_cmd = "racket -t %s/bootstrap-run.rkt -- -c compiled/cache-src/ ++knot read - -s -x -t %s -o compiled/%s.sexp" % (
        EXPANDER_DIR, rkt_file_name, rkt_file_name)
    pipe2 = create_popen_file(extract_cmd, "r")
    pipe2.read()
    pipe2.close()
    linklet_json_cmd = "racket linklet-extractor/linklet-sexp-to-json.rkt --output %s.linklet compiled/%s.sexp" % (
        rkt_file_name, rkt_file_name)
    pipe3 = create_popen_file(linklet_json_cmd, "r")
    pipe3.read()
    pipe3.close()
コード例 #2
0
ファイル: exec_.py プロジェクト: youaani/hippyvm
def exec_(interp, cmd, r_output=None, r_return_var=None):
    space = interp.space
    if not cmd:
        raise ExitFunctionWithError('Cannot execute a blank command')
    if r_output is not None:
        if not space.is_array(r_output.deref_temp()):
            r_output.store(space.new_array_from_list([]))
        w_output = r_output.deref_unique()
    else:
        w_output = None
    try:
        pfile = create_popen_file(cmd, 'r')
    except OSError:
        raise ExitFunctionWithError('Unable to fork [%s]' % cmd, w_Null)
    last_line = ''
    while True:
        line = pfile.readline()
        if not line:
            break
        last_line = line.rstrip()
        if w_output:
            w_output.appenditem_inplace(space, space.newstr(last_line))
    exitcode = pfile.close()
    if r_return_var is not None:
        r_return_var.store(space.wrap(exitcode))
    return space.newstr(last_line)
コード例 #3
0
ファイル: expand.py プロジェクト: fenildf/pycket
def _expand_file_to_json(rkt_file, json_file, byte_flag=False):
    lib = _BE if byte_flag else _FN

    dbgprint("_expand_file_to_json", "", lib=lib, filename=rkt_file)

    from rpython.rlib.rfile import create_popen_file
    if not os.access(rkt_file, os.R_OK):
        raise ValueError("Cannot access file %s" % rkt_file)
    if not os.access(rkt_file, os.W_OK):
        # we guess that this means no permission to write the json file
        raise PermException(rkt_file)
    try:
        os.remove(json_file)
    except IOError:
        pass
    except OSError:
        pass

    cmd = "racket %s --output \"%s\" \"%s\" 2>&1" % (lib, json_file, rkt_file)

    if byte_flag:
        print "Transforming %s bytecode to %s" % (rkt_file, json_file)
        #cmd = "racket %s --output \"%s\" \"%s\"" % (lib, json_file, rkt_file)
    else:
        print "Expanding %s to %s" % (rkt_file, json_file)

    # print cmd
    pipe = create_popen_file(cmd, "r")
    out = pipe.read()
    err = os.WEXITSTATUS(pipe.close())
    if err != 0:
        raise ExpandException("Racket produced an error and said '%s'" % out)
    return json_file
コード例 #4
0
def systemstar_json_term(t):
  from rpython.rlib import rfile
  args = [shellquote(x.string_value()) for x in W_TermList(t)]
  f = rfile.create_popen_file(' '.join(args), 'r')
  s = f.read()
  f.close()
  return string_to_term(s)
コード例 #5
0
ファイル: expand.py プロジェクト: magnusmorton/pycket
def _expand_file_to_json(rkt_file, json_file, byte_flag=False):
    lib = _BE if byte_flag else _FN

    dbgprint("_expand_file_to_json", "", lib=lib, filename=rkt_file)

    from rpython.rlib.rfile import create_popen_file
    if not os.access(rkt_file, os.R_OK):
        raise ValueError("Cannot access file %s" % rkt_file)
    if not os.access(rkt_file, os.W_OK):
        # we guess that this means no permission to write the json file
        raise PermException(rkt_file)
    try:
        os.remove(json_file)
    except IOError:
        pass
    except OSError:
        pass

    cmd = "racket %s --output \"%s\" \"%s\" 2>&1" % (lib, json_file, rkt_file)

    if byte_flag:
        print "Transforming %s bytecode to %s" % (rkt_file, json_file)
        #cmd = "racket %s --output \"%s\" \"%s\"" % (lib, json_file, rkt_file)
    else:
        print "Expanding %s to %s" % (rkt_file, json_file)

    # print cmd
    pipe = create_popen_file(cmd, "r")
    out = pipe.read()
    err = os.WEXITSTATUS(pipe.close())
    if err != 0:
        raise ExpandException("Racket produced an error and said '%s'" % out)
    return json_file
コード例 #6
0
ファイル: exec_.py プロジェクト: CodeOps/hippyvm
def exec_(interp, cmd, r_output=None, r_return_var=None):
    space = interp.space
    if not cmd:
        raise ExitFunctionWithError("Cannot execute a blank command")
    if r_output is not None:
        if not space.is_array(r_output.deref_temp()):
            r_output.store(space.new_array_from_list([]))
        w_output = r_output.deref_unique()
    else:
        w_output = None
    try:
        pfile = create_popen_file(cmd, "r")
    except OSError:
        raise ExitFunctionWithError("Unable to fork [%s]" % cmd, w_Null)
    last_line = ""
    while True:
        line = pfile.readline()
        if not line:
            break
        last_line = line.rstrip()
        if w_output:
            w_output.appenditem_inplace(space, space.newstr(last_line))
    exitcode = pfile.close()
    if r_return_var is not None:
        r_return_var.store(space.wrap(exitcode))
    return space.newstr(last_line)
コード例 #7
0
ファイル: test_rfile.py プロジェクト: zcxowwww/pypy
 def test_pclose(self):
     retval = 32
     printval = 42
     cmd = "python -c 'import sys; print %s; sys.exit(%s)'" % (printval,
                                                               retval)
     f = rfile.create_popen_file(cmd, "r")
     s = f.read()
     r = f.close()
     assert s == "%s\n" % printval
     assert os.WEXITSTATUS(r) == retval
コード例 #8
0
ファイル: test_rfile.py プロジェクト: yuyichao/pypy
 def test_pclose(self):
     retval = 32
     printval = 42
     cmd = "python -c 'import sys; print %s; sys.exit(%s)'" % (
         printval, retval)
     f = rfile.create_popen_file(cmd, "r")
     s = f.read()
     r = f.close()
     assert s == "%s\n" % printval
     assert os.WEXITSTATUS(r) == retval
コード例 #9
0
ファイル: exec_.py プロジェクト: youaani/hippyvm
def shell_exec(interp, cmd):
    try:
        r_pfile = create_popen_file(cmd, 'r')
    except OSError:
        interp.warn("Unable to execute '%s'" % cmd)
        return w_Null
    res = r_pfile.read(-1)
    if res:
        return interp.space.wrap(res)
    else:
        return w_Null
コード例 #10
0
ファイル: expand.py プロジェクト: 8l/pycket
def expand_file_rpython(rkt_file):
    from rpython.rlib.rfile import create_popen_file
    cmd = "racket %s --stdout \"%s\" 2>&1" % (fn, rkt_file)
    if not os.access(rkt_file, os.R_OK):
        raise ValueError("Cannot access file %s" % rkt_file)
    pipe = create_popen_file(cmd, "r")
    out = pipe.read()
    err = os.WEXITSTATUS(pipe.close())
    if err != 0:
        raise ExpandException("Racket produced an error and said '%s'" % out)
    return out
コード例 #11
0
def expand_file_rpython(rkt_file, lib=_FN):
    from rpython.rlib.rfile import create_popen_file
    cmd = "racket %s --stdout \"%s\" 2>&1" % (lib, rkt_file)
    if not os.access(rkt_file, os.R_OK):
        raise ValueError("Cannot access file %s" % rkt_file)
    pipe = create_popen_file(cmd, "r")
    out = pipe.read()
    err = os.WEXITSTATUS(pipe.close())
    if err != 0:
        raise ExpandException("Racket produced an error and said '%s'" % out)
    return out
コード例 #12
0
ファイル: exec_.py プロジェクト: CodeOps/hippyvm
def shell_exec(interp, cmd):
    try:
        r_pfile = create_popen_file(cmd, "r")
    except OSError:
        interp.warn("Unable to execute '%s'" % cmd)
        return w_Null
    res = r_pfile.read(-1)
    if res:
        return interp.space.wrap(res)
    else:
        return w_Null
コード例 #13
0
ファイル: racket_entry.py プロジェクト: pycket/pycket
def create_linklet_json(rkt_file_name=""):
    # uses expander's extract to turn it into a linklet
    # gets the bytecodes and uses zo-expand to turn it into a json
    # and loads and instantiates it
    import os
    from pycket.util import os_get_env_var
    from rpython.rlib.rfile import create_popen_file
    PLTHOME = os_get_env_var("PLTHOME")
    EXPANDER_DIR = os.path.join(PLTHOME, os.path.join("racket", os.path.join("src", "expander")))

    # FIXME: error check
    prep_cmd = "raco make -v %s/bootstrap-run.rkt" % EXPANDER_DIR
    pipe1 = create_popen_file(prep_cmd, "r")
    pipe1.read()
    pipe1.close()
    extract_cmd = "racket -t %s/bootstrap-run.rkt -- -c compiled/cache-src/ ++knot read - -s -x -t %s -o compiled/%s.sexp" % (EXPANDER_DIR, rkt_file_name, rkt_file_name)
    pipe2 = create_popen_file(extract_cmd, "r")
    pipe2.read()
    pipe2.close()
    linklet_json_cmd = "racket linklet-extractor/linklet-sexp-to-json.rkt --output %s.linklet compiled/%s.sexp" % (rkt_file_name, rkt_file_name)
    pipe3 = create_popen_file(linklet_json_cmd, "r")
    pipe3.read()
    pipe3.close()
コード例 #14
0
    def execute(self, cmd):
        try:
            from rpython.rlib.rfile import create_popen_file
        except:
            return self.execute_fallback(cmd)

        pipe = create_popen_file(cmd, "r")
        result = pipe.read()
        err = ""
        exit_status = os.WEXITSTATUS(pipe.close())
        if exit_status != 0:
            err = result
            result = ""
        return result, err
コード例 #15
0
 def _call_reader_rpython(self, modus, input):
     tmp_file = os.tmpnam()
     cmd = "racket -l racket/base -t %s -e '(do-read \"%s\")'" % (
         "read.rkt", tmp_file)
     if not os.access("read.rkt", os.R_OK):
         raise Exception("Racket reader can not be accessed")
     pipe = create_popen_file(cmd, "w")
     input = "(%s %s)" % (modus, input)
     # NOTE: might go wrong when dealing with UNICODE
     pipe.write(input)
     pipe.write("\n\0\n")
     pipe.flush()
     err = os.WEXITSTATUS(pipe.close())
     if err != 0:
         raise Exception("Reader produced an unexpected error")
     return tmp_file
コード例 #16
0
def runlpeg(filename):
    changed = False
    if "lpeg" in listdir("."):
        chdir("./lpeg")  # extremly unsafe.
        changed = True
    # i do this because the lpeg import by lua fails if i don't. no clue why.
    if filename in listdir("."):
        c_str = "lua "+filename
        file = create_popen_file(c_str, "r")
        bytecodestring = file.read()
        file.close()
    else:
        bytecodestring = None
    if changed:
        chdir("..")
    return bytecodestring
コード例 #17
0
def expand_code_to_json(code, json_file, stdlib=True, mcons=False, wrap=True):
    from rpython.rlib.rfile import create_popen_file
    try:
        os.remove(json_file)
    except IOError:
        pass
    except OSError:
        pass
    cmd = "racket %s --output \"%s\" --stdin" % (_FN, json_file)
    # print cmd
    pipe = create_popen_file(cmd, "w")
    pipe.write("#lang s-exp pycket%s" % (" #:stdlib" if stdlib else ""))
    pipe.write(code)
    err = os.WEXITSTATUS(pipe.close())
    if err != 0:
        raise ExpandException("Racket produced an error we failed to record")
    return json_file
コード例 #18
0
ファイル: expand.py プロジェクト: magnusmorton/pycket
def expand_code_to_json(code, json_file, stdlib=True, mcons=False, wrap=True):
    from rpython.rlib.rfile import create_popen_file
    try:
        os.remove(json_file)
    except IOError:
        pass
    except OSError:
        pass
    cmd = "racket %s --output \"%s\" --stdin" % (_FN, json_file)
    # print cmd
    pipe = create_popen_file(cmd, "w")
    pipe.write("#lang s-exp pycket%s" % (" #:stdlib" if stdlib else ""))
    pipe.write(code)
    err = os.WEXITSTATUS(pipe.close())
    if err != 0:
        raise ExpandException("Racket produced an error we failed to record")
    return json_file
コード例 #19
0
ファイル: exec_.py プロジェクト: youaani/hippyvm
def passthru(interp, cmd, r_return_var=None):
    space = interp.space
    if not cmd:
        raise ExitFunctionWithError('Cannot execute a blank command')
    try:
        pfile = create_popen_file(cmd, 'r')
    except OSError:
        raise ExitFunctionWithError('Unable to fork [%s]' % cmd, w_Null)
    last_line = ''
    while True:
        line = pfile.read()
        if not line:
            break
        interp.writestr(line, buffer=False)
    exitcode = pfile.close()
    if r_return_var is not None:
        r_return_var.store(space.wrap(exitcode))
    return space.newstr(last_line)
コード例 #20
0
ファイル: exec_.py プロジェクト: CodeOps/hippyvm
def passthru(interp, cmd, r_return_var=None):
    space = interp.space
    if not cmd:
        raise ExitFunctionWithError("Cannot execute a blank command")
    try:
        pfile = create_popen_file(cmd, "r")
    except OSError:
        raise ExitFunctionWithError("Unable to fork [%s]" % cmd, w_Null)
    last_line = ""
    while True:
        line = pfile.read()
        if not line:
            break
        interp.writestr(line, buffer=False)
    exitcode = pfile.close()
    if r_return_var is not None:
        r_return_var.store(space.wrap(exitcode))
    return space.newstr(last_line)
コード例 #21
0
def file_to_AST_str(file_name_str, path=""):
    from config import USE_RPYTHON_POPEN
    out = ""
    c_str = command_str + option_str + " "+path+file_name_str # java call
    if USE_RPYTHON_POPEN:
        from rpython.rlib.rfile import create_popen_file
        file = create_popen_file(c_str, "r")
        out = file.read()
        file.close()
    else:        
        p =  Popen(c_str , shell=True, stderr=PIPE, stdin=PIPE, stdout=PIPE)
        w, r, e = (p.stdin, p.stdout, p.stderr)
        out = r.read()
        err_out = e.read()
        if err_out:
            print err_out
        r.close()
        w.close()
        e.close()
    return del_spaces(out)
コード例 #22
0
def file_to_AST_str_no_print(file_name_str):
    from config import USE_RPYTHON_POPEN
    out = ""
    c_str = command_str + option_str + " "+file_name_str
    #print c_str
    if USE_RPYTHON_POPEN:
        # TODO: remove % s
        from rpython.rlib.rfile import create_popen_file   
        file = create_popen_file(c_str, "r")
        out = file.read()
        file.close()
        return del_spaces(out), None
    else:      
        p =  Popen(c_str, shell=True, stderr=PIPE, stdin=PIPE, stdout=PIPE)
        w, r, e = (p.stdin, p.stdout, p.stderr)
        out = r.read()
        err_out = e.read()
        r.close()
        w.close()
        e.close()
        return del_spaces(out), err_out
コード例 #23
0
ファイル: expand.py プロジェクト: 8l/pycket
def _expand_file_to_json(rkt_file, json_file):
    from rpython.rlib.rfile import create_popen_file
    if not os.access(rkt_file, os.R_OK):
        raise ValueError("Cannot access file %s" % rkt_file)
    if not os.access(rkt_file, os.W_OK):
        # we guess that this means no permission to write the json file
        raise PermException(rkt_file)
    try:
        os.remove(json_file)
    except IOError:
        pass
    except OSError:
        pass
    print "Expanding %s to %s" % (rkt_file, json_file)
    cmd = "racket %s --output \"%s\" \"%s\" 2>&1" % (fn, json_file, rkt_file)
    # print cmd
    pipe = create_popen_file(cmd, "r")
    out = pipe.read()
    err = os.WEXITSTATUS(pipe.close())
    if err != 0:
        raise ExpandException("Racket produced an error and said '%s'" % out)
    return json_file
コード例 #24
0
ファイル: expand.py プロジェクト: uternet/pycket
def _expand_file_to_json(rkt_file, json_file):
    from rpython.rlib.rfile import create_popen_file

    if not os.access(rkt_file, os.R_OK):
        raise ValueError("Cannot access file %s" % rkt_file)
    if not os.access(rkt_file, os.W_OK):
        # we guess that this means no permission to write the json file
        raise PermException(rkt_file)
    try:
        os.remove(json_file)
    except IOError:
        pass
    except OSError:
        pass
    print "Expanding %s to %s" % (rkt_file, json_file)
    cmd = 'racket %s --output "%s" "%s" 2>&1' % (fn, json_file, rkt_file)
    # print cmd
    pipe = create_popen_file(cmd, "r")
    out = pipe.read()
    err = os.WEXITSTATUS(pipe.close())
    if err != 0:
        raise ExpandException("Racket produced an error and said '%s'" % out)
    return json_file
コード例 #25
0
ファイル: test_rfile.py プロジェクト: yuyichao/pypy
 def f():
     f = rfile.create_popen_file(cmd, "r")
     s = f.read()
     assert s == "%s\n" % printval
     return f.close()
コード例 #26
0
ファイル: test_rfile.py プロジェクト: zcxowwww/pypy
 def test_popen(self):
     f = rfile.create_popen_file("python -c 'print 42'", "r")
     s = f.read()
     f.close()
     assert s == '42\n'
コード例 #27
0
ファイル: test_rfile.py プロジェクト: yuyichao/pypy
 def test_popen(self):
     f = rfile.create_popen_file("python -c 'print 42'", "r")
     s = f.read()
     f.close()
     assert s == '42\n'
コード例 #28
0
ファイル: test_rfile.py プロジェクト: zcxowwww/pypy
 def f():
     f = rfile.create_popen_file(cmd, "r")
     s = f.read()
     assert s == "%s\n" % printval
     return f.close()