11import json
2- import traceback
32import datetime
43import secrets
54
1312from sqlalchemy .exc import DataError
1413from zipfile import BadZipFile
1514
16- from .utils import authed_request , demand_authed_request , get_uid , id_generator , validate_new_app_fields , is_valid_category , is_valid_appinfo , is_valid_platform , clone_asset_collection_without_images , is_valid_image_file , is_valid_image_size , get_max_image_dimensions , generate_image_url , is_users_developer_id , user_is_wizard , newAppValidationException , algolia_app , first_version_is_newer
17- from .models import Category , db , App , Developer , Release , CompanionApp , Binary , AssetCollection , LockerEntry , UserLike
15+ from .utils import demand_authed_request , id_generator , validate_new_app_fields , is_valid_category , is_valid_appinfo , is_valid_platform , clone_asset_collection_without_images , is_valid_image_file , is_valid_image_size , get_max_image_dimensions , is_users_developer_id , user_is_wizard , newAppValidationException , algolia_app , first_version_is_newer
16+ from .models import db , App , Developer , Release , AssetCollection
1817from .pbw import PBW , release_from_pbw
1918from .s3 import upload_pbw , upload_asset
2019from .settings import config
4443 if config ['ALGOLIA_DISABLE' ]:
4544 algolia_index = None
4645 else :
47- raise KeyError (f "ALGOLIA_ADMIN_API_KEY not set. Either set key or disable algolia integration with ALGOLIA_DISABLE=True" )
46+ raise KeyError ("ALGOLIA_ADMIN_API_KEY not set. Either set key or disable algolia integration with ALGOLIA_DISABLE=True" )
4847
4948@devportal_api .route ('/onboard' , methods = ['POST' ])
5049def create_developer ():
5150 try :
5251 req = request .json
53- except BadRequest as e :
52+ except BadRequest :
5453 return jsonify (error = "Invalid POST body. Expected JSON" , e = "body.invalid" ), 400
5554
5655 if req is None :
@@ -98,19 +97,19 @@ def submit_new_app():
9897 with pbw .zip .open ('appinfo.json' ) as f :
9998 appinfo = json .load (f )
10099 except BadZipFile as e :
101- return jsonify (error = f "Your pbw file is corrupt or invalid" , e = "invalid.pbw" ), 400
100+ return jsonify (error = "Your pbw file is corrupt or invalid" , e = "invalid.pbw" ), 400
102101 except KeyError as e :
103- return jsonify (error = f "Your pbw file is invalid or corrupt" , e = "invalid.pbw" ), 400
102+ return jsonify (error = "Your pbw file is invalid or corrupt" , e = "invalid.pbw" ), 400
104103
105104
106105 appinfo_valid , appinfo_validation_error = is_valid_appinfo (appinfo )
107106 if not appinfo_valid :
108107 return jsonify (error = f"The appinfo.json in your pbw file has the following error: { appinfo_validation_error } " , e = "invalid.appinfocontent" ), 400
109108
110109 if params ["type" ] == "watchface" and not appinfo ["watchapp" ]["watchface" ]:
111- return jsonify (error = f "You selected the app type 'Watchface'. This does not match the configuration in your appinfo.json" , e = "invalid.appinfocontent" ), 400
110+ return jsonify (error = "You selected the app type 'Watchface'. This does not match the configuration in your appinfo.json" , e = "invalid.appinfocontent" ), 400
112111 elif params ["type" ] == "watchapp" and appinfo ["watchapp" ]["watchface" ]:
113- return jsonify (error = f "You selected the app type 'Watch App'. This does not match the configuration in your appinfo.json" , e = "invalid.appinfocontent" ), 400
112+ return jsonify (error = "You selected the app type 'Watch App'. This does not match the configuration in your appinfo.json" , e = "invalid.appinfocontent" ), 400
114113
115114 # Check app doesn't already exist
116115 try :
@@ -229,7 +228,7 @@ def update_app_fields(app_id):
229228
230229 # Check all valid passed fields are correct type
231230 for x in req :
232- if (x in allowed_fields_type_map ) and (not type (req [x ]) == allowed_fields_type_map [x ]):
231+ if (x in allowed_fields_type_map ) and (type (req [x ]) is not allowed_fields_type_map [x ]):
233232 return jsonify (error = f"Invalid value for field '{ x } '" , e = f"invalid.field.{ x } " ), 400
234233
235234
@@ -259,7 +258,7 @@ def update_app_fields(app_id):
259258 if "timeline_enabled" in req :
260259 if not req ["timeline_enabled" ]:
261260 req ["timeline_token" ] = None
262- elif app .timeline_token == None :
261+ elif app .timeline_token is None :
263262 req ["timeline_token" ] = secrets .token_urlsafe (32 )
264263
265264 # Update the app
@@ -303,10 +302,10 @@ def submit_new_release(app_id):
303302 pbw = PBW (pbw_file , 'aplite' )
304303 with pbw .zip .open ('appinfo.json' ) as f :
305304 appinfo = json .load (f )
306- except BadZipFile as e :
307- return jsonify (error = f "Your pbw file is invalid or corrupted" , e = "invalid.pbw" ), 400
308- except KeyError as e :
309- return jsonify (error = f "Your pbw file is invalid or corrupted" , e = "invalid.pbw" ), 400
305+ except BadZipFile :
306+ return jsonify (error = "Your pbw file is invalid or corrupted" , e = "invalid.pbw" ), 400
307+ except KeyError :
308+ return jsonify (error = "Your pbw file is invalid or corrupted" , e = "invalid.pbw" ), 400
310309
311310 appinfo_valid , appinfo_valid_reason = is_valid_appinfo (appinfo )
312311 if not appinfo_valid :
@@ -376,7 +375,7 @@ def get_app_screenshots(app_id, platform):
376375
377376 try :
378377 app = App .query .filter (App .id == app_id ).one ()
379- except NoResultFound as e :
378+ except NoResultFound :
380379 return jsonify (error = "Unknown app" , e = "app.notfound" ), 400
381380
382381 asset_collection = AssetCollection .query .filter (AssetCollection .app_id == app .id , AssetCollection .platform == platform ).one_or_none ()
@@ -390,7 +389,7 @@ def get_app_screenshots(app_id, platform):
390389def new_app_screenshots (app_id , platform ):
391390 try :
392391 app = App .query .filter (App .id == app_id ).one ()
393- except NoResultFound as e :
392+ except NoResultFound :
394393 return jsonify (error = "Unknown app" , e = "app.notfound" ), 400
395394
396395 # Check we own the app
@@ -437,7 +436,7 @@ def new_app_screenshots(app_id, platform):
437436def delete_screenshot (app_id , platform , screenshot_id ):
438437 try :
439438 app = App .query .filter (App .id == app_id ).one ()
440- except NoResultFound as e :
439+ except NoResultFound :
441440 return jsonify (error = "Unknown app" , e = "app.notfound" ), 400
442441
443442 # Check we own the app
@@ -476,7 +475,7 @@ def get_app_banners(app_id, platform):
476475
477476 try :
478477 app = App .query .filter (App .id == app_id ).one ()
479- except NoResultFound as e :
478+ except NoResultFound :
480479 return jsonify (error = "Unknown app" , e = "app.notfound" ), 404
481480
482481 asset_collection = AssetCollection .query .filter (AssetCollection .app_id == app .id , AssetCollection .platform == platform ).one_or_none ()
@@ -490,7 +489,7 @@ def get_app_banners(app_id, platform):
490489def new_app_banner (app_id , platform ):
491490 try :
492491 app = App .query .filter (App .id == app_id ).one ()
493- except NoResultFound as e :
492+ except NoResultFound :
494493 return jsonify (error = "Unknown app" , e = "app.notfound" ), 404
495494
496495 # Check we own the app
@@ -538,7 +537,7 @@ def new_app_banner(app_id, platform):
538537def delete_banner (app_id , platform , banner_id ):
539538 try :
540539 app = App .query .filter (App .id == app_id ).one ()
541- except NoResultFound as e :
540+ except NoResultFound :
542541 return jsonify (error = "Unknown app" , e = "app.notfound" ), 404
543542
544543 # Check we own the app
@@ -572,7 +571,7 @@ def delete_banner(app_id, platform, banner_id):
572571def get_app_icons (app_id ):
573572 try :
574573 app = App .query .filter (App .id == app_id ).one ()
575- except NoResultFound as e :
574+ except NoResultFound :
576575 return jsonify (error = "Unknown app" , e = "app.notfound" ), 404
577576
578577
@@ -585,7 +584,7 @@ def get_app_icon(app_id, size):
585584
586585 try :
587586 app = App .query .filter (App .id == app_id ).one ()
588- except NoResultFound as e :
587+ except NoResultFound :
589588 return jsonify (error = "Unknown app" , e = "app.notfound" ), 404
590589
591590 out = app .icon_small if size == "small" else app .icon_large
@@ -598,7 +597,7 @@ def new_app_icon(app_id, size):
598597
599598 try :
600599 app = App .query .filter (App .id == app_id ).one ()
601- except NoResultFound as e :
600+ except NoResultFound :
602601 return jsonify (error = "Unknown app" , e = "app.notfound" ), 404
603602
604603 # Check we own the app
@@ -640,7 +639,7 @@ def wizard_rename_developer(developer_id):
640639
641640 try :
642641 req = request .json
643- except BadRequest as e :
642+ except BadRequest :
644643 return jsonify (error = "Invalid POST body. Expected JSON" , e = "body.invalid" ), 400
645644
646645 if req is None :
@@ -651,7 +650,7 @@ def wizard_rename_developer(developer_id):
651650 return jsonify (error = f"Illegal field: { f } " , e = "illegal.field" ), 400
652651
653652 if "name" not in req :
654- return jsonify (error = f "Missing required field: name" , e = "missing.field.name" ), 400
653+ return jsonify (error = "Missing required field: name" , e = "missing.field.name" ), 400
655654
656655
657656 developer = Developer .query .filter_by (id = developer_id ).one_or_none ()
@@ -675,7 +674,7 @@ def wizard_update_app(app_id):
675674
676675 try :
677676 req = request .json
678- except BadRequest as e :
677+ except BadRequest :
679678 return jsonify (error = "Invalid POST body. Expected JSON" , e = "body.invalid" ), 400
680679
681680 if req is None :
@@ -702,7 +701,7 @@ def wizard_update_app(app_id):
702701 try :
703702 db .session .commit ()
704703 return jsonify (success = True , id = app .id , developer_id = app .developer_id )
705- except IntegrityError as e :
704+ except IntegrityError :
706705 return jsonify (error = "Failed to update developer ID. Does new ID exist?" , e = "body.invalid" ), 400
707706 else :
708707 return jsonify (error = "Invalid POST body. Provide one or more fields to update" , e = "body.invalid" ), 400
0 commit comments