From 8ad6443a6c0913e5d7e3113ec367231490c52847 Mon Sep 17 00:00:00 2001 From: rluzuriaga Date: Thu, 2 Apr 2020 18:25:52 -0700 Subject: [PATCH] Fix pokedex dump -l argument error - PR Changes All changes requested in PR 17f36243bc5af4ed7baeaef268ec8daa46737437 ### pokedex/main.py - #### create_parser() - - Change to langs argument reverting the help message to the original one but changing the default to 'all'. #### command_dump() - - Add check for 'all' langs code instead of in the load.py file. - Add/fix comments. --- ### pokedex/db/load.py - #### dump() - - Remove unneeded check for 'all' langs code since not it is checked in the main.py file. - Reword comment of what happens when the 'none' code is passed. --- pokedex/db/load.py | 6 +++--- pokedex/main.py | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pokedex/db/load.py b/pokedex/db/load.py index 023f7a8..522d691 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -431,11 +431,11 @@ def dump(session, tables=[], directory=None, verbose=False, langs=None): # if specified, or for official languages by default. # For non-translation tables, dump all rows. if 'local_language_id' in columns: - # If no lang arguments were passed or the 'all' argument was passed - if langs is None or langs == ['all']: + if langs is None: def include_row(row): return languages[row.local_language_id].official - # If the none argument is passed then nothing should be changed from the csv files + # 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): diff --git a/pokedex/main.py b/pokedex/main.py index 51d16a1..af229b0 100644 --- a/pokedex/main.py +++ b/pokedex/main.py @@ -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', 'all', or other languages like 'en,es' (default: all). The 'all' and 'none' codes cannot be used with other codes.") + help=u"comma-separated list of language codes to load, 'none', or 'all' (default: all)") cmd_dump.add_argument( 'tables', nargs='*', help="list of database tables to load (default: all)") @@ -210,9 +210,13 @@ 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': + langs = None + # Check if either 'all' or 'none' codes are used along side other codes. - # If either code is used, an error message will be displayed and the progrm will close. - if len(langs) > 1 and 'all' in langs: + # If either code is used, an error message will be displayed and the program will close. + elif len(langs) > 1 and 'all' in langs: print("\nERROR: The 'all' code should be used by itself.") return elif len(langs) > 1 and 'none' in langs: