Exemplo n.º 1
0
Arquivo: sm.py Projeto: certik/pyjamas
def build_script():
    usage = """
    usage: %prog [options] module_name
    """
    parser = OptionParser(usage = usage)
    translator.add_compile_options(parser)
    # override the default because we want print
    parser.set_defaults(print_statements=True)
    linker.add_linker_options(parser)
    options, args = parser.parse_args()
    if len(args) != 1:
        parser.error("incorrect number of arguments")

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    translator_arguments=dict(
        debug=options.debug,
        print_statements = options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source
        )

    l = SpidermonkeyLinker(top_module,
                           output=options.output,
                           platforms=[PLATFORM],
                           path=pyjs.path,
                           translator_arguments=translator_arguments)
    l()
def build_script():
    usage = """
    usage: %prog [options] module_name
    """
    parser = OptionParser(usage=usage)
    translator.add_compile_options(parser)
    # override the default because we want print
    parser.set_defaults(print_statements=True)
    linker.add_linker_options(parser)
    options, args = parser.parse_args()
    if len(args) != 1:
        parser.error("incorrect number of arguments in %s" % repr(sys.argv))

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    translator_arguments = dict(
        debug=options.debug,
        print_statements=options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source)

    l = SpidermonkeyLinker(top_module,
                           output=options.output,
                           platforms=[PLATFORM],
                           path=pyjs.path,
                           translator_arguments=translator_arguments)
    l()
Exemplo n.º 3
0
def build_script():
    usage = """
    usage: %prog [options] module_name
    """
    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"
    )

    # override the default because we want print
    parser.set_defaults(print_statements=True)
    linker.add_linker_options(parser)
    options, args = parser.parse_args()
    if len(args) == 0:
        parser.error("incorrect number of arguments")

    pyjs.path = ["."] + pyjs.path
    #top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    print "paths:", pyjs.path

    translator_arguments = dict(
        debug=options.debug,
        print_statements=options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source,
        inline_code=options.inline_code,
        operator_funcs=options.operator_funcs,
        number_classes=options.number_classes,
    )

    l = PyV8Linker(
        args,  #[top_module],
        output=options.output,
        platforms=[PLATFORM],
        path=pyjs.path,
        compiler=compiler,
        translator_arguments=translator_arguments)
    l()

    return l
Exemplo n.º 4
0
def build_script():
    usage = """
    usage: %prog [options] module_name
    """
    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"
        )

    # override the default because we want print
    parser.set_defaults(print_statements=True)
    linker.add_linker_options(parser)
    options, args = parser.parse_args()
    if len(args) == 0:
        parser.error("incorrect number of arguments")

    pyjs.path = ["."] + pyjs.path
    #top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    print "paths:", pyjs.path

    translator_arguments=dict(
        debug=options.debug,
        print_statements = options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source,
        inline_code = options.inline_code,
        operator_funcs = options.operator_funcs,
        number_classes = options.number_classes,
        )

    l = PyV8Linker(args, #[top_module],
                           output=options.output,
                           platforms=[PLATFORM],
                           path=pyjs.path,
                           compiler=compiler,
                           translator_arguments=translator_arguments)
    l()

    return l
Exemplo n.º 5
0
def build_script():
    usage = """usage: %prog [OPTIONS...] APPLICATION [MODULE...]

Command line interface to the pyjs.org suite: Python Application -> AJAX Application.
APPLICATION is the translation entry point; it MUST be importable by the toolchain.
MODULE(s) will also translate, if available; they MUST be importable by the toolchain."""
    global app_platforms

    parser = OptionParser(usage=usage,
                          epilog='For more information, see http://pyjs.org/')
    parser_group_builder = OptionGroup(
        parser, 'Builder', 'Configures the high-level properties of current '
        'command and final project assembly.')
    parser_group_trans = OptionGroup(
        parser, 'Translator', 'Configures the semantics/expectations of '
        'application code. Each --enable-* implies '
        '--disable-*. Groups modify several options at once.')
    parser_group_linker = OptionGroup(
        parser, 'Linker', 'Configures the includes/destination of application '
        'code, static resources, and project support files.')
    add_builder_options(parser_group_builder)
    translator.add_compile_options(parser_group_trans)
    linker.add_linker_options(parser_group_linker)
    parser.add_option_group(parser_group_builder)
    parser.add_option_group(parser_group_trans)
    parser.add_option_group(parser_group_linker)

    options, _args = parser.parse_args()
    args = []
    for a in _args:
        if a.lower().endswith('.py'):
            args.append(a[:-3])
        else:
            args.append(a)

    if options.log_level is not None:
        import logging
        logging.basicConfig(level=options.log_level)
    if len(args) < 1:
        parser.error("incorrect number of arguments in %s" % repr(
            (sys.argv, options, _args)))

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    if options.platforms:
        app_platforms = options.platforms.lower().split(',')

    if options.multi_file and options.compile_inplace:
        options.compile_inplace = False

    runtime_options = []
    runtime_options.append(("arg_ignore", options.function_argument_checking))
    runtime_options.append(("arg_count", options.function_argument_checking))
    runtime_options.append(
        ("arg_is_instance", options.function_argument_checking))
    runtime_options.append(
        ("arg_instance_type", options.function_argument_checking))
    runtime_options.append(
        ("arg_kwarg_dup", options.function_argument_checking))
    runtime_options.append(
        ("arg_kwarg_unexpected_keyword", options.function_argument_checking))
    runtime_options.append(
        ("arg_kwarg_multiple_values", options.function_argument_checking))
    runtime_options.append(
        ("dynamic_loading", (len(options.unlinked_modules) > 0)))

    build(top_module, pyjs, options, app_platforms, runtime_options, args)

    if not options.auto_build:
        sys.exit(0)

    # autobuild starts here: loops round the current directory file structure
    # looking for file modifications.  extra files in the public folder are
    # copied to output, verbatim (without a recompile) but changes to python
    # files result in a recompile with the exact same compile options.

    first_loop = True

    public_dir = options.public_folder
    output_dir = options.output

    serve(top_module)

    while True:
        for root, dirs, files in os.walk('.'):
            if root[2:].startswith(output_dir):
                continue
            if root[2:].startswith(public_dir):
                for filename in files:
                    file_path = os.path.join(root, filename)
                    if is_modified(file_path) and not first_loop:
                        dest_path = output_dir
                        dest_path += file_path.split(public_dir, 1)[1]
                        dest_dir = os.path.dirname(dest_path)
                        if not os.path.exists(dest_dir):
                            os.makedirs(dest_dir)
                        print('Copying %s to %s' % (file_path, dest_path))
                        shutil.copy(file_path, dest_path)
            else:
                for filename in files:
                    if os.path.splitext(filename)[1] in ('.py', ):
                        file_path = os.path.join(root, filename)
                        if is_modified(file_path) and not first_loop:
                            try:
                                build(top_module, pyjs, options, app_platforms,
                                      runtime_options, args)
                            except Exception:
                                traceback.print_exception(*sys.exc_info())
                            break
        first_loop = False
        time.sleep(1)
Exemplo n.º 6
0
def build_script():
    usage = """
    usage: %prog [options] <application module name>

    This is the command line builder for the pyjamas project, which can
    be used to build Ajax applications from Python.
    For more information, see the website at http://pyjs.org/
    """
    global app_platforms
    parser = OptionParser(usage = usage)
    # TODO: compile options
    translator.add_compile_options(parser)
    linker.add_linker_options(parser)
    parser.add_option("-P", "--platforms", dest="platforms",
        help="platforms to build for, comma-separated")
    parser.add_option("-l", "--log-level", dest="log_level",
                      default=None,
                      type="int",
                      help="The python log level as an int")
    parser.add_option(
        "-m", "--multi-file", dest="multi_file",
        default=False,
        action="store_true",
        help="Include each module via a script-tag instead of writing"
              " the whole code into the main cache.html file")

    parser.add_option(
        "-c", "--cache-buster", action="store_true",
        dest="cache_buster",
        default=False,
        help="Enable browser cache-busting (MD5 hash added to output filenames)",
        )

    parser.add_option(
        "--bootstrap-file", 
        dest="bootstrap_file",
        help="Specify the bootstrap code. (Used when application html file is generated)."
        )

    parser.add_option(
        "--public-folder",
        dest="public_folder",
        help="Specifiy the public folder. (Contents copied into the output dir, see -o)."
        )

    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(
        "--keep-lib-files", dest="keep_lib_files",
        default=False,
        action="store_true",
        help="Keep the files generated in the lib directory"
        )

    parser.set_defaults(output="output",
                        js_includes=[],
                        js_static_includes=[],
                        library_dirs=[],
                        platforms=(','.join(AVAILABLE_PLATFORMS)),
                        bootstrap_file="bootstrap.js",
                        public_folder="public",
                        unlinked_modules=[],
                        )
    options, _args = parser.parse_args()
    args = []
    for a in _args:
        if a.lower().endswith('.py'):
            args.append(a[:-3])
        else:
            args.append(a)

    compiler = translator.import_compiler(options.internal_ast)

    if options.log_level is not None:
        import logging
        logging.basicConfig(level=options.log_level)
    if len(args) < 1:
        parser.error("incorrect number of arguments")

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    if options.platforms:
       app_platforms = options.platforms.lower().split(',')
    print "Building:", top_module
    print "PYJSPATH:", pyjs.path

    runtime_options = []
    runtime_options.append(("arg_ignore", options.function_argument_checking))
    runtime_options.append(("arg_count", options.function_argument_checking))
    runtime_options.append(("arg_is_instance", options.function_argument_checking))
    runtime_options.append(("arg_instance_type", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_dup", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_unexpected_keyword", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_multiple_values", options.function_argument_checking))
    runtime_options.append(("dynamic_loading", (len(options.unlinked_modules)>0)))

    translator_arguments=dict(
        debug=options.debug,
        print_statements = options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        bound_methods=options.bound_methods,
        descriptors=options.descriptors,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source,
        inline_code = options.inline_code,
        operator_funcs = options.operator_funcs,
        number_classes = options.number_classes,
    )

    l = BrowserLinker(args,
                      compiler=compiler,
                      output=options.output,
                      platforms=app_platforms,
                      path=pyjs.path,
                      js_libs=options.js_includes,
                      unlinked_modules=options.unlinked_modules,
                      keep_lib_files=options.keep_lib_files,
                      translator_arguments=translator_arguments,
                      multi_file=options.multi_file,
                      cache_buster=options.cache_buster,
                      bootstrap_file=options.bootstrap_file,
                      public_folder=options.public_folder,
                      runtime_options=runtime_options,
                     )
    l()
    print "Built to :", os.path.abspath(options.output)
Exemplo n.º 7
0
def build_script():
    usage = """
    usage: %prog [options] <application module name>

    This is the command line builder for the pyjamas project, which can
    be used to build Ajax applications from Python.
    For more information, see the website at http://pyjs.org/
    """
    global app_platforms
    parser = OptionParser(usage = usage)
    # TODO: compile options
    translator.add_compile_options(parser)
    linker.add_linker_options(parser)
    parser.add_option("-P", "--platforms", dest="platforms",
        help="platforms to build for, comma-separated")
    parser.add_option("-l", "--log-level", dest="log_level",
                      default=None,
                      type="int",
                      help="The python log level as an int")
    parser.add_option(
        "-m", "--multi-file", dest="multi_file",
        default=False,
        action="store_true",
        help="Include each module via a script-tag instead of writing"
              " the whole code into the main cache.html file")

    parser.add_option("-A", "--auto-build", dest="auto_build",
                      default=False,
                      action="store_true",
                      help="Runs continuous re-builds on file changes")

    parser.add_option("-i", "--list-imports", dest="list_imports",
                      default=False,
                      action="store_true",
                      help="List import dependencies (without compiling)")

    parser.add_option(
        "-c", "--cache-buster", action="store_true",
        dest="cache_buster",
        default=False,
        help="Enable browser cache-busting (MD5 hash added to output filenames)",
        )

    parser.add_option(
        "--bootstrap-file", 
        dest="bootstrap_file",
        help="Specify the bootstrap code. (Used when application html file is generated)."
        )

    parser.add_option(
        "--public-folder",
        dest="public_folder",
        help="Specifiy the public folder. (Contents copied into the output dir, see -o)."
        )

    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(
        "--no-compile-inplace", dest="compile_inplace",
        action="store_false",
        help="Store all js compiled files in output/lib"
        )

    parser.add_option(
        "--no-keep-lib-files", dest="keep_lib_files",
        action="store_false",
        help="Deletes the js compiled files after linking"
        )

    parser.add_option(
        "--compile-inplace", dest="compile_inplace",
        default=True,
        action="store_true",
        help="Store js compiled files in the same place as the python source"
        )

    parser.add_option(
        "--keep-lib-files", dest="keep_lib_files",
        default=True,
        action="store_true",
        help="Keep the js compiled files"
        )

    parser.set_defaults(output="output",
                        js_includes=[],
                        js_static_includes=[],
                        library_dirs=[],
                        platforms=(','.join(AVAILABLE_PLATFORMS)),
                        bootstrap_file="bootstrap.js",
                        public_folder="public",
                        unlinked_modules=[],
                        )
    options, _args = parser.parse_args()
    args = []
    for a in _args:
        if a.lower().endswith('.py'):
            args.append(a[:-3])
        else:
            args.append(a)

    if options.log_level is not None:
        import logging
        logging.basicConfig(level=options.log_level)
    if len(args) < 1:
        parser.error("incorrect number of arguments")

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    if options.platforms:
       app_platforms = options.platforms.lower().split(',')

    if options.multi_file and options.compile_inplace:
        options.compile_inplace = False

    runtime_options = []
    runtime_options.append(("arg_ignore", options.function_argument_checking))
    runtime_options.append(("arg_count", options.function_argument_checking))
    runtime_options.append(("arg_is_instance", options.function_argument_checking))
    runtime_options.append(("arg_instance_type", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_dup", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_unexpected_keyword", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_multiple_values", options.function_argument_checking))
    runtime_options.append(("dynamic_loading", (len(options.unlinked_modules)>0)))

    build(top_module, pyjs, options, app_platforms,
          runtime_options, args)

    if not options.auto_build:
        sys.exit(0)

    # autobuild starts here: loops round the current directory file structure
    # looking for file modifications.  extra files in the public folder are
    # copied to output, verbatim (without a recompile) but changes to python
    # files result in a recompile with the exact same compile options.

    first_loop = True

    public_dir = options.public_folder
    output_dir = options.output

    serve(top_module)

    while True:
        for root, dirs, files in os.walk('.'):
            if root[2:].startswith(output_dir):
                continue
            if root[2:].startswith(public_dir):
                for filename in files:
                    file_path = os.path.join(root, filename)
                    if is_modified(file_path) and not first_loop:
                        dest_path = output_dir
                        dest_path += file_path.split(public_dir, 1)[1]
                        dest_dir = os.path.dirname(dest_path)
                        if not os.path.exists(dest_dir):
                            os.makedirs(dest_dir)
                        print('Copying %s to %s' % (file_path, dest_path))
                        shutil.copy(file_path, dest_path)
            else:
                for filename in files:
                    if os.path.splitext(filename)[1] in ('.py',):
                        file_path = os.path.join(root, filename)
                        if is_modified(file_path) and not first_loop:
                            try:
                              build(top_module, pyjs, options,
                                    app_platforms, runtime_options, args)
                            except Exception:
                              traceback.print_exception(*sys.exc_info())
                            break
        first_loop = False
        time.sleep(1)
Exemplo n.º 8
0
def build_script():
    usage = """usage: %prog [OPTIONS...] APPLICATION [MODULE...]

Command line interface to the pyjs.org suite: Python Application -> AJAX Application.
APPLICATION is the translation entry point; it MUST be importable by the toolchain.
MODULE(s) will also translate, if available; they MUST be importable by the toolchain."""
    global app_platforms

    parser = OptionParser(usage=usage, epilog='For more information, see http://pyjs.org/')
    parser_group_builder = OptionGroup(parser, 'Builder',
                                      'Configures the high-level properties of current '
                                      'command and final project assembly.')
    parser_group_trans = OptionGroup(parser, 'Translator',
                                    'Configures the semantics/expectations of '
                                    'application code. Each --enable-* implies '
                                    '--disable-*. Groups modify several options at once.')
    parser_group_linker = OptionGroup(parser, 'Linker',
                                      'Configures the includes/destination of application '
                                      'code, static resources, and project support files.')
    add_builder_options(parser_group_builder)
    translator.add_compile_options(parser_group_trans)
    linker.add_linker_options(parser_group_linker)
    parser.add_option_group(parser_group_builder)
    parser.add_option_group(parser_group_trans)
    parser.add_option_group(parser_group_linker)

    options, _args = parser.parse_args()
    args = []
    for a in _args:
        if a.lower().endswith('.py'):
            args.append(a[:-3])
        else:
            args.append(a)

    if options.log_level is not None:
        import logging
        logging.basicConfig(level=options.log_level)
    if len(args) < 1:
        parser.error("incorrect number of arguments in %s" % repr((sys.argv, options, _args)))

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    if options.platforms:
       app_platforms = options.platforms.lower().split(',')

    if options.multi_file and options.compile_inplace:
        options.compile_inplace = False

    runtime_options = []
    runtime_options.append(("arg_ignore", options.function_argument_checking))
    runtime_options.append(("arg_count", options.function_argument_checking))
    runtime_options.append(("arg_is_instance", options.function_argument_checking))
    runtime_options.append(("arg_instance_type", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_dup", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_unexpected_keyword", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_multiple_values", options.function_argument_checking))
    runtime_options.append(("dynamic_loading", (len(options.unlinked_modules)>0)))

    build(top_module, pyjs, options, app_platforms,
          runtime_options, args)

    if not options.auto_build:
        sys.exit(0)

    # autobuild starts here: loops round the current directory file structure
    # looking for file modifications.  extra files in the public folder are
    # copied to output, verbatim (without a recompile) but changes to python
    # files result in a recompile with the exact same compile options.

    first_loop = True

    public_dir = options.public_folder
    output_dir = options.output

    serve(top_module)

    while True:
        for root, dirs, files in os.walk('.'):
            if root[2:].startswith(output_dir):
                continue
            if root[2:].startswith(public_dir):
                for filename in files:
                    file_path = os.path.join(root, filename)
                    if is_modified(file_path) and not first_loop:
                        dest_path = output_dir
                        dest_path += file_path.split(public_dir, 1)[1]
                        dest_dir = os.path.dirname(dest_path)
                        if not os.path.exists(dest_dir):
                            os.makedirs(dest_dir)
                        print('Copying %s to %s' % (file_path, dest_path))
                        shutil.copy(file_path, dest_path)
            else:
                for filename in files:
                    if os.path.splitext(filename)[1] in ('.py',):
                        file_path = os.path.join(root, filename)
                        if is_modified(file_path) and not first_loop:
                            try:
                              build(top_module, pyjs, options,
                                    app_platforms, runtime_options, args)
                            except Exception:
                              traceback.print_exception(*sys.exc_info())
                            break
        first_loop = False
        time.sleep(1)
Exemplo n.º 9
0
def build_script():
    usage = """
    usage: %prog [options] <application module name>

    This is the command line builder for the pyjamas project, which can
    be used to build Ajax applications from Python.
    For more information, see the website at http://pyjs.org/
    """
    global app_platforms
    parser = OptionParser(usage = usage)
    # TODO: compile options
    translator.add_compile_options(parser)
    linker.add_linker_options(parser)
    parser.add_option("-P", "--platforms", dest="platforms",
        help="platforms to build for, comma-separated")
    parser.add_option("-l", "--log-level", dest="log_level",
                      default=None,
                      type="int",
                      help="The python log level as an int")
    parser.add_option(
        "-m", "--multi-file", dest="multi_file",
        default=False,
        action="store_true",
        help="Include each module via a script-tag instead of writing"
              " the whole code into the main cache.html file")

    parser.add_option(
        "-c", "--cache-buster", action="store_true",
        dest="cache_buster",
        default=False,
        help="Enable browser cache-busting (MD5 hash added to output filenames)",
        )

    parser.add_option(
        "--bootstrap-file", 
        dest="bootstrap_file",
        help="Specify the bootstrap code. (Used when application html file is generated)."
        )

    parser.add_option(
        "--public-folder",
        dest="public_folder",
        help="Specifiy the public folder. (Contents copied into the output dir, see -o)."
        )

    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(
        "--keep-lib-files", dest="keep_lib_files",
        default=False,
        action="store_true",
        help="Keep the files generated in the lib directory"
        )

    parser.set_defaults(output="output",
                        js_includes=[],
                        js_static_includes=[],
                        library_dirs=[],
                        platforms=(','.join(AVAILABLE_PLATFORMS)),
                        bootstrap_file="bootstrap.js",
                        public_folder="public",
                        unlinked_modules=[],
                        )
    options, _args = parser.parse_args()
    args = []
    for a in _args:
        if a.lower().endswith('.py'):
            args.append(a[:-3])
        else:
            args.append(a)

    compiler = translator.import_compiler(options.internal_ast)

    if options.log_level is not None:
        import logging
        logging.basicConfig(level=options.log_level)
    if len(args) < 1:
        parser.error("incorrect number of arguments")

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    if options.platforms:
       app_platforms = options.platforms.lower().split(',')
    print "Building:", top_module
    print "PYJSPATH:", pyjs.path

    runtime_options = []
    runtime_options.append(("arg_ignore", options.function_argument_checking))
    runtime_options.append(("arg_count", options.function_argument_checking))
    runtime_options.append(("arg_is_instance", options.function_argument_checking))
    runtime_options.append(("arg_instance_type", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_dup", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_unexpected_keyword", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_multiple_values", options.function_argument_checking))
    runtime_options.append(("dynamic_loading", (len(options.unlinked_modules)>0)))

    translator_arguments=dict(
        debug=options.debug,
        print_statements = options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        bound_methods=options.bound_methods,
        descriptors=options.descriptors,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source,
        inline_code = options.inline_code,
        operator_funcs = options.operator_funcs,
        number_classes = options.number_classes,
    )

    l = BrowserLinker(args,
                      compiler=compiler,
                      output=options.output,
                      platforms=app_platforms,
                      path=pyjs.path,
                      js_libs=options.js_includes,
                      unlinked_modules=options.unlinked_modules,
                      keep_lib_files=options.keep_lib_files,
                      translator_arguments=translator_arguments,
                      multi_file=options.multi_file,
                      cache_buster=options.cache_buster,
                      bootstrap_file=options.bootstrap_file,
                      public_folder=options.public_folder,
                      runtime_options=runtime_options,
                     )
    l()
    print "Built to :", os.path.abspath(options.output)
Exemplo n.º 10
0
def build_script():
    usage = """
    usage: %prog [options] <application module name>

    This is the command line builder for the pyjamas project, which can
    be used to build Ajax applications from Python.
    For more information, see the website at http://pyjs.org/
    """
    global app_platforms
    parser = OptionParser(usage=usage)
    # TODO: compile options
    translator.add_compile_options(parser)
    linker.add_linker_options(parser)
    parser.add_option("-P",
                      "--platforms",
                      dest="platforms",
                      help="platforms to build for, comma-separated")
    parser.add_option("-l",
                      "--log-level",
                      dest="log_level",
                      default=None,
                      type="int",
                      help="The python log level as an int")
    parser.add_option(
        "-m",
        "--multi-file",
        dest="multi_file",
        default=False,
        action="store_true",
        help="Include each module via a script-tag instead of writing"
        " the whole code into the main cache.html file")

    parser.add_option("-A",
                      "--auto-build",
                      dest="auto_build",
                      default=False,
                      action="store_true",
                      help="Runs continuous re-builds on file changes")

    parser.add_option("-i",
                      "--list-imports",
                      dest="list_imports",
                      default=False,
                      action="store_true",
                      help="List import dependencies (without compiling)")

    parser.add_option(
        "-c",
        "--cache-buster",
        action="store_true",
        dest="cache_buster",
        default=False,
        help=
        "Enable browser cache-busting (MD5 hash added to output filenames)",
    )

    parser.add_option(
        "--bootstrap-file",
        dest="bootstrap_file",
        help=
        "Specify the bootstrap code. (Used when application html file is generated)."
    )

    parser.add_option(
        "--public-folder",
        dest="public_folder",
        help=
        "Specifiy the public folder. (Contents copied into the output dir, see -o)."
    )

    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("--no-compile-inplace",
                      dest="compile_inplace",
                      action="store_false",
                      help="Store all js compiled files in output/lib")

    parser.add_option("--no-keep-lib-files",
                      dest="keep_lib_files",
                      action="store_false",
                      help="Deletes the js compiled files after linking")

    parser.add_option(
        "--compile-inplace",
        dest="compile_inplace",
        default=True,
        action="store_true",
        help="Store js compiled files in the same place as the python source")

    parser.add_option("--keep-lib-files",
                      dest="keep_lib_files",
                      default=True,
                      action="store_true",
                      help="Keep the js compiled files")

    parser.set_defaults(
        output="output",
        js_includes=[],
        js_static_includes=[],
        library_dirs=[],
        platforms=(','.join(AVAILABLE_PLATFORMS)),
        bootstrap_file="bootstrap.js",
        public_folder="public",
        unlinked_modules=[],
    )
    options, _args = parser.parse_args()
    args = []
    for a in _args:
        if a.lower().endswith('.py'):
            args.append(a[:-3])
        else:
            args.append(a)

    if options.log_level is not None:
        import logging
        logging.basicConfig(level=options.log_level)
    if len(args) < 1:
        parser.error("incorrect number of arguments")

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    if options.platforms:
        app_platforms = options.platforms.lower().split(',')

    if options.multi_file and options.compile_inplace:
        options.compile_inplace = False

    runtime_options = []
    runtime_options.append(("arg_ignore", options.function_argument_checking))
    runtime_options.append(("arg_count", options.function_argument_checking))
    runtime_options.append(
        ("arg_is_instance", options.function_argument_checking))
    runtime_options.append(
        ("arg_instance_type", options.function_argument_checking))
    runtime_options.append(
        ("arg_kwarg_dup", options.function_argument_checking))
    runtime_options.append(
        ("arg_kwarg_unexpected_keyword", options.function_argument_checking))
    runtime_options.append(
        ("arg_kwarg_multiple_values", options.function_argument_checking))
    runtime_options.append(
        ("dynamic_loading", (len(options.unlinked_modules) > 0)))

    build(top_module, pyjs, options, app_platforms, runtime_options, args)

    if not options.auto_build:
        sys.exit(0)

    # autobuild starts here: loops round the current directory file structure
    # looking for file modifications.  extra files in the public folder are
    # copied to output, verbatim (without a recompile) but changes to python
    # files result in a recompile with the exact same compile options.

    first_loop = True

    public_dir = options.public_folder
    output_dir = options.output

    serve(top_module)

    while True:
        for root, dirs, files in os.walk('.'):
            if root[2:].startswith(output_dir):
                continue
            if root[2:].startswith(public_dir):
                for filename in files:
                    file_path = os.path.join(root, filename)
                    if is_modified(file_path) and not first_loop:
                        dest_path = output_dir
                        dest_path += file_path.split(public_dir, 1)[1]
                        dest_dir = os.path.dirname(dest_path)
                        if not os.path.exists(dest_dir):
                            os.makedirs(dest_dir)
                        print('Copying %s to %s' % (file_path, dest_path))
                        shutil.copy(file_path, dest_path)
            else:
                for filename in files:
                    if os.path.splitext(filename)[1] in ('.py', ):
                        file_path = os.path.join(root, filename)
                        if is_modified(file_path) and not first_loop:
                            try:
                                build(top_module, pyjs, options, app_platforms,
                                      runtime_options, args)
                            except Exception:
                                traceback.print_exception(*sys.exc_info())
                            break
        first_loop = False
        time.sleep(1)