mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Don't dump unofficial translations in pokedex dump
(Translations cannot be dumped properly because the source string hash isn't in the database.) By default, unofficial texts are only dumped for English, but that can be configured if someone wants CSVs for different language(s). Official texts (<thing>_names rows for official languages) are always dumped.
This commit is contained in:
parent
9b7a3dc4c9
commit
817c4c289d
2 changed files with 46 additions and 18 deletions
|
@ -8,8 +8,8 @@ from sqlalchemy.orm.attributes import instrumentation_registry
|
|||
import sqlalchemy.sql.util
|
||||
import sqlalchemy.types
|
||||
|
||||
from pokedex.db import metadata
|
||||
import pokedex.db.tables as tables
|
||||
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
|
||||
|
||||
|
@ -306,7 +306,7 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
|
|||
|
||||
|
||||
|
||||
def dump(session, tables=[], directory=None, verbose=False):
|
||||
def dump(session, tables=[], directory=None, verbose=False, langs=['en']):
|
||||
"""Dumps the contents of a database to a set of CSV files. Probably not
|
||||
useful to anyone besides a developer.
|
||||
|
||||
|
@ -322,11 +322,15 @@ def dump(session, tables=[], directory=None, verbose=False):
|
|||
|
||||
`verbose`
|
||||
If set to True, status messages will be printed to stdout.
|
||||
|
||||
`langs`
|
||||
List of identifiers of languages to dump unofficial texts for
|
||||
"""
|
||||
|
||||
# First take care of verbosity
|
||||
print_start, print_status, print_done = _get_verbose_prints(verbose)
|
||||
|
||||
languages = dict((l.id, l) for l in session.query(pokedex.db.tables.Language))
|
||||
|
||||
if not directory:
|
||||
directory = get_default_csv_dir()
|
||||
|
@ -342,10 +346,28 @@ def dump(session, tables=[], directory=None, verbose=False):
|
|||
writer = csv.writer(open("%s/%s.csv" % (directory, table_name), 'wb'),
|
||||
lineterminator='\n')
|
||||
columns = [col.name for col in table.columns]
|
||||
|
||||
# For name tables, dump rows for official languages, as well as
|
||||
# for those in `langs`.
|
||||
# For other translation tables, only dump rows for languages in `langs`
|
||||
# For non-translation tables, dump all rows.
|
||||
if 'local_language_id' in columns:
|
||||
if any(col.info.get('official') for col in table.columns):
|
||||
def include_row(row):
|
||||
return (languages[row.local_language_id].official or
|
||||
languages[row.local_language_id].identifier in langs)
|
||||
else:
|
||||
def include_row(row):
|
||||
return languages[row.local_language_id].identifier in langs
|
||||
else:
|
||||
def include_row(row):
|
||||
return True
|
||||
|
||||
writer.writerow(columns)
|
||||
|
||||
primary_key = table.primary_key
|
||||
for row in session.query(table).order_by(*primary_key).all():
|
||||
if include_row(row):
|
||||
csvs = []
|
||||
for col in columns:
|
||||
# Convert Pythony values to something more universal
|
||||
|
|
|
@ -108,14 +108,20 @@ def get_csv_directory(options):
|
|||
def command_dump(*args):
|
||||
parser = get_parser(verbose=True)
|
||||
parser.add_option('-d', '--directory', dest='directory', default=None)
|
||||
parser.add_option('-l', '--langs', dest='langs', default='en',
|
||||
help="Comma-separated list of languages to dump all strings for. "
|
||||
"Default is English ('en')")
|
||||
options, tables = parser.parse_args(list(args))
|
||||
|
||||
session = get_session(options)
|
||||
get_csv_directory(options)
|
||||
|
||||
langs = [l.strip() for l in options.langs.split(',')]
|
||||
|
||||
pokedex.db.load.dump(session, directory=options.directory,
|
||||
tables=tables,
|
||||
verbose=options.verbose)
|
||||
verbose=options.verbose,
|
||||
langs=langs)
|
||||
|
||||
def command_load(*args):
|
||||
parser = get_parser(verbose=True)
|
||||
|
|
Loading…
Reference in a new issue