Пример #1
0
    def generate_code_signal(self, request, response,
                             tmpl, config, json_data):
        output = config.get('output', 'auto')
        fixcode = config.get('fixcode', None)
        upsert = config.get('upsert', True)

        if output == 'auto':
            filepath0 = request.file_to_generate[0]
            filename1 = filepath0[:filepath0.rfind('.')]
            fpath = '{}_helper.py'.format(filename1)
        else:
            filepath0 = request.file_to_generate[0]
            filepath0 = filepath0.replace('\\', '/')
            filename1 = filepath0[:filepath0.rfind('/') + 1]
            if filepath0.rfind('/') >= 0:
                filename = filepath0[
                    filepath0.rfind('/') + 1: filepath0.rfind('.')
                ]
            else:
                filename = filepath0[:filepath0.rfind('.')]

            fpath = filename1 + \
                output.format(filename=gfuncs.camel_to_snake(filename))

        fpath2 = os.path.abspath(fpath)
        if not upsert and os.path.exists(fpath2):
            return

        fout = response.file.add()
        fout.name = fpath
        fout.content = gfuncs.generate_file(tmpl, **json_data)
        fout.content = self.auto_fmt(fout.content, fixcode)
Пример #2
0
        def gen_file(_upsert, objname, tconfig):
            fpath = filename1 + \
                output.format(objname=gfuncs.camel_to_snake(objname))

            fpath2 = os.path.abspath(fpath)
            if not _upsert and os.path.exists(fpath2):
                return

            fout = response.file.add()
            tconfig['objname'] = objname
            tconfig['json_data'] = json_data
            fout.content = gfuncs.generate_file(tmpl, **tconfig)
            fout.content = self.auto_fmt(fout.content, fixcode)
            fout.name = fpath
Пример #3
0
            def gen_file2(_upsert, dbname, table, tconfig):
                fpath = filename1 + output.format(
                    db=gfuncs.camel_to_snake(dbname),
                    table=gfuncs.camel_to_snake(table)
                )

                fpath2 = os.path.abspath(fpath)
                if not _upsert and os.path.exists(fpath2):
                    return

                fout = response.file.add()
                tconfig['db'] = dbname
                fout.content = gfuncs.generate_file(tmpl, **tconfig)
                fout.content = self.auto_fmt(fout.content, fixcode)
                fout.name = fpath
Пример #4
0
 def generate_code_by_json(cls, json_data, tmpl_path, fixcode):
     content = gfuncs.generate_file(tmpl_path, **json_data)
     content = cls.auto_fmt(content, fixcode)
     return content
Пример #5
0
 def generate_code_by_json(cls, json_data, tmpl_path, fixcode):
     _json_data = cls.init_table_json(json_data.copy())
     content = gfuncs.generate_file(tmpl_path, **json_data)
     content = cls.auto_fmt(content, fixcode)
     return content