Browse Source

Raise exceptions instead of return

pull/37/head
Dashie der otter 9 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
117 117
     @babel.localeselector
118 118
     def get_locale():
119 119
         # if a user is logged in, use the locale from the user settings
120
-        identity = getattr(g, "identity", None)
121
-        if identity is not None and identity.id:
122
-            return identity.user.locale
120
+        # FIXME: not implemented yet
121
+        # identity = getattr(g, "identity", None)
122
+        # if identity is not None and identity.id:
123
+        #     return identity.user.locale
123 124
         # otherwise try to guess the language from the user accept
124 125
         # header the browser transmits.  We support fr/en in this
125 126
         # example.  The best match wins.
@@ -127,9 +128,11 @@ def create_app(config_filename="config.py", app_name=None, register_blueprints=T
127 128
 
128 129
     @babel.timezoneselector
129 130
     def get_timezone():
130
-        identity = getattr(g, "identity", None)
131
-        if identity is not None and identity.id:
132
-            return identity.user.timezone
131
+        # identity = getattr(g, "identity", None)
132
+        # if identity is not None and identity.id:
133
+        #     return identity.user.timezone
134
+        # FIXME: not implemented yet
135
+        pass
133 136
 
134 137
     @app.before_request
135 138
     def before_request():
@@ -302,10 +305,11 @@ def create_app(config_filename="config.py", app_name=None, register_blueprints=T
302 305
         pass
303 306
 
304 307
     @cron.command()
305
-    def update_dxcc_from_cty():
308
+    @click.option("--file", default=None, help="Local file to import instead of downloading", type=click.Path(exists=True))
309
+    def update_dxcc_from_cty(file):
306 310
         """Update DXCC tables from cty.xml"""
307 311
         print("-- STARTED on {0}".format(datetime.datetime.now()))
308
-        update_dxcc_from_cty_xml()
312
+        update_dxcc_from_cty_xml(file)
309 313
         print("-- FINISHED on {0}".format(datetime.datetime.now()))
310 314
 
311 315
     @cron.command()

+ 8
- 8
crons.py View File

@@ -114,7 +114,7 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
114 114
         if not silent:
115 115
             print("!!! Error: config not found")
116 116
         add_log(category="CONFIG", level="ERROR", message="Config not found")
117
-        return
117
+        raise Exception("config not found")
118 118
 
119 119
     if os.path.isfile(fname):
120 120
         os.remove(fname)
@@ -128,7 +128,7 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
128 128
             if not silent:
129 129
                 print("!! Clublog API Key not defined")
130 130
             add_log(category="CRONS", level="ERROR", message="Clublog API Key not defined")
131
-            return
131
+            raise Exception("no clublog_api_key in config")
132 132
         url = "https://secure.clublog.org/cty.php?api={0}".format(config.clublog_api_key)
133 133
 
134 134
         try:
@@ -138,7 +138,7 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
138 138
         except urllib.error.URLError as err:
139 139
             if not silent:
140 140
                 print("!! Error: {0}".format(err))
141
-            exit(-1)
141
+            raise Exception(f"error: {err}")
142 142
         if not silent:
143 143
             print("-- File downloaded at {0}".format(fname))
144 144
     elif os.path.isfile(_file):
@@ -147,8 +147,8 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
147 147
             print("-- File at {0}".format(fname))
148 148
     else:
149 149
         if not silent:
150
-            print("-- derp ?")
151
-        exit()
150
+            print("-- what are you trying to do ?")
151
+        raise Exception("unknown error")
152 152
 
153 153
     # Now parse XML file
154 154
     tree = None
@@ -157,14 +157,14 @@ def update_dxcc_from_cty_xml(_file=None, silent=False):
157 157
     except FileNotFoundError as err:
158 158
         if not silent:
159 159
             print("!! Error: {0}".format(err))
160
-        exit(-1)
160
+        raise Exception(f"file not found: {err}")
161 161
     except ElementTree.ParseError as err:
162 162
         if not silent:
163 163
             print("!! Error: {0}".format(err))
164
-        exit(-1)
164
+        raise Exception(f"XML Parsing error: {err}")
165 165
 
166 166
     if not tree:
167
-        exit(-1)
167
+        raise Exception("XML tree is none")
168 168
 
169 169
     root = tree.getroot()
170 170
 

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