Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pokedex dump -l argument error (#295) #299

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
30 changes: 21 additions & 9 deletions pokedex/db/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,22 +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
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
Expand Down
16 changes: 15 additions & 1 deletion pokedex/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', or 'all' (default: none)")
cmd_dump.add_argument(
'tables', nargs='*',
help="list of database tables to load (default: all)")
Expand Down Expand Up @@ -209,6 +209,20 @@ def command_dump(parser, args):

if args.langs is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this:

if args.langs == 'none':
    langs = []
elif args.langs is None or args.langs == 'all':
    langs = None
else:
    langs = [l.strip() for l in args.langs.split(',')]
    # etc...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do something like this then in load.py I would have to change

elif langs == ['none']:
    return False

to

elif len(langs) == 0:
    return False

So I would think that its pretty much the same thing

langs = [l.strip() for l in args.langs.split(',')]

# 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.
# 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:
print("\nERROR: The 'none' code should be used by itself.")
return
else:
langs = None

Expand Down