def generate_schema(table, export_fields, output_format, output_fobj):
if output_format in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>from rows import plugins<EOL>data = [<EOL>{<EOL>"<STR_LIT>": fieldname,<EOL>"<STR_LIT>": fieldtype.__name__.replace("<STR_LIT>", "<STR_LIT>").lower(),<EOL>}<EOL>for fieldname, fieldtype in table.fields.items()<EOL>if fieldname in export_fields<EOL>]<EOL>table = plugins.dicts.import_from_dicts(<EOL>data, import_fields=["<STR_LIT>", "<STR_LIT>"]<EOL>)<EOL>if output_format == "<STR_LIT>":<EOL><INDENT>plugins.txt.export_to_txt(table, output_fobj)<EOL><DEDENT>elif output_format == "<STR_LIT>":<EOL><INDENT>plugins.csv.export_to_csv(table, output_fobj)<EOL><DEDENT><DEDENT>elif output_format == "<STR_LIT>":<EOL><INDENT>sql_fields = {<EOL>rows.fields.BinaryField: "<STR_LIT>",<EOL>rows.fields.BoolField: "<STR_LIT>",<EOL>rows.fields.IntegerField: "<STR_LIT>",<EOL>rows.fields.FloatField: "<STR_LIT>",<EOL>rows.fields.PercentField: "<STR_LIT>",<EOL>rows.fields.DateField: "<STR_LIT>",<EOL>rows.fields.DatetimeField: "<STR_LIT>",<EOL>rows.fields.TextField: "<STR_LIT>",<EOL>rows.fields.DecimalField: "<STR_LIT>",<EOL>rows.fields.EmailField: "<STR_LIT>",<EOL>rows.fields.JSONField: "<STR_LIT>",<EOL>}<EOL>fields = [<EOL>"<STR_LIT>".format(field_name, sql_fields[field_type])<EOL>for field_name, field_type in table.fields.items()<EOL>if field_name in export_fields<EOL>]<EOL>sql = (<EOL>dedent(<EOL>"""<STR_LIT>"""<EOL>)<EOL>.strip()<EOL>.format(name=table.name, fields="<STR_LIT>".join(fields))<EOL>+ "<STR_LIT:\n>"<EOL>)<EOL>output_fobj.write(sql)<EOL><DEDENT>elif output_format == "<STR_LIT>":<EOL><INDENT>django_fields = {<EOL>rows.fields.BinaryField: "<STR_LIT>",<EOL>rows.fields.BoolField: "<STR_LIT>",<EOL>rows.fields.IntegerField: "<STR_LIT>",<EOL>rows.fields.FloatField: "<STR_LIT>",<EOL>rows.fields.PercentField: "<STR_LIT>",<EOL>rows.fields.DateField: "<STR_LIT>",<EOL>rows.fields.DatetimeField: "<STR_LIT>",<EOL>rows.fields.TextField: "<STR_LIT>",<EOL>rows.fields.DecimalField: "<STR_LIT>",<EOL>rows.fields.EmailField: "<STR_LIT>",<EOL>rows.fields.JSONField: "<STR_LIT>",<EOL>}<EOL>table_name = "<STR_LIT>".join(word.capitalize() for word in table.name.split("<STR_LIT:_>"))<EOL>lines = ["<STR_LIT>"]<EOL>if rows.fields.JSONField in [<EOL>table.fields[field_name] for field_name in export_fields<EOL>]:<EOL><INDENT>lines.append("<STR_LIT>")<EOL><DEDENT>lines.append("<STR_LIT>")<EOL>lines.append("<STR_LIT>".format(table_name))<EOL>for field_name, field_type in table.fields.items():<EOL><INDENT>if field_name not in export_fields:<EOL><INDENT>continue<EOL><DEDENT>if field_type is not rows.fields.JSONField:<EOL><INDENT>django_type = "<STR_LIT>".format(django_fields[field_type])<EOL><DEDENT>else:<EOL><INDENT>django_type = "<STR_LIT>"<EOL><DEDENT>lines.append("<STR_LIT>".format(field_name, django_type))<EOL><DEDENT>result = "<STR_LIT:\n>".join(lines) + "<STR_LIT:\n>"<EOL>output_fobj.write(result)<EOL><DEDENT>
Generate table schema for a specific output format and write

    Current supported output formats: 'txt', 'sql' and 'django'.
    The table name and all fields names pass for a slugifying process (table
    name is taken from file name).