def main():
    parser = ArgumentParser()
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='Verbose logging')
    parser.add_argument('-d',
                        '--dump-tree',
                        action='store_true',
                        help='Dump tree')
    parser.add_argument('-o',
                        '--dump-orphans',
                        action='store_true',
                        help='Dump orphans tree')
    parser.add_argument('-f', '--filter', help='Filter output')
    options = parser.parse_args()

    if options.verbose:
        logging_config(
            level='INFO',
            format='[%(levelname)s %(module)s@%(lineno)d] %(message)s')
    else:
        logging_config(format='[%(levelname)s] %(message)s')

    if options.filter:
        filter_re = re_compile(options.filter)
    else:
        filter_re = None

    root, orphans = process()

    def _log(node, indent=''):
        if len(node) == 0:
            asset = node.attributes['asset']
            owners = ', '.join(asset['ownerNames'])
            if (filter_re and filter_re.search(owners)) or not filter_re:

                if asset.get('explicitlyTrashed', False):
                    trashed = ' - TRASHED'
                else:
                    trashed = ''

                print '%s- "%s" (%s)%s' % (indent, node.attributes['name'],
                                           owners, trashed)
        else:
            print '%s-+ %s' % (indent, node.attributes['name'])
            if len(indent) > 0 and indent[-1] == '\\':
                indent = indent[:-1] + ' '
            for r in node[:-1]:
                _log(r, indent + ' |')
            else:
                _log(node[-1], indent + ' \\')

    if options.dump_tree:
        _log(root)
    if options.dump_orphans:
        _log(orphans)

    return 0
Exemple #2
0
def handle_message(event):
    """
    This function is LINE webhook handler.
    """
    logging.logging_config()
    c.REPLY_TOKEN = event.reply_token
    r = di()
    r.exec_router(event.message.text)
def main():
    parser = ArgumentParser()
    parser.add_argument("-v", "--verbose", action="store_true", help="Verbose logging")
    parser.add_argument("-d", "--dump-tree", action="store_true", help="Dump tree")
    parser.add_argument("-o", "--dump-orphans", action="store_true", help="Dump orphans tree")
    parser.add_argument("-f", "--filter", help="Filter output")
    options = parser.parse_args()

    if options.verbose:
        logging_config(level="INFO", format="[%(levelname)s %(module)s@%(lineno)d] %(message)s")
    else:
        logging_config(format="[%(levelname)s] %(message)s")

    if options.filter:
        filter_re = re_compile(options.filter)
    else:
        filter_re = None

    root, orphans = process()

    def _log(node, indent=""):
        if len(node) == 0:
            asset = node.attributes["asset"]
            owners = ", ".join(asset["ownerNames"])
            if (filter_re and filter_re.search(owners)) or not filter_re:

                if asset.get("explicitlyTrashed", False):
                    trashed = " - TRASHED"
                else:
                    trashed = ""

                print '%s- "%s" (%s)%s' % (indent, node.attributes["name"], owners, trashed)
        else:
            print "%s-+ %s" % (indent, node.attributes["name"])
            if len(indent) > 0 and indent[-1] == "\\":
                indent = indent[:-1] + " "
            for r in node[:-1]:
                _log(r, indent + " |")
            else:
                _log(node[-1], indent + " \\")

    if options.dump_tree:
        _log(root)
    if options.dump_orphans:
        _log(orphans)

    return 0
Exemple #4
0
def main():
    parser = OptionParser()
    parser.add_option('--clean', action='store_true', default=False, help="Clean build output")
    parser.add_option('--assets', action='store_true', default=False, help="Build assets")
    parser.add_option('--code', action='store_true', default=False, help="Build code")
    parser.add_option('--all', action='store_true', default=False, help="Build everything")

    parser.add_option('--find-non-ascii', action='store_true', default=False,
                      help="Searches for non ascii characters in the scripts")
    parser.add_option('--template', dest='templateName', help="Specify the template to build")
    parser.add_option('--closure', default=None, help="Path to Closure")
    parser.add_option('--yui', default=None, help="Path to YUI")
    parser.add_option('--threads', default=4, help="Number of threads to use")
    parser.add_option('--verbose', action='store_true', help="Prints additional information about the build process")
    (options, args) = parser.parse_args()

    if options.verbose:
        logging_config(level='INFO', format='[%(levelname)s %(module)s@%(lineno)d] %(message)s')
    else:
        logging_config(format='[%(levelname)s] %(message)s')

    env = {}

    _log_stage('CONFIGURING')
    if not configure(env, options):
        error('Failed to configure build')
        return 1

    if options.find_non_ascii:
        _log_stage('NON-ASCII CHARACTERS')
        count = find_non_ascii(env['APP_SCRIPTS'], env)
        if count > 0:
            error("Found non-ascii character in script")
        else:
            info("Only ASCII found!")
        return count

    if options.clean:
        _log_stage('CLEANING')
        success = clean(env)
        if not success:
            error('Failed to clean build')
            return 1
        else:
            info('Cleaned')

    if options.assets or options.all:
        _log_stage("ASSET BUILD (may be slow - only build code with --code)")

        # Mapping table
        mkdir('staticmax')
        (mapping_table_obj, build_deps) = gen_mapping('assets', 'staticmax',
            ['.pdf', '.mtl', '.otf', '.txt', '.cgh', '.mb'])
        debug('assets:src:%s' % build_deps)
        urn_mapping = mapping_table_obj['urnmapping']

        def _write_mapping_table():
            print '%i assets -> %s' % (len(urn_mapping), env['MAPPING_TABLE'])
            with open(env['APP_MAPPING_TABLE'], 'w') as f:
                json_dump(mapping_table_obj, f, separators=(',', ':'))

        # Write mapping table
        _write_mapping_table()

        longest = len(max(build_deps, key=len)) + 2
        def _log(src, dest, skipping=False):
            msg = '(skipping) ' if skipping else ''
            print '{0:-<{longest}}> {2}{1}'.format(src + ' ', dest, msg, longest=longest)

        metrics = dict(built=0, skipped=0, failed=0)
        def build(src):
            dest = build_deps[src]
            if path_exists(dest):
                _log(src, dest, True)
                metrics['skipped'] += 1
            else:
                _log(src, dest)
                success = build_asset(src, dest, env, options)
                if not success:
                    # Bit of a hack to remove the failed asset from the mapping table.
                    asset = src[len('assets/'):]
                    del urn_mapping[asset]
                    info('Removing asset from mapping table: %s' % asset)
                    metrics['failed'] += 1
                else:
                    metrics['built'] += 1

        class Builder(Thread):
            def __init__(self, assets):
                Thread.__init__(self)
                self.assets = assets

            def run(self):
                map(build, self.assets)

        assets = build_deps.keys()
        num_threads = int(options.threads)
        threads = [Builder(assets[i::num_threads]) for i in range(num_threads)]
        for t in threads:
            t.start()
        for t in threads:
            t.join()
        else:
            del threads

        # Write mapping table
        _write_mapping_table()

        _log_stage("BUILT: %i - SKIPPED: %i - FAILED: %i" % (metrics['built'], metrics['skipped'], metrics['failed']))

    if options.code or options.all:
        _log_stage('CODE BUILD')
        if options.templateName:
            code_files = ['%s.js' % path_join('templates', options.templateName)]
        else:
            code_files = glob('templates/*.js')
        debug("code:src:%s" % code_files)

        for src in code_files:
            (code_base, code_ext) = path_splitext(path_split(src)[1])
            code_dests = [ code_base + ".canvas.debug.html",
                           code_base + ".canvas.release.html",
                           code_base + ".canvas.default.debug.html",
                           code_base + ".canvas.default.release.html",
                           code_base + ".canvas.js",
                           code_base + ".debug.html",
                           code_base + ".release.html",
                           code_base + ".default.debug.html",
                           code_base + ".default.release.html",
                           code_base + ".tzjs" ]
            debug("code:dest:%s" % code_dests)

            for dest in code_dests:
                print '%s -> %s' % (src, dest)
                success = build_code(src, dest, env, options)
                if not success:
                    warning('failed')

    _log_stage('END')

    return 0
def main():

    result = 0
    env = {}

    templates = ['app']
    shaders = [] # Ignore temporarily ['draw2D']

    parser = OptionParser()

    parser.add_option('--clean', action='store_true', default=False, help="Only builds")
    parser.add_option('--clean-only', action='store_true', default=False, help="Only cleans")
    parser.add_option('--code-only', action='store_true', default=False, help="Build only the game code")
    parser.add_option('--template', dest='templateName', help="Specify the template to build")
    parser.add_option('--find-non-ascii', action='store_true', default=False,
                      help="Searches for non ascii characters in the scripts")
    parser.add_option('--development', action='store_true', help="Only builds the development build")
    parser.add_option('--closure', action='store_true', default=False, help="Use Google Closure to post process")
    parser.add_option('--verbose', action='store_true', help="Prints additional information about the build process")
    (options, args) = parser.parse_args()

    if options.verbose:
        logging_config(level='INFO', format='[%(levelname)s @%(lineno)d] %(message)s')
    else:
        logging_config(format='[%(levelname)s] %(message)s')

    if not configure(env, options):
        result = 1
        print 'Failed to configure build'
        return result

    if options.find_non_ascii:
        result = find_non_ascii(env['APP_SCRIPTS'], env, options)
        if result != 0:
            print "Found non-ascii character in script"
        else:
            print "Only ASCII found!"
        return result

    # Clean only
    if options.clean_only:
        result = clean(env, options)
        if result != 0:
            print 'Failed to clean build'
        else:
            print 'Cleaned'
        return result

    # Clean build first
    if options.clean:
        result = clean(env, options)
        if result != 0:
            print 'Failed to clean build'
            return result

        print 'Cleaned'

    # Asset build
    if len(args) > 0:
        files = args
    else:

        if not options.code_only:

            print ""
            print "----------------------------------------------------------"
            print "   ASSET BUILD (may be slow - disable with --code-only)"
            print "----------------------------------------------------------"
            print ""

            # Mapping table

            if not os.path.exists('staticmax'):
               os.makedirs('staticmax')
            (mapping_table_obj, build_deps) = gen_mapping('assets', 'staticmax')

            # Write mapping table

            with open('mapping_table.json', 'wb') as f:
                json_dump(mapping_table_obj, f, separators=(',', ':'))

            # Build all asset files

            # print "Deps: %s" % build_deps

            for src in build_deps:
                dest = build_deps[src]
                print "Building %s -> %s" % (src, dest)

                result = do_build(src, dest, env, options)
                if result:
                    print "Build failed"
                    exit(1)

        # Code

        print ""
        print "----------------------------------------------------------"
        print "                   CODE BUILD"
        print "----------------------------------------------------------"
        print ""

        if options.templateName:
            code_files = [os.path.join('templates/', options.templateName) + '.js']
        else:
            code_files = glob.glob('templates/*.js')

        # print "CODE FILES: %s" % code_files

        for f in code_files:
            print " APP: %s" % f
            (code_base, code_ext) = os.path.splitext(os.path.split(f)[1])

            code_dests = [ code_base + ".canvas.debug.html",

                           code_base + ".canvas.release.html",
                           code_base + ".canvas.js",

                           code_base + ".debug.html",

                           code_base + ".release.html",
                           code_base + ".tzjs" ]

            # print "  CODE:FILES: %s" % code_dests

            for dest in code_dests:
                do_build_code(dest, env, options)

        print "DONE"
        exit(0)

        # files = []
        # for s in shaders:
        #     files.append('%s.cgfx' % s)

        # result = build(files, env, options)
        # if result == 0:
        #     print 'Built Assets'
        # else:
        #     print 'Failed to build assets'
        #     return result

    # if yaml2json('mapping_table', 'mapping_table', True, env, options) == 0:
    #     print 'Built Mapping Table'
    # else:
    #     print 'Failed Mapping Table'

    if len(args) > 0:
        files = args
    else:
        files = []
        for t in templates:
            if options.development:
                if env['SDK_VERSION'] < StrictVersion('0.19.0'):
                    files.append('%s.jsinc' % t)
                    files.append('%s.development.html' % t)
                else:
                    files.append('%s.debug.html' % t)
                    files.append('%s.canvas.debug.html' % t)
            else:
                if env['SDK_VERSION'] < StrictVersion('0.19.0'):
                    files.append('%s.jsinc' % t)
                    files.append('%s.development.html' % t)
                    files.append('%s.release.html' % t)
                    files.append('%s.tzjs' % t)
                else:
                    # Order is important
                    files.append('%s.debug.html' % t)
                    files.append('%s.default.debug.html' % t)

                    files.append('%s.canvas.debug.html' % t)
                    files.append('%s.canvas.default.debug.html' % t)

                    files.append('%s.tzjs' % t)
                    files.append('%s.release.html' % t)

                    files.append('%s.canvas.js' % t)
                    files.append('%s.canvas.release.html' % t)

    result = build(files, env, options)
    if result == 0:
        print 'Built Templates'
    else:
        print 'Failed Templates'

    return result