mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Fix pokedex dump -l argument error - PR Changes
### pokedex/main.py - #### create_parser() - - Change the default in the the help text for the `-l` argument in the `pokedex dump` parser. #### command_dump() - - Change the functionality of `pokedex dump -l none` to be the same as entering `pokedex dump`. --- ### pokedex/db/load.py - #### dump() - - Change the functionality of the dump command to work the way that the help text says it should. - Tables always dump official languages. - If there were any `langs` passed, then the official languages plus the specified `langs` will be dumped from the tables that have a 'local_language_id' column. - If `pokedex dump -l all` is passed then all the languages (official and unofficial) will be dumped. - If the table doesn't have a 'local_language_id' column, then all the rows will be dumped.
This commit is contained in:
parent
8ad6443a6c
commit
cc3d5d7aaf
2 changed files with 25 additions and 16 deletions
|
@ -425,26 +425,34 @@ def dump(session, tables=[], directory=None, verbose=False, langs=None):
|
|||
writer = csv.writer(open(filename, 'wb'), lineterminator='\n')
|
||||
columns = [col.name.encode('utf8') for col in table.columns]
|
||||
|
||||
# For name tables, always dump rows for official languages, as well as
|
||||
# for those in `langs` if specified.
|
||||
# For other translation tables, only dump rows for languages in `langs`
|
||||
# if specified, or for official languages by default.
|
||||
# For non-translation tables, dump all rows.
|
||||
# Tables always dump official languages.
|
||||
# If there were any `langs` passed, then the official languages plus
|
||||
# the specified `langs` will be dumped from the tables that have a
|
||||
# 'local_language_id' column.
|
||||
# If the table doesn't have a 'local_language_id' column, then
|
||||
# all the rows will be dumped.
|
||||
if 'local_language_id' in columns:
|
||||
# If 'pokedex dump' OR 'pokedex dump -l none' were passed
|
||||
# Only columns with official languages will be dumped.
|
||||
if langs is None:
|
||||
def include_row(row):
|
||||
return languages[row.local_language_id].official
|
||||
# If the none code is passed, then all the csv files with the local_language_id
|
||||
# column are not updated. In other words they are left blank.
|
||||
elif langs == ['none']:
|
||||
return False
|
||||
elif any(col.info.get('official') for col in table.columns):
|
||||
|
||||
# If 'pokedex dump -l all' was passed. All the columns will be
|
||||
# dumped, no matter if the language is official or not.
|
||||
elif langs == ['all']:
|
||||
def include_row(row):
|
||||
return True
|
||||
|
||||
# If there is a/multiple language codes passed, then all the columns that are
|
||||
# those languages OR are official languages will be dumped.
|
||||
else:
|
||||
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
|
||||
|
||||
# If there is no 'local_language_id' column in the table then all the rows
|
||||
# are dumped.
|
||||
else:
|
||||
def include_row(row):
|
||||
return True
|
||||
|
|
|
@ -114,7 +114,7 @@ def create_parser():
|
|||
help="directory to place the dumped CSV files")
|
||||
cmd_dump.add_argument(
|
||||
'-l', '--langs', dest='langs', default=None,
|
||||
help=u"comma-separated list of language codes to load, 'none', or 'all' (default: all)")
|
||||
help=u"comma-separated list of language codes to load, 'none', or 'all' (default: none)")
|
||||
cmd_dump.add_argument(
|
||||
'tables', nargs='*',
|
||||
help="list of database tables to load (default: all)")
|
||||
|
@ -210,8 +210,9 @@ def command_dump(parser, args):
|
|||
if args.langs is not None:
|
||||
langs = [l.strip() for l in args.langs.split(',')]
|
||||
|
||||
# If the langs code is only 'all' then langs is None so that all the tables get dumped.
|
||||
if len(langs) == 1 and langs[0] == 'all':
|
||||
# If the `langs` code is 'none' then langs is None so only the official languages
|
||||
# from the tables will be dumped. This is the same as if no `langs` were passed.
|
||||
if len(langs) == 1 and langs[0] == 'none':
|
||||
langs = None
|
||||
|
||||
# Check if either 'all' or 'none' codes are used along side other codes.
|
||||
|
|
Loading…
Reference in a new issue