|
@ -1,8 +1,9 @@ |
|
|
from collections import defaultdict |
|
|
from collections import defaultdict |
|
|
from difflib import SequenceMatcher |
|
|
from difflib import SequenceMatcher |
|
|
from inspect import getsourcelines |
|
|
from inspect import getsourcelines |
|
|
|
|
|
from collections import OrderedDict |
|
|
|
|
|
|
|
|
from migration_base import * |
|
|
from migration_base import appconfs, legacy_app |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_field_line(line): |
|
|
def is_field_line(line): |
|
@ -28,25 +29,34 @@ def print_commented_source(model): |
|
|
return new_to_old |
|
|
return new_to_old |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_similarity(): |
|
|
field_mappings = OrderedDict() |
|
|
|
|
|
|
|
|
def similar(a, b): |
|
|
|
|
|
return SequenceMatcher(None, a, b).ratio() |
|
|
|
|
|
|
|
|
|
|
|
different_pairs = defaultdict(list) |
|
|
|
|
|
for app in appconfs: |
|
|
for app in appconfs: |
|
|
for model in app.models.values(): |
|
|
for model in app.models.values(): |
|
|
|
|
|
new_to_old = OrderedDict() |
|
|
lines = getsourcelines(model)[0] |
|
|
lines = getsourcelines(model)[0] |
|
|
for line in lines: |
|
|
for line in lines: |
|
|
if is_field_line(line): |
|
|
if is_field_line(line): |
|
|
new = get_field(line) |
|
|
new = get_field(line) |
|
|
old = line.split('#')[-1].strip() |
|
|
old = line.split('#')[-1].strip() |
|
|
if similar(new, old) < .7: |
|
|
new_to_old[new] = old |
|
|
different_pairs['%s (%s)' % (model.__name__, app.name)].append((new, old)) |
|
|
field_mappings[model] = new_to_old |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_similarity(): |
|
|
|
|
|
|
|
|
|
|
|
def similar(a, b): |
|
|
|
|
|
return SequenceMatcher(None, a, b).ratio() |
|
|
|
|
|
|
|
|
|
|
|
different_pairs = defaultdict(list) |
|
|
|
|
|
for model, new_to_old in field_mappings.items(): |
|
|
|
|
|
for new, old in new_to_old.items(): |
|
|
|
|
|
if similar(new, old) < 0.7: |
|
|
|
|
|
different_pairs[model].append((new, old)) |
|
|
|
|
|
|
|
|
if different_pairs: |
|
|
if different_pairs: |
|
|
print '\n\n######## Different Pairs #########' |
|
|
print '\n\n######## Different Pairs #########' |
|
|
for name, pairs in different_pairs.items(): |
|
|
for model, pairs in different_pairs.items(): |
|
|
print name |
|
|
print '%s (%s)' % (model.__name__, app.name) |
|
|
for a, b in pairs: |
|
|
for a, b in pairs: |
|
|
print ' ', a, b |
|
|
print ' ', a, b |
|
|
|
|
|
return different_pairs |