From 48d4ff5e971d3094bf36d1a172af9ca114ee1747 Mon Sep 17 00:00:00 2001 From: Epithumia Date: Sun, 22 Dec 2013 19:21:01 +0100 Subject: [PATCH] Add more comments. --- pokedex/db/load.py | 2 +- pokedex/db/oracle.py | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pokedex/db/load.py b/pokedex/db/load.py index 9df2b64..ec5d6d9 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -383,7 +383,7 @@ def dump(session, tables=[], directory=None, verbose=False, langs=['en']): table_names = _get_table_names(metadata, tables) table_names.sort() - # Handle Oracle + # Oracle fixery : read from short table names, dump long names oranames = (session.connection().dialect.name == 'oracle') if oranames: # Make a dictionary to match old<->new names diff --git a/pokedex/db/oracle.py b/pokedex/db/oracle.py index 67d445b..81b2105 100644 --- a/pokedex/db/oracle.py +++ b/pokedex/db/oracle.py @@ -3,28 +3,39 @@ from pokedex.db import metadata ### Helper functions for oracle def rewrite_long_table_names(): """Modifies the table names to disenvowel long table names. + Takes the metadata from memory or uses the imported one. + + Returns a dictionary matching short names -> long names. """ + + # Load table names from metadata t_names = metadata.tables.keys() table_names = list(t_names) table_objs = [metadata.tables[name] for name in table_names] # Prepare a dictionary to match old<->new names - oradict = {} + dictionary = {} # Shorten table names, Oracle limits table and column names to 30 chars for table in table_objs: table._orginal_name = table.name[:] - oradict[table.name]=table._orginal_name + dictionary[table.name]=table._orginal_name if len(table._orginal_name) > 30: for letter in ['a', 'e', 'i', 'o', 'u', 'y']: table.name=table.name.replace(letter,'') - oradict[table.name]=table._orginal_name - return oradict + dictionary[table.name]=table._orginal_name + return dictionary -def restore_long_table_names(metadata,oradict): +def restore_long_table_names(metadata,dictionary): """Modifies the table names to restore the long-naming. + + `metadata` + The metadata to restore. + + `dictionary` + The dictionary matching short name -> long name. """ for table in metadata.tables.values(): - table.name = oradict[table.name] + table.name = dictionary[table.name]