Browse Source

Raise exceptions instead of return

pull/37/head
Dashie der otter 11 months ago
parent
commit
31db117abd
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755
6 changed files with 20 additions and 16 deletions
  1. 12
    8
      app.py
  2. 8
    8
      crons.py
  3. 0
    0
      tests/conftest.py
  4. 0
    0
      tests/test_c_contacts.py
  5. 0
    0
      tests/test_c_home.py
  6. 0
    0
      tests/test_c_users.py

+ 12
- 8
app.py View File

@@ -117,9 +117,10 @@ def create_app(config_filename="config.py", app_name=None, register_blueprints=T
@babel.localeselector
def get_locale():
# if a user is logged in, use the locale from the user settings
identity = getattr(g, "identity", None)
if identity is not None and identity.id:
return identity.user.locale
# FIXME: not implemented yet
# identity = getattr(g, "identity", None)
# if identity is not None and identity.id:
# return identity.user.locale
# otherwise try to guess the language from the user accept
# header the browser transmits. We support fr/en in this
# example. The best match wins.
@@ -127,9 +128,11 @@ def create_app(config_filename="config.py", app_name=None, register_blueprints=T

@babel.timezoneselector
def get_timezone():
identity = getattr(g, "identity", None)
if identity is not None and identity.id:
return identity.user.timezone
# identity = getattr(g, "identity", None)
# if identity is not None and identity.id:
# return identity.user.timezone
# FIXME: not implemented yet
pass

@app.before_request
def before_request():
@@ -302,10 +305,11 @@ def create_app(config_filename="config.py", app_name=None, register_blueprints=T
pass

@cron.command()
def update_dxcc_from_cty():
@click.option("--file", default=None, help="Local file to import instead of downloading", type=click.Path(exists=True))
def update_dxcc_from_cty(file):
"""Update DXCC tables from cty.xml"""
print("-- STARTED on {0}".format(datetime.datetime.now()))
update_dxcc_from_cty_xml()
update_dxcc_from_cty_xml(file)
print("-- FINISHED on {0}".format(datetime.datetime.now()))

@cron.command()

+ 8
- 8
crons.py View File

@@ -114,7 +114,7 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
if not silent:
print("!!! Error: config not found")
add_log(category="CONFIG", level="ERROR", message="Config not found")
return
raise Exception("config not found")

if os.path.isfile(fname):
os.remove(fname)
@@ -128,7 +128,7 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
if not silent:
print("!! Clublog API Key not defined")
add_log(category="CRONS", level="ERROR", message="Clublog API Key not defined")
return
raise Exception("no clublog_api_key in config")
url = "https://secure.clublog.org/cty.php?api={0}".format(config.clublog_api_key)

try:
@@ -138,7 +138,7 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
except urllib.error.URLError as err:
if not silent:
print("!! Error: {0}".format(err))
exit(-1)
raise Exception(f"error: {err}")
if not silent:
print("-- File downloaded at {0}".format(fname))
elif os.path.isfile(_file):
@@ -147,8 +147,8 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
print("-- File at {0}".format(fname))
else:
if not silent:
print("-- derp ?")
exit()
print("-- what are you trying to do ?")
raise Exception("unknown error")

# Now parse XML file
tree = None
@@ -157,14 +157,14 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
except FileNotFoundError as err:
if not silent:
print("!! Error: {0}".format(err))
exit(-1)
raise Exception(f"file not found: {err}")
except ElementTree.ParseError as err:
if not silent:
print("!! Error: {0}".format(err))
exit(-1)
raise Exception(f"XML Parsing error: {err}")

if not tree:
exit(-1)
raise Exception("XML tree is none")

root = tree.getroot()


tests/init.py → tests/conftest.py View File


+ 0
- 0
tests/test_c_contacts.py View File


+ 0
- 0
tests/test_c_home.py View File


+ 0
- 0
tests/test_c_users.py View File


Loading…
Cancel
Save