예제 #1
0
    def run(self, descriptors, params):
        content = '// This file is auto-generated by taxi v%s, DO NOT EDIT!\n\n' % version.VER_STRING
        content += 'using System;\n'
        content += 'using System.IO;\n'
        content += 'using System.Collections.Generic;\n'

        if 'pkg' in params:
            content += '\nnamespace %s\n{\n' % params['pkg']

        for struct in descriptors:
            genutil.setup_comment(struct)
            genutil.setup_key_value_mode(struct)

        for struct in descriptors:
            content += self.generate_class(struct)

        content += self.gen_global_class(descriptors)

        if 'pkg' in params:
            content += '\n}\n'  # namespace

        filename = params.get(predef.OptionOutSourceFile, 'AutogenConfig.cs')
        filename = os.path.abspath(filename)
        strutil.compare_and_save_content(filename, content, 'utf-8')
        print('wrote source file to', filename)
예제 #2
0
    def run(self, descriptors, params):
        content = '// This file is auto-generated by taxi v%s, DO NOT EDIT!\n\n' % version.VER_STRING
        content += 'package %s\n' % params['pkg']
        content += 'import (\n'
        content += '    "encoding/csv"\n'
        content += '    "io"\n'
        content += '    "strings"\n'
        content += ')\n'
        content += '\nvar (\n'
        content += '\t_ = io.EOF\n'
        content += '\t_ = strings.Compare\n'
        content += ')\n\n'
        content += self.gen_const_names(descriptors)

        for struct in descriptors:
            genutil.setup_comment(struct)
            genutil.setup_key_value_mode(struct)

        for struct in descriptors:
            content += self.generate(struct, params)

        filename = params.get(predef.OptionOutSourceFile, 'config.go')
        filename = os.path.abspath(filename)
        strutil.compare_and_save_content(filename, content, 'utf-8')
        print('wrote source to %s' % filename)

        goroot = os.getenv('GOROOT')
        if goroot is not None:
            cmd = goroot + '/bin/go fmt ' + filename
            print(cmd)
            os.system(cmd)
예제 #3
0
    def run(self, descriptors, params):
        mgr_content = '// This file is auto-generated by taxi v%s, DO NOT EDIT!\n\n' % version.VER_STRING
        mgr_filename = '%s.java' % strutil.config_manager_name

        basedir = params.get(predef.OptionOutSourceFile, '.')
        print(basedir)
        if 'pkg' in params:
            package = params['pkg']
            names = [basedir] + package.split('.')
            basedir = '/'.join(names)
            mgr_content += 'package %s;' % package
            mgr_filename = '%s/%s' % (basedir, mgr_filename)
            try:
                print('make dir', basedir)
                os.makedirs(basedir)
            except Exception as e:
                # print(e)
                pass

        class_dict = {}
        mgr_content += JAVA_CLASS_TEMPLATE % strutil.config_manager_name
        load_func_content = '    public static void loadAllConfig() {\n'

        for struct in descriptors:
            genutil.setup_comment(struct)
            genutil.setup_key_value_mode(struct)

        for struct in descriptors:
            content = '// This file is auto-generated by TAKSi v%s, DO NOT EDIT!\n\n' % version.VER_STRING
            filename = '%s.java' % struct['camel_case_name']
            # print(filename)
            if 'pkg' in params:
                filename = '%s/%s' % (basedir, filename)
                content += 'package %s;\n\n' % params['pkg']
            content += 'import java.util.*;\n'
            content += '\n'
            content += self.generate_class(struct, params)
            class_dict[filename] = content

            name = strutil.camel_to_snake(struct['name'])
            load_func_content += '        %s.loadFromFile("%s.csv");\n' % (
                struct['name'], name)

        load_func_content += '    }\n'
        mgr_content += load_func_content
        mgr_content += '}\n'
        class_dict[mgr_filename] = mgr_content

        for filename in class_dict:
            content = class_dict[filename]
            filename = os.path.abspath(filename)
            strutil.compare_and_save_content(filename, content, 'utf-8')
            print('wrote source file to', filename)
예제 #4
0
    def run(self, descriptors, params):
        headerfile = params.get(predef.OptionOutSourceFile, 'AutogenConfig') + '.h'
        sourcefile = params.get(predef.OptionOutSourceFile, 'AutogenConfig') + '.cpp'

        for struct in descriptors:
            genutil.setup_comment(struct)
            genutil.setup_key_value_mode(struct)

        header_content = self.gen_header_content(descriptors, params, self.gen_struct_method_declare)
        cpp_content = self.gen_source_content(descriptors, params, headerfile)

        encoding = params.get(predef.OptionSourceEncoding, 'utf-8')
        filename = os.path.abspath(headerfile)
        strutil.compare_and_save_content(filename, header_content, encoding)
        print('wrote header file to', filename)

        filename = os.path.abspath(sourcefile)
        strutil.compare_and_save_content(filename, cpp_content, encoding)
        print('wrote source file to', filename)
예제 #5
0
    def run(self, descriptors, params):
        basedir = params.get(predef.OptionOutSourceFile, '.')
        print(basedir)
        if 'pkg' in params:
            package = params['pkg']
            names = [basedir] + package.split('.')
            basedir = '/'.join(names)
            try:
                print('make dir', basedir)
                os.makedirs(basedir)
            except Exception as e:
                # print(e)
                pass

        for struct in descriptors:
            genutil.setup_comment(struct)
            genutil.setup_key_value_mode(struct)

        class_dict = {}

        for struct in descriptors:
            content = '// This file is auto-generated by taxi v%s, DO NOT EDIT!\n\n' % version.VER_STRING
            filename = '%s.java' % struct['camel_case_name']
            # print(filename)
            if 'pkg' in params:
                filename = '%s/%s' % (basedir, filename)
                content += 'package %s;\n\n' % params['pkg']
            content += 'import java.util.*;\n'
            content += '\n'
            content += self.gen_java_class(struct)
            content += '}\n\n'
            class_dict[filename] = content

        for filename in class_dict:
            content = class_dict[filename]
            filename = os.path.abspath(filename)
            strutil.compare_and_save_content(filename, content, 'utf-8')
            print('wrote source file to', filename)