From 17f36243bc5af4ed7baeaef268ec8daa46737437 Mon Sep 17 00:00:00 2001 From: rluzuriaga Date: Tue, 31 Mar 2020 20:02:06 -0700 Subject: [PATCH 1/3] Fix pokedex dump -l argument error (#295) pokedex/main.py - create_parser() - Change the help message for the langs argument in the dump subparser to show the actual default and state that the 'all' and 'none' codes cannot be used alongside other codes. command_dump() - Check if 'all' or 'none' codes are passed alongside other codes. If they are, error message is printed and program ends. pokedex/db/load.py - dump() - Add check if langs code is 'all' or 'none'. If langs wasn't passed to the parser or 'all' was passed (they are the same since the default is 'all'), then everything will get dumped to the csv files. If 'none' was passed to the parser, then nothing new should be dumped to the csv files. pokexed/.travis.yml - Re-added 'pokedex dump -l all' that was previously remove on 77e3d9df163ac602d5c939cee75750f8be0dc725 Resolves: #295 --- .travis.yml | 2 +- pokedex/db/load.py | 6 +++++- pokedex/main.py | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d2079058a..01cdd810e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,5 +13,5 @@ install: pip install -e . before_script: pokedex setup -v script: - py.test - - pokedex dump + - pokedex dump -l all - git --no-pager diff --exit-code pokedex/data/csv/ diff --git a/pokedex/db/load.py b/pokedex/db/load.py index f34ee4647..023f7a834 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -431,9 +431,13 @@ 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 langs is None: + # If no lang arguments were passed or the 'all' argument was passed + if langs is None or langs == ['all']: 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 + elif langs == ['none']: + return False elif any(col.info.get('official') for col in table.columns): def include_row(row): return (languages[row.local_language_id].official or diff --git a/pokedex/main.py b/pokedex/main.py index 6044d9e87..51d16a19a 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="comma-separated list of language codes to load, 'none', or 'all' (default: en)") + 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.") cmd_dump.add_argument( 'tables', nargs='*', help="list of database tables to load (default: all)") @@ -209,6 +209,15 @@ def command_dump(parser, args): if args.langs is not None: langs = [l.strip() for l in args.langs.split(',')] + + # 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: + print("\nERROR: The 'all' code should be used by itself.") + return + elif len(langs) > 1 and 'none' in langs: + print("\nERROR: The 'none' code should be used by itself.") + return else: langs = None From 8ad6443a6c0913e5d7e3113ec367231490c52847 Mon Sep 17 00:00:00 2001 From: rluzuriaga Date: Thu, 2 Apr 2020 18:25:52 -0700 Subject: [PATCH 2/3] 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 023f7a834..522d69188 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 51d16a19a..af229b0f1 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: From cc3d5d7aafb5f2e8f7f2a17284e8235bd6f269ed Mon Sep 17 00:00:00 2001 From: rluzuriaga Date: Fri, 10 Apr 2020 12:05:29 -0700 Subject: [PATCH 3/3] 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. --- pokedex/db/load.py | 34 +++++++++++++++++++++------------- pokedex/main.py | 7 ++++--- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/pokedex/db/load.py b/pokedex/db/load.py index 522d69188..a15900da1 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -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 (languages[row.local_language_id].official or - languages[row.local_language_id].identifier in langs) + 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].identifier in langs + return (languages[row.local_language_id].official or + 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 diff --git a/pokedex/main.py b/pokedex/main.py index af229b0f1..52fe0395b 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', 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.