From 3f63e3c802f6a6de1bcc9b9da2381eb17226bc5f Mon Sep 17 00:00:00 2001 From: Epithumia Date: Thu, 19 Dec 2013 00:36:43 +0100 Subject: [PATCH] Aggressive table renaming, in case dropping the vowels still doesn't bring the length under 30 --- pokedex/db/__init__.py | 9 +++++++++ pokedex/db/load.py | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/pokedex/db/__init__.py b/pokedex/db/__init__.py index 0bb1705..558a26c 100644 --- a/pokedex/db/__init__.py +++ b/pokedex/db/__init__.py @@ -3,6 +3,8 @@ import re from sqlalchemy import engine_from_config, orm +from hashlib import md5 + from ..defaults import get_default_db_uri from .tables import Language, metadata from .multilang import MultilangSession, MultilangScopedSession @@ -53,6 +55,13 @@ def connect(uri=None, session_args={}, engine_args={}, engine_prefix=''): if len(table.name) > 30: for letter in ['a', 'e', 'i', 'o', 'u', 'y']: 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 engine_args[engine_prefix + 'url'] = uri diff --git a/pokedex/db/load.py b/pokedex/db/load.py index bc52578..251f19e 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -7,6 +7,8 @@ import sys import sqlalchemy.sql.util import sqlalchemy.types +from hashlib import md5 + import pokedex from pokedex.db import metadata, tables, translations 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']: table.name=table.name.replace(letter,'') 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: table_objs.extend(find_dependent_tables(table_objs))