<s> import PyV8 <EOL> import os <EOL> import sys <EOL> from os . path import join , dirname , basename , abspath <EOL> from optparse import OptionParser <EOL> usage = """<STR_LIT>""" <EOL> currentdir = abspath ( dirname ( __file__ ) ) <EOL> pyjspth = abspath ( join ( dirname ( __file__ ) , "<STR_LIT:..>" ) ) <EOL> sys . path = [ ( join ( pyjspth , "<STR_LIT>" , "<STR_LIT:src>" ) ) ] + sys . path <EOL> import pyjs <EOL> pyjs . pyjspth = pyjspth <EOL> pyjs . path += [ os . path . join ( pyjspth , '<STR_LIT>' ) , <EOL> os . path . join ( pyjspth , '<STR_LIT>' ) , <EOL> ] <EOL> from pyjs import translator <EOL> from linker import PLATFORM , PyV8Linker , add_linker_options <EOL> from jsglobal import Global <EOL> class JSRuntimeError ( Exception ) : <EOL> def __init__ ( self , ctxt , exc ) : <EOL> self . module = ctxt . locals [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . lineno = ctxt . locals [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . traceback = self . get_traceback ( ctxt . locals [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT::>' in exc . message and not '<STR_LIT:U+0020>' in exc . message . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] : <EOL> errortype , errortext = exc . message . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> self . jserrortype = errortype <EOL> self . jserrortext = errortext <EOL> else : <EOL> self . jserrortype = exc . __class__ . __name__ <EOL> self . jserrortext = exc . message <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" . format ( self ) <EOL> def full ( self ) : <EOL> return ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( self , trace = self . get_traceback_text ( ) ) ) <EOL> def get_traceback ( self , jstb ) : <EOL> tb = [ ] <EOL> for x in jstb : <EOL> tb . append ( dict ( module = x [ '<STR_LIT>' ] , lineno = x [ '<STR_LIT>' ] ) ) <EOL> return tb <EOL> def get_traceback_text ( self ) : <EOL> trace = [ ] <EOL> for x in self . traceback : <EOL> trace . append ( "<STR_LIT>" . format ( x [ '<STR_LIT>' ] , x [ '<STR_LIT>' ] ) ) <EOL> return "<STR_LIT:\n>" . join ( trace ) <EOL> def main ( ) : <EOL> usage = """<STR_LIT>""" <EOL> parser = OptionParser ( usage = usage ) <EOL> translator . add_compile_options ( parser ) <EOL> parser . add_option ( <EOL> "<STR_LIT:-c>" , <EOL> dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> args = sys . argv [ <NUM_LIT:1> : ] <EOL> app_args = [ ] <EOL> if '<STR_LIT>' in args : <EOL> idx = args . index ( '<STR_LIT>' ) <EOL> app_args = args [ idx + <NUM_LIT:1> : ] <EOL> args = args [ <NUM_LIT:0> : idx ] <EOL> parser . set_defaults ( print_statements = True ) <EOL> add_linker_options ( parser ) <EOL> options , args = parser . parse_args ( args ) <EOL> IS_REPL = False <EOL> if len ( args ) == <NUM_LIT:0> or args [ <NUM_LIT:0> ] == '<STR_LIT:->' : <EOL> IS_REPL = True <EOL> modules = [ '<STR_LIT>' ] <EOL> else : <EOL> modules = args <EOL> app_args [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ modules [ <NUM_LIT:0> ] ] <EOL> _modules = [ ] <EOL> for mod in modules : <EOL> if mod . startswith ( '<STR_LIT:.>' ) or mod . startswith ( '<STR_LIT:/>' ) or mod . endswith ( '<STR_LIT>' ) : <EOL> pyjs . path [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ os . path . dirname ( os . path . abspath ( mod ) ) ] <EOL> _modules . append ( os . path . basename ( mod ) . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> _modules . append ( mod ) <EOL> modules = _modules <EOL> pyjs . path [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ join ( pyjs . pyjspth , '<STR_LIT>' ) ] <EOL> pyjs . path . append ( join ( pyjs . pyjspth , '<STR_LIT>' , '<STR_LIT:src>' ) ) <EOL> for d in options . library_dirs : <EOL> pyjs . path . append ( os . path . abspath ( d ) ) <EOL> translator_arguments = translator . get_compile_options ( options ) <EOL> linker = PyV8Linker ( modules , output = options . output , <EOL> platforms = [ PLATFORM ] , <EOL> path = pyjs . path , <EOL> compiler = translator . compiler , <EOL> translator_arguments = translator_arguments ) <EOL> linker ( ) <EOL> fp = open ( linker . out_file_mod , '<STR_LIT:r>' ) <EOL> txt = fp . read ( ) <EOL> fp . close ( ) <EOL> g = Global ( app_args , pyjs . path ) <EOL> ctxt = PyV8 . JSContext ( g ) <EOL> g . __context__ = ctxt <EOL> ctxt . enter ( ) <EOL> try : <EOL> x = ctxt . eval ( txt ) <EOL> except Exception , e : <EOL> print JSRuntimeError ( ctxt , e ) . full ( ) <EOL> if IS_REPL : <EOL> from repl import REPL <EOL> REPL ( translator . compiler , linker , translator_arguments , g , ctxt ) ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
