Example #1
0
def main():
    (options, args_, parser_) = simple_options(_parser, __version__, __dependencies__)

    try:
        with open(options.input) as xml_file:
            xml_string = xml_file.read()

            # At the moment there doesn't seem to be an obvious way to extract the xmlns from the asset.
            # For now, we'll attempt to just remove it before transforming it into a Python object.

            # <COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
            #   ==>
            # <COLLADA version="1.4.1">
            if options.namespace is False:
                xml_string = sub(' xmlns="[^"]*"', '', xml_string)

            json_string = xml2json(xml_string, indent=options.json_indent, convert_types=options.convert_types)
            if options.output:
                with open(options.output, 'w') as target:
                    target.write(json_string)
                    target.write('\n')
            else:
                print json_string

    except IOError as e:
        LOG.error(e)
        return e.errno
    except Exception as e:
        LOG.critical('Unexpected exception: %s' % e)
        return 1
Example #2
0
def main():
    (options, args_, parser_) = simple_options(_parser, __version__, __dependencies__)

    try:
        with open(options.input) as xml_file:
            xml_string = xml_file.read()

            # At the moment there doesn't seem to be an obvious way to extract the xmlns from the asset.
            # For now, we'll attempt to just remove it before transforming it into a Python object.

            # <COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
            #   ==>
            # <COLLADA version="1.4.1">
            if options.namespace is False:
                xml_string = sub(' xmlns="[^"]*"', '', xml_string)

            json_string = xml2json(xml_string, indent=options.json_indent, convert_types=options.convert_types)
            if options.output:
                with open(options.output, 'w') as target:
                    target.write(json_string)
                    target.write('\n')
            else:
                print json_string

    except IOError as e:
        LOG.error(e)
        return e.errno
    except Exception as e:
        LOG.critical('Unexpected exception: %s', e)
        return 1
Example #3
0
def main():
    (options, args, parser) = simple_options(_parser, __version__,
                                             __dependencies__)

    Profiler.start('main')
    Profiler.start('startup')

    # Sanity checks

    if 0 == len(args):
        LOG.error("no input files specified")
        parser.print_help()
        exit(1)

    if options.mode not in [
            'plugin', 'canvas', 'webworker', 'webworker-debug'
    ]:
        LOG.error("invalid mode %s", options.mode)
        parser.print_help()
        exit(1)

    if options.output is None:
        LOG.error("no output file specified (required in dependency mode)")
        parser.print_help()
        exit(1)

    # Create a jinja2 env

    env = env_create(options)
    input_js = args

    LOG.info("input files: %s", input_js)

    Profiler.stop('startup')
    Profiler.start('run')

    # Execute

    retval = 1
    try:

        if options.dependency:
            LOG.info("dependency generation selected")
            retval = tzjs_dump_dependencies(env, options, input_js)
        else:
            LOG.info("rendering tzjs")
            retval = tzjs_generate(env, options, input_js)

    except ToolsException, e:
        LOG.error(str(e))
        exit(1)
Example #4
0
def main():
    (options, args, parser) = simple_options(_parser, __version__,
                                             __dependencies__)

    Profiler.start('main')
    Profiler.start('startup')

    # Sanity checks

    if 0 == len(args):
        LOG.error("no input files specified")
        parser.print_help()
        exit(1)

    if options.mode not in [ 'plugin', 'canvas' ]:
        LOG.error("invalid mode %s" % options.mode)
        parser.print_help()
        exit(1)

    if options.output is None:
        LOG.error("no output file specified (required in dependency mode)")
        parser.print_help()
        exit(1)

    # Create a jinja2 env

    env = env_create(options)
    input_js = args

    LOG.info("input files: %s" % input_js)

    Profiler.stop('startup')
    Profiler.start('run')

    # Execute

    retval = 1
    try:

        if options.dependency:
            LOG.info("dependency generation selected")
            retval = tzjs_dump_dependencies(env, options, input_js)
        else:
            LOG.info("rendering tzjs")
            retval = tzjs_generate(env, options, input_js)

    except ToolsException, e:
        LOG.error(str(e))
        exit(1)
Example #5
0
def main():
    (options, args, parser_) = simple_options(_parser, __version__, __dependencies__)

    divider = "+-------------------------+----------------------+---------------+------------------------+"
    if options.header:
        print divider
        print "|    keys: punctn: values |     k%:    p%:    v% | # keys:unique |   total:   gzip: ratio |"
        print divider

    def vadd(a, b):
        return tuple([x + y for (x, y) in zip(a, b)])

    def log((keys, punctuation, values, key_count, unique_count, total_size, compressed_size), f):
        k_percent = keys * 100.0 / total_size
        p_percent = punctuation * 100.0 / total_size
        v_percent = values * 100.0 / total_size
        c_percent = compressed_size * 100.0 / total_size
        print "| %7i:%7i:%7i | %5.1f%%:%5.1f%%:%5.1f%% | %6i:%6i | %7i:%7i:%5.1f%% | %s" % \
            (keys, punctuation, values, k_percent, p_percent, v_percent, key_count, unique_count, \
             total_size, compressed_size, c_percent, f)
Example #6
0
def main():
    (options, args_, parser_) = simple_options(_parser, __version__,
                                               __dependencies__)

    source_file = options.input

    LOG.info('%s %s', __file__, source_file)
    LOG.info('input: %s', source_file)

    try:
        with open(source_file, 'r') as source:
            json_asset = json.load(source)

            def find_node(nodes, sub_asset):
                for (k, v) in sub_asset.iteritems():
                    if fnmatch(k, nodes[0]):
                        if len(nodes) == 1:
                            yield (k, sub_asset[k])
                        elif isinstance(v, dict):
                            for n in find_node(nodes[1:], sub_asset[k]):
                                yield n
                            for n in find_node(nodes, sub_asset[k]):
                                yield n

            if options.path:
                node_list = options.path.split('/')

            if options.html:
                renderer = Json2htmlRenderer()
            elif options.color:
                renderer = Json2txtColourRenderer()
            else:
                renderer = Json2txtRenderer()

            disassembler = Disassembler(renderer, options.listcull,
                                        options.dictcull, options.depth)
            expand = True

            if options.output:
                with open(options.output, 'w') as target:
                    if options.path:
                        for name, node in find_node(node_list, json_asset):
                            target.write(name + ': ' +
                                         disassembler.mark_up_asset(
                                             {name: node}, expand))
                            target.write('\n')
                    else:
                        target.write(
                            disassembler.mark_up_asset({'root': json_asset},
                                                       expand))
                        target.write('\n')
            elif options.color:
                if options.path:
                    for name, node in find_node(node_list, json_asset):
                        print '\033[;31m' + name + '\033[;m' + ': ' + disassembler.mark_up_asset(
                            {name: node}, expand),
                else:
                    print disassembler.mark_up_asset({'root': json_asset},
                                                     expand)
            else:
                if options.path:
                    for name, node in find_node(node_list, json_asset):
                        print name + ': ' + disassembler.mark_up_asset(
                            {name: node}, expand),
                else:
                    print disassembler.mark_up_asset({'root': json_asset},
                                                     expand)

    except IOError as e:
        LOG.error(e)
        return e.errno
    except Exception as e:
        LOG.critical('Unexpected exception: %s', e)
        return 1
    return 0
Example #7
0
def main():

    (options, args, parser) = simple_options(_parser, __version__,
                                             __dependencies__, input_required=False)

    Profiler.start('main')
    Profiler.start('startup')

    input_files = args

    # Check that if dump-default-template is set then output and exit

    if options.dump_default_template:
        exit(dump_default_template(options.output))
    elif 0 == len(args):
        LOG.error('No input files specified')
        parser.print_help()
        exit(1)

    LOG.info("options: %s" % options)
    LOG.info("args: %s" % args)
    LOG.info("parser: %s" % parser)
    LOG.info("templatedirs: %s" % options.templatedirs)

    if options.output is None:
        LOG.error("no output file specified (required in dependency mode)")
        parser.print_help()
        exit(1)

    # Check mode

    if options.mode not in [ 'plugin-debug', 'plugin', 'canvas-debug', 'canvas' ]:
        LOG.error('Unrecognised mode: %s' % options.mode)
        parser.print_help()
        exit(1)

    # Check a release source name is given if mode is one of release
    # or canvas

    if options.mode in [ 'plugin', 'canvas' ] and \
            not options.dependency and \
            not options.codefile:
        LOG.error('Missing code file name.  Use --code to specify.')
        parser.print_usage()
        exit(1)

    # Check input files and split them into (ordered) js and html

    (input_js, input_html) = check_input(input_files)

    LOG.info("js files: %s" % input_js)
    LOG.info("html files: %s" % input_html)

    # In debug and canvas-debug we need a .js input file

    if 0 == len(input_js):
        if options.mode in [ 'debug', 'canvas-debug' ]:
            LOG.error('Missing input .js file')
            parser.print_usage()
            exit(1)
    if 1 < len(input_html):
        LOG.error('Multiple html files specified: %s' % input_html)
        exit(1)

    # Create a jinja2 env

    env = env_create(options, DEFAULT_HTML_TEMPLATE)

    Profiler.stop('startup')
    Profiler.start('run')

    # Execute

    retval = 1
    try:

        if options.dependency:
            LOG.info("generating dependencies")
            retval = html_dump_dependencies(env, options, input_js, input_html)
            LOG.info("done generating dependencies")

        else:
            retval = html_generate(env, options, input_js, input_html)

    except ToolsException, e:
        #traceback.print_exc()
        LOG.error("%s" % str(e))
Example #8
0
def main():
    (options, args_, parser_) = simple_options(_parser, __version__, __dependencies__)

    source_file = options.input

    LOG.info('%s %s', __file__, source_file)
    LOG.info('input: %s', source_file)

    try:
        with open(source_file, 'r') as source:
            json_asset = json.load(source)

            def find_node(nodes, sub_asset):
                for (k, v) in sub_asset.iteritems():
                    if fnmatch(k, nodes[0]):
                        if len(nodes) == 1:
                            yield (k, sub_asset[k])
                        elif isinstance(v, dict):
                            for n in find_node(nodes[1:], sub_asset[k]):
                                yield n
                            for n in find_node(nodes, sub_asset[k]):
                                yield n

            if options.path:
                node_list = options.path.split('/')

            if options.html:
                renderer = Json2htmlRenderer()
            elif options.color:
                renderer = Json2txtColourRenderer()
            else:
                renderer = Json2txtRenderer()

            disassembler = Disassembler(renderer, options.listcull, options.dictcull, options.depth)
            expand = True

            if options.output:
                with open(options.output, 'w') as target:
                    if options.path:
                        for name, node in find_node(node_list, json_asset):
                            target.write(name + ': ' + disassembler.mark_up_asset({name: node}, expand))
                            target.write('\n')
                    else:
                        target.write(disassembler.mark_up_asset({'root': json_asset}, expand))
                        target.write('\n')
            elif options.color:
                if options.path:
                    for name, node in find_node(node_list, json_asset):
                        print '\033[;31m' + name + '\033[;m' + ': ' + disassembler.mark_up_asset({name: node}, expand),
                else:
                    print disassembler.mark_up_asset({'root': json_asset}, expand)
            else:
                if options.path:
                    for name, node in find_node(node_list, json_asset):
                        print name + ': ' + disassembler.mark_up_asset({name: node}, expand),
                else:
                    print disassembler.mark_up_asset({'root': json_asset}, expand)

    except IOError as e:
        LOG.error(e)
        return e.errno
    except Exception as e:
        LOG.critical('Unexpected exception: %s', e)
        return 1
    return 0
Example #9
0
def main():
    (options, args_, parser_) = simple_options(_parser, __version__, __dependencies__)

    # Cleanly handle asset location
    asset_root = options.asset_root.replace('\\', '/').rstrip('/')

    def _filename(filename):
        if filename[0] == '/':
            return asset_root + filename
        else:
            return asset_root + '/' + filename

    tar_file = DependencyTar()

    LOG.info('%s %s' % (__file__, options.input))
    LOG.info('input: %s' % options.input)

    try:
        with open(options.input, 'r') as source:
            json_asset = json.load(source)
            if not options.dependency:
                tar_file = tarfile.open(options.output, 'w')
            image_map = { }
            (added, missed, skipped) = (0, 0, 0)
            for image_name, texture_stage_ in images_in_asset(json_asset):
                # This is probably a procedural image - skip it
                if image_name not in image_map:
                    # We used to convert .tga -> .png, .cubemap -> .dds, and support dropping mips from dds files.
                    # Currently this is disabled until we integrate the tool with a build process.
                    # Alternatively we expect this conversion to happen in the image pipeline.
                    try:
                        image_path = _filename(image_name)
                        if os.path.exists(image_path):
                            # Actually do the tar add
                            tar_file.add(image_path, image_name)
                            LOG.info('adding: %s' % image_name)
                            image_path = image_path.replace("\\", "/")
                            added += 1
                        else:
                            # We don't mind if files are missing
                            LOG.warning('missing: %s' % image_name)
                            missed += 1
                    except OSError:
                        # We don't mind if files are missing
                        LOG.warning('missing: %s' % image_name)
                        missed += 1
                    image_map[image_name] = 0
                else:
                    LOG.info('skipping: %s' % image_name)
                    skipped += 1
                image_map[image_name] += 1
            tar_file.close()
            LOG.info('output: %s' % options.output)
            LOG.info('report: added %i, missing %i, skipped %i' % (added, missed, skipped))
    except IOError as e:
        LOG.error(e)
        return e.errno
    except Exception as e:
        LOG.critical('Unexpected exception: %s' % e)
        return 1

    if options.dependency:
        if options.dependency_file:
            LOG.info('writing dependencies: %s' % options.dependency_file)
            dep_file = open(options.dependency_file, 'w')

            for dep in tar_file.items():
                dep_file.write("%s\n" % dep)
            dep_file.close()
        else:
            for dep in tar_file.items():
                print dep
            print

    return 0
Example #10
0
def main():
    (options, args_, parser_) = simple_options(_parser, __version__,
                                               __dependencies__)

    # Cleanly handle asset location
    asset_root = options.asset_root.replace('\\', '/').rstrip('/')

    def _filename(filename):
        if filename[0] == '/':
            return asset_root + filename
        else:
            return asset_root + '/' + filename

    tar_file = DependencyTar()

    LOG.info('%s %s' % (__file__, options.input))
    LOG.info('input: %s' % options.input)

    try:
        with open(options.input, 'r') as source:
            json_asset = json.load(source)
            if not options.dependency:
                tar_file = tarfile.open(options.output, 'w')
            image_map = {}
            (added, missed, skipped) = (0, 0, 0)
            for image_name, texture_stage_ in images_in_asset(json_asset):
                # This is probably a procedural image - skip it
                if image_name not in image_map:
                    # We used to convert .tga -> .png, .cubemap -> .dds, and support dropping mips from dds files.
                    # Currently this is disabled until we integrate the tool with a build process.
                    # Alternatively we expect this conversion to happen in the image pipeline.
                    try:
                        image_path = _filename(image_name)
                        if os.path.exists(image_path):
                            # Actually do the tar add
                            tar_file.add(image_path, image_name)
                            LOG.info('adding: %s' % image_name)
                            image_path = image_path.replace("\\", "/")
                            added += 1
                        else:
                            # We don't mind if files are missing
                            LOG.warning('missing: %s' % image_name)
                            missed += 1
                    except OSError:
                        # We don't mind if files are missing
                        LOG.warning('missing: %s' % image_name)
                        missed += 1
                    image_map[image_name] = 0
                else:
                    LOG.info('skipping: %s' % image_name)
                    skipped += 1
                image_map[image_name] += 1
            tar_file.close()
            LOG.info('output: %s' % options.output)
            LOG.info('report: added %i, missing %i, skipped %i' %
                     (added, missed, skipped))
    except IOError as e:
        LOG.error(e)
        return e.errno
    except Exception as e:
        LOG.critical('Unexpected exception: %s' % e)
        return 1

    if options.dependency:
        if options.dependency_file:
            LOG.info('writing dependencies: %s' % options.dependency_file)
            dep_file = open(options.dependency_file, 'w')

            for dep in tar_file.items():
                dep_file.write("%s\n" % dep)
            dep_file.close()
        else:
            for dep in tar_file.items():
                print dep
            print

    return 0
Example #11
0
def main():

    (options, args, parser) = simple_options(_parser,
                                             __version__,
                                             __dependencies__,
                                             input_required=False)

    Profiler.start('main')
    Profiler.start('startup')

    input_files = args

    # Check that if dump-default-template is set then output and exit

    if options.dump_default_template:
        exit(dump_default_template(options.output))
    elif 0 == len(args):
        LOG.error('No input files specified')
        parser.print_help()
        exit(1)

    LOG.info("options: %s", options)
    LOG.info("args: %s", args)
    LOG.info("parser: %s", parser)
    LOG.info("templatedirs: %s", options.templatedirs)

    if options.output is None:
        LOG.error("no output file specified (required in dependency mode)")
        parser.print_help()
        exit(1)

    # Check mode

    if options.mode not in [
            'plugin-debug', 'plugin', 'canvas-debug', 'canvas'
    ]:
        LOG.error('Unrecognised mode: %s', options.mode)
        parser.print_help()
        exit(1)

    # Check a release source name is given if mode is one of release
    # or canvas

    if options.mode in [ 'plugin', 'canvas' ] and \
            not options.dependency and \
            not options.codefile:
        LOG.error('Missing code file name.  Use --code to specify.')
        parser.print_usage()
        exit(1)

    # Check input files and split them into (ordered) js and html

    (input_js, input_html) = check_input(input_files)

    LOG.info("js files: %s", input_js)
    LOG.info("html files: %s", input_html)

    # In debug and canvas-debug we need a .js input file

    if 0 == len(input_js):
        if options.mode in ['debug', 'canvas-debug']:
            LOG.error('Missing input .js file')
            parser.print_usage()
            exit(1)
    if 1 < len(input_html):
        LOG.error('Multiple html files specified: %s', input_html)
        exit(1)

    # Create a jinja2 env

    env = env_create(options, DEFAULT_HTML_TEMPLATE)

    Profiler.stop('startup')
    Profiler.start('run')

    # Execute

    retval = 1
    try:

        if options.dependency:
            LOG.info("generating dependencies")
            retval = html_dump_dependencies(env, options, input_js, input_html)
            LOG.info("done generating dependencies")

        else:
            retval = html_generate(env, options, input_js, input_html)

    except ToolsException, e:
        #traceback.print_exc()
        LOG.error("%s", str(e))