Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# coding: utf-8
from __future__ import print_function
import csv
import sys
import datetime
from tqdm import tqdm
import importlib
import re
from decimal import Decimal
from ec.models.shop import ShopInfo
cls_list = []
with open(sys.argv[1], 'r') as f:
for row in f:
path, cls_name, _ = row.split(':', 2)
mod_path = path[:-3].replace('/', '.')
cls_name = re.search('class (\w+)\(', cls_name).group(1)
mod = importlib.import_module(mod_path)
klass = getattr(mod, cls_name)
if not hasattr(klass, 'Meta'):
# print('Meta DO NOT exists in class %s' % (cls_name), file=sys.stderr)
continue
meta = getattr(klass, 'Meta')
for (fname, ftype, _, _, _, _) in ShopInfo.raw_sql('desc %s' % (meta.table)):
if re.match('float|double|decimal', ftype):
if not hasattr(meta.default, fname):
print('field %s DO NOT exists in %s.Meta.default' % (fname, cls_name), file=sys.stderr)
continue
field = getattr(meta.default, fname)
if not (isinstance(field, float) or isinstance(field, Decimal)):
print('%s:%s.%s type: %s, type_in_class: %s' % (path, meta.table, fname, ftype, type(field)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment