mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Grouped all the hackery manipulations of the names in oracle.py, easily reversible too. Fixed dump to read from short named columns but dump in long named files. Load/dump now uses oracle.py to handle the name stuff.
This commit is contained in:
parent
6c0074b1a5
commit
00013f5ac0
1 changed files with 12 additions and 10 deletions
|
@ -11,6 +11,7 @@ import pokedex
|
|||
from pokedex.db import metadata, tables, translations
|
||||
from pokedex.defaults import get_default_csv_dir
|
||||
from pokedex.db.dependencies import find_dependent_tables
|
||||
from pokedex.db.oracle import rewrite_long_table_names
|
||||
|
||||
|
||||
def _get_table_names(metadata, patterns):
|
||||
|
@ -142,17 +143,9 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
|
|||
# flag for oracle stuff
|
||||
oranames = (session.connection().dialect.name == 'oracle')
|
||||
if oranames:
|
||||
# Prepare a dictionary to match old<->new names
|
||||
oradict = {}
|
||||
|
||||
# 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
|
||||
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
|
||||
# Make a dictionary to match old<->new names
|
||||
oradict = rewrite_long_table_names()
|
||||
|
||||
if recursive:
|
||||
table_objs.extend(find_dependent_tables(table_objs))
|
||||
|
@ -390,6 +383,11 @@ def dump(session, tables=[], directory=None, verbose=False, langs=['en']):
|
|||
table_names = _get_table_names(metadata, tables)
|
||||
table_names.sort()
|
||||
|
||||
# Handle Oracle
|
||||
oranames = (session.connection().dialect.name == 'oracle')
|
||||
if oranames:
|
||||
# Make a dictionary to match old<->new names
|
||||
oradict = rewrite_long_table_names()
|
||||
|
||||
for table_name in table_names:
|
||||
print_start(table_name)
|
||||
|
@ -397,6 +395,10 @@ def dump(session, tables=[], directory=None, verbose=False, langs=['en']):
|
|||
|
||||
writer = csv.writer(open("%s/%s.csv" % (directory, table_name), 'wb'),
|
||||
lineterminator='\n')
|
||||
# In oracle mode, use the original names instead of current
|
||||
if oranames:
|
||||
writer = csv.writer(open("%s/%s.csv" % (directory, oradict[table_name]), 'wb'),
|
||||
lineterminator='\n')
|
||||
columns = [col.name for col in table.columns]
|
||||
|
||||
# For name tables, dump rows for official languages, as well as
|
||||
|
|
Loading…
Reference in a new issue