mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Load translations in pokedex load.
This commit is contained in:
parent
817c4c289d
commit
34a8070449
2 changed files with 33 additions and 2 deletions
|
@ -96,7 +96,7 @@ def _get_verbose_prints(verbose):
|
||||||
return print_start, print_status, print_done
|
return print_start, print_status, print_done
|
||||||
|
|
||||||
|
|
||||||
def load(session, tables=[], directory=None, drop_tables=False, verbose=False, safe=True, recursive=False):
|
def load(session, tables=[], directory=None, drop_tables=False, verbose=False, safe=True, recursive=True, langs=None):
|
||||||
"""Load data from CSV files into the given database session.
|
"""Load data from CSV files into the given database session.
|
||||||
|
|
||||||
Tables are created automatically.
|
Tables are created automatically.
|
||||||
|
@ -123,6 +123,9 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
|
||||||
|
|
||||||
`recursive`
|
`recursive`
|
||||||
If set to True, load all dependent tables too.
|
If set to True, load all dependent tables too.
|
||||||
|
|
||||||
|
`langs`
|
||||||
|
List of identifiers of extra language to load, or None to load them all
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# First take care of verbosity
|
# First take care of verbosity
|
||||||
|
@ -300,6 +303,23 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
|
||||||
|
|
||||||
print_done()
|
print_done()
|
||||||
|
|
||||||
|
|
||||||
|
print_start('Translations')
|
||||||
|
transl = translations.Translations(csv_directory=directory)
|
||||||
|
|
||||||
|
new_row_count = 0
|
||||||
|
for translation_class, rows in transl.get_load_data(langs):
|
||||||
|
table_obj = translation_class.__table__
|
||||||
|
if table_obj in table_objs:
|
||||||
|
insert_stmt = table_obj.insert()
|
||||||
|
session.connection().execute(insert_stmt, rows)
|
||||||
|
session.commit()
|
||||||
|
# We don't have a total, but at least show some increasing number
|
||||||
|
new_row_count += len(rows)
|
||||||
|
print_status(str(new_row_count))
|
||||||
|
|
||||||
|
print_done()
|
||||||
|
|
||||||
# SQLite check
|
# SQLite check
|
||||||
if session.connection().dialect.name == 'sqlite':
|
if session.connection().dialect.name == 'sqlite':
|
||||||
session.connection().execute("PRAGMA integrity_check")
|
session.connection().execute("PRAGMA integrity_check")
|
||||||
|
|
|
@ -130,6 +130,9 @@ def command_load(*args):
|
||||||
parser.add_option('-r', '--recursive', dest='recursive', default=False, action='store_true')
|
parser.add_option('-r', '--recursive', dest='recursive', default=False, action='store_true')
|
||||||
parser.add_option('-S', '--safe', dest='safe', default=False, action='store_true',
|
parser.add_option('-S', '--safe', dest='safe', default=False, action='store_true',
|
||||||
help="Do not use backend-specific optimalizations.")
|
help="Do not use backend-specific optimalizations.")
|
||||||
|
parser.add_option('-l', '--langs', dest='langs', default=None,
|
||||||
|
help="Comma-separated list of extra languages to load, or 'none' for none. "
|
||||||
|
"Default is to load 'em all. Example: 'fr,de'")
|
||||||
options, tables = parser.parse_args(list(args))
|
options, tables = parser.parse_args(list(args))
|
||||||
|
|
||||||
if not options.engine_uri:
|
if not options.engine_uri:
|
||||||
|
@ -139,6 +142,13 @@ def command_load(*args):
|
||||||
print "`pokedex setup` to do both at once."
|
print "`pokedex setup` to do both at once."
|
||||||
print
|
print
|
||||||
|
|
||||||
|
if options.langs == 'none':
|
||||||
|
langs = []
|
||||||
|
elif options.langs is None:
|
||||||
|
langs = None
|
||||||
|
else:
|
||||||
|
langs = [l.strip() for l in options.langs.split(',')]
|
||||||
|
|
||||||
session = get_session(options)
|
session = get_session(options)
|
||||||
get_csv_directory(options)
|
get_csv_directory(options)
|
||||||
|
|
||||||
|
@ -147,7 +157,8 @@ def command_load(*args):
|
||||||
tables=tables,
|
tables=tables,
|
||||||
verbose=options.verbose,
|
verbose=options.verbose,
|
||||||
safe=options.safe,
|
safe=options.safe,
|
||||||
recursive=options.recursive)
|
recursive=options.recursive,
|
||||||
|
langs=langs)
|
||||||
|
|
||||||
def command_reindex(*args):
|
def command_reindex(*args):
|
||||||
parser = get_parser(verbose=True)
|
parser = get_parser(verbose=True)
|
||||||
|
|
Loading…
Reference in a new issue