Пример #1
0
def main():
    usage = """
    usage: %prog [ options ] [ -c command | module_name | script | - ] [ -- arguments ]
    """
    parser = OptionParser(usage = usage)
    translator.add_compile_options(parser)

    parser.add_option(
        "--dynamic",
        dest="unlinked_modules",
        action="append",
        help="regular expression for modules that will not be linked"
        "and thus loaded dynamically"
        )
    parser.add_option(
        "-c",
        dest="command",
        help="Python command to run")
    
    # override the default because we want print
    parser.set_defaults(print_statements=True)
    add_linker_options(parser)
    options, args = parser.parse_args()
    IS_REPL = False
    if len(args) == 0 or args[0] == '-':
        IS_REPL = True
        modules = ['main']
    else:
        modules = args

    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    #print "paths:", pyjs.path
    translator_arguments = translator.get_compile_options(options)
    linker = PyV8Linker(modules, output=options.output,
                        platforms=[PLATFORM],
                        path=pyjs.path,
                        compiler=compiler,
                        translator_arguments=translator_arguments)
    linker()
    
    fp = open(linker.out_file_mod, 'r')
    txt = fp.read()
    fp.close()

    #PyV8.debugger.enabled = True
    
    # create a context with an explicit global
    g = Global()
    ctxt = PyV8.JSContext(g)
    g.__context__ = ctxt
    # enter the context
    ctxt.enter()
    try:
        x = ctxt.eval(txt)
    except Exception, e:
        raise
Пример #2
0
def main():
    usage = """
    usage: %prog [ options ] [ -c command | module_name | script | - ] [ -- arguments ]
    """
    parser = OptionParser(usage=usage)
    translator.add_compile_options(parser)

    parser.add_option(
        "--dynamic",
        dest="unlinked_modules",
        action="append",
        help="regular expression for modules that will not be linked"
        "and thus loaded dynamically")
    parser.add_option("-c", dest="command", help="Python command to run")

    # override the default because we want print
    parser.set_defaults(print_statements=True)
    add_linker_options(parser)
    options, args = parser.parse_args()
    IS_REPL = False
    if len(args) == 0 or args[0] == '-':
        IS_REPL = True
        modules = ['main']
    else:
        modules = args

    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    #print "paths:", pyjs.path
    translator_arguments = translator.get_compile_options(options)
    linker = PyV8Linker(modules,
                        output=options.output,
                        platforms=[PLATFORM],
                        path=pyjs.path,
                        compiler=compiler,
                        translator_arguments=translator_arguments)
    linker()

    fp = open(linker.out_file_mod, 'r')
    txt = fp.read()
    fp.close()

    #PyV8.debugger.enabled = True

    # create a context with an explicit global
    g = Global()
    ctxt = PyV8.JSContext(g)
    g.__context__ = ctxt
    # enter the context
    ctxt.enter()
    try:
        x = ctxt.eval(txt)
    except Exception, e:
        raise
Пример #3
0
def main():
    usage = """
    usage: %prog [ options ] [ -c command | module_name | script | - ] [ -- arguments ]
    """
    parser = OptionParser(usage = usage)
    translator.add_compile_options(parser)

    parser.add_option(
        "-c",
        dest="command",
        help="Python command to run")

    args = sys.argv[1:]
    app_args = []
    if '--' in args:
        idx = args.index('--')
        app_args = args[idx+1:]
        args = args[0:idx]
    # override the default because we want print
    parser.set_defaults(print_statements=True)
    add_linker_options(parser)
    options, args = parser.parse_args(args)
    IS_REPL = False
    if len(args) == 0 or args[0] == '-':
        IS_REPL = True
        modules = ['main']
    else:
        modules = args

    app_args[0:0] = [modules[0]]

    _modules = []
    for mod in modules:
        if mod.startswith('.') or mod.startswith('/') or mod.endswith('.py'):
            pyjs.path[0:0] = [os.path.dirname(os.path.abspath(mod))]
            _modules.append(os.path.basename(mod).split('.')[0])
        else:
            _modules.append(mod)
    modules = _modules

    pyjs.path[0:0] = [join(pyjs.pyjspth, 'stdlib')]
    pyjs.path.append(join(pyjs.pyjspth, 'pyjs', 'src'))

    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    #print "paths:", pyjs.path
    translator_arguments = translator.get_compile_options(options)
    linker = PyV8Linker(modules, output=options.output,
                        platforms=[PLATFORM],
                        path=pyjs.path,
                        compiler=translator.compiler,
                        translator_arguments=translator_arguments)
    linker()

    fp = open(linker.out_file_mod, 'r')
    txt = fp.read()
    fp.close()

    #PyV8.debugger.enabled = True

    # create a context with an explicit global
    g = Global(app_args, pyjs.path)
    ctxt = PyV8.JSContext(g)
    g.__context__ = ctxt
    # enter the context
    ctxt.enter()
    try:
        x = ctxt.eval(txt)
    except Exception, e:
        print JSRuntimeError(ctxt, e).full()