Aggressive table renaming, in case dropping the vowels still doesn't bring the length under 30

This commit is contained in:
Epithumia 2013-12-19 00:36:43 +01:00
parent 0d9d44ca03
commit 3f63e3c802
2 changed files with 20 additions and 0 deletions

View file

@ -3,6 +3,8 @@ import re
from sqlalchemy import engine_from_config, orm from sqlalchemy import engine_from_config, orm
from hashlib import md5
from ..defaults import get_default_db_uri from ..defaults import get_default_db_uri
from .tables import Language, metadata from .tables import Language, metadata
from .multilang import MultilangSession, MultilangScopedSession from .multilang import MultilangSession, MultilangScopedSession
@ -53,6 +55,13 @@ def connect(uri=None, session_args={}, engine_args={}, engine_prefix=''):
if len(table.name) > 30: if len(table.name) > 30:
for letter in ['a', 'e', 'i', 'o', 'u', 'y']: for letter in ['a', 'e', 'i', 'o', 'u', 'y']:
table.name=table.name.replace(letter,'') table.name=table.name.replace(letter,'')
# Aggressive renaming if the length is still too long:
# Take the initials of the table, add a hash to make a new name
if len(table.name) > 30:
hashedname = md5(table._orginal_name).hexdigest()
shortname = ''.join(word[:1] for word in table.name.split('_'))
shortname = ''.join([shortname, hashedname])
table.name = shortname[:30]
### Connect ### Connect
engine_args[engine_prefix + 'url'] = uri engine_args[engine_prefix + 'url'] = uri

View file

@ -7,6 +7,8 @@ import sys
import sqlalchemy.sql.util import sqlalchemy.sql.util
import sqlalchemy.types import sqlalchemy.types
from hashlib import md5
import pokedex import pokedex
from pokedex.db import metadata, tables, translations from pokedex.db import metadata, tables, translations
from pokedex.defaults import get_default_csv_dir from pokedex.defaults import get_default_csv_dir
@ -153,6 +155,15 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
for letter in ['a', 'e', 'i', 'o', 'u', 'y']: for letter in ['a', 'e', 'i', 'o', 'u', 'y']:
table.name=table.name.replace(letter,'') table.name=table.name.replace(letter,'')
oradict[table.name]=table._orginal_name oradict[table.name]=table._orginal_name
# Aggressive renaming if the length is still too long:
# Take the initials of the table, add a hash to make a new name
if len(table.name) > 30:
hashedname = md5(table._orginal_name).hexdigest()
shortname = ''.join(word[:1] for word in table.name.split('_'))
shortname = ''.join([shortname, hashedname])
table.name = shortname[:30]
oradict[table.name]=table._orginal_name
if recursive: if recursive:
table_objs.extend(find_dependent_tables(table_objs)) table_objs.extend(find_dependent_tables(table_objs))