|
|
@ -10,12 +10,16 @@ _base_dir = None |
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
|
|
|
# --------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
def _get_key( nat ) : |
|
|
|
def _make_key( nat ) : |
|
|
|
"""Get the JSON key for a nationality. |
|
|
|
"""Get the JSON key for a nationality. |
|
|
|
|
|
|
|
|
|
|
|
We require the JSON keys to be lower-case, with no spaces (not strictly necessary, but not a bad idea :-/). |
|
|
|
We require the JSON keys to be lower-case, with no spaces (not strictly necessary, but not a bad idea :-/). |
|
|
|
""" |
|
|
|
""" |
|
|
|
return nat.lower().replace( " " , "-" ) |
|
|
|
return nat.lower().replace( " " , "-" ) if nat else None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def display_name_from_key( key ) : |
|
|
|
|
|
|
|
"""Get the nationality display string from a JSON key.""" |
|
|
|
|
|
|
|
return key.replace( "-" , " " ).capitalize() |
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
|
|
|
# --------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
@ -35,16 +39,32 @@ def dump() : |
|
|
|
for nat in sorted(_nat_info.keys()) : |
|
|
|
for nat in sorted(_nat_info.keys()) : |
|
|
|
print( "{}:".format( nat ) ) |
|
|
|
print( "{}:".format( nat ) ) |
|
|
|
print( "- flag = {}".format( get_flag(nat) ) ) |
|
|
|
print( "- flag = {}".format( get_flag(nat) ) ) |
|
|
|
|
|
|
|
print( "- accel = {}".format( get_accel_for_nat(nat) ) ) |
|
|
|
|
|
|
|
|
|
|
|
def get_flag( nat ) : |
|
|
|
def get_flag( nat ) : |
|
|
|
"""Locate the flag image file for a nationality. |
|
|
|
"""Locate the flag image file for a nationality. |
|
|
|
|
|
|
|
|
|
|
|
These are set in the JSON data file at $/{nat}/flag. If there is no entry, the default is $/flags/${nat}.png |
|
|
|
These are set in the JSON data file at $/{nat}/flag. If there is no entry, the default is $/flags/${nat}.png |
|
|
|
""" |
|
|
|
""" |
|
|
|
key = _get_key( nat ) |
|
|
|
key = _make_key( nat ) |
|
|
|
try : |
|
|
|
try : |
|
|
|
fname = _nat_info[ key ][ "flag" ] |
|
|
|
fname = _nat_info[ key ][ "flag" ] |
|
|
|
except ( KeyError , TypeError ) : |
|
|
|
except ( KeyError , TypeError ) : |
|
|
|
fname = key + ".png" |
|
|
|
fname = "{}.png".format( key ) |
|
|
|
fname = os.path.join( _base_dir , os.path.join("flags", fname) ) |
|
|
|
fname = os.path.join( _base_dir , os.path.join("flags", fname) ) |
|
|
|
return fname if os.path.isfile(fname) else None |
|
|
|
return fname if os.path.isfile(fname) else None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_nats_for_accel( ch ) : |
|
|
|
|
|
|
|
"""Get the nationalities for an accelerator key.""" |
|
|
|
|
|
|
|
if ch is None : return None |
|
|
|
|
|
|
|
ch = ch.strip().lower() |
|
|
|
|
|
|
|
if not ch : return None |
|
|
|
|
|
|
|
return [ nat for nat,vals in _nat_info.items() if vals.get("accelerator","").lower() == ch ] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_accel_for_nat( nat ) : |
|
|
|
|
|
|
|
"""Get the accelerator key for a nationality.""" |
|
|
|
|
|
|
|
key = _make_key( nat ) |
|
|
|
|
|
|
|
try : |
|
|
|
|
|
|
|
return _nat_info[ key ][ "accelerator" ].lower() |
|
|
|
|
|
|
|
except ( KeyError , TypeError ) : |
|
|
|
|
|
|
|
return None |
|
|
|