Skip to content

Commit 12420cf

Browse files
authored
Merge pull request #55 from aveao/cleanups
Clean up minor issues in entire codebase
2 parents 554cfc1 + f0048ae commit 12420cf

File tree

10 files changed

+60
-65
lines changed

10 files changed

+60
-65
lines changed

appstore/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
except ImportError:
99
print("Couldn't import google exceptions")
1010

11-
from flask import Flask, jsonify, request
11+
from flask import Flask, jsonify
1212
from werkzeug.middleware.proxy_fix import ProxyFix
1313
from rws_common import honeycomb
1414

@@ -20,7 +20,6 @@
2020
from .developer_portal_api import init_app as init_developer_portal_api
2121
from .commands import init_app as init_commands
2222
from .utils import init_app as init_utils
23-
from .locker import locker
2423

2524
app = Flask(__name__)
2625
app.config.update(**config)

appstore/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def home(home_type):
211211
'apps': url_for('api.apps_by_collection', slug=collection.slug, app_type=home_type)
212212
},
213213
} for collection in collections), {
214-
'name': f'Most Loved',
214+
'name': 'Most Loved',
215215
'slug': 'most-loved',
216216
'application_ids': [
217217
x.id for x in App.query
@@ -235,7 +235,7 @@ def home(home_type):
235235
'apps': url_for('api.apps_by_collection', slug='all', app_type=home_type),
236236
}
237237
}, *([{
238-
'name': f'Generated Watchfaces',
238+
'name': 'Generated Watchfaces',
239239
'slug': 'all-generated',
240240
'application_ids': [
241241
x.id for x in App.query

appstore/commands.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import flask.json
77
import shutil
88
import subprocess
9-
import uuid
109
import zipfile
1110

1211
import click
@@ -16,7 +15,6 @@
1615
import requests
1716
from sqlalchemy.orm import load_only
1817
from sqlalchemy.orm.exc import NoResultFound
19-
from sqlalchemy.exc import IntegrityError
2018

2119
from algoliasearch import algoliasearch
2220

@@ -248,7 +246,7 @@ def import_app_from_locker(locker_app):
248246
if not os.path.exists(filename):
249247
with requests.get(release['file'], stream=True) as r:
250248
if r.status_code != 200:
251-
print(f"FAILED to download pbw.")
249+
print("FAILED to download pbw.")
252250
return False
253251
with open(filename, 'wb') as f:
254252
shutil.copyfileobj(r.raw, f)

appstore/dev_portal_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sqlalchemy.orm.exc import NoResultFound
77
from datetime import datetime
88

9-
from .utils import authed_request, demand_authed_request, get_uid
9+
from .utils import demand_authed_request, get_uid
1010
from .models import LockerEntry, UserLike, db, App, Developer, UserFlag
1111
from .discord import report_app_flag
1212
from .settings import config
@@ -98,11 +98,11 @@ def update_my_developer():
9898
return jsonify(error="Invalid POST body. Expected JSON and 'Content-Type: application/json'", e="request.invalid"), 400
9999

100100
for f in req:
101-
if not f in permitted_fields:
101+
if f not in permitted_fields:
102102
return jsonify(error=f"Illegal field: {f}", e="illegal.field"), 400
103103

104-
if not "name" in req:
105-
return jsonify(error=f"Missing required field: name", e="missing.field.name"), 400
104+
if "name" not in req:
105+
return jsonify(error="Missing required field: name", e="missing.field.name"), 400
106106

107107
# Resolve our auth token to our developer ID
108108
result = demand_authed_request('GET', f"{config['REBBLE_AUTH_URL']}/api/v1/me/pebble/appstore")

appstore/developer_portal_api.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import traceback
32
import datetime
43
import secrets
54

@@ -13,8 +12,8 @@
1312
from sqlalchemy.exc import DataError
1413
from 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
1817
from .pbw import PBW, release_from_pbw
1918
from .s3 import upload_pbw, upload_asset
2019
from .settings import config
@@ -44,13 +43,13 @@
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'])
5049
def 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):
390389
def 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):
437436
def 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):
490489
def 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):
538537
def 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):
572571
def 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

appstore/discord.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from .settings import config
66
from .utils import get_app_description, generate_image_url, who_am_i
7-
from appstore.models import App
87

98
party_time_emoji = ["🎉","🥳","👏","❤️","🥰","🎊"]
109

@@ -113,9 +112,9 @@ def audit_log(operation, affected_app_uuid = None):
113112

114113
request_data = {
115114
"embeds": [{
116-
"title": f"Wizard Audit Log 🪄",
115+
"title": "Wizard Audit Log 🪄",
117116
"color": int("0xffaa00", 0),
118-
"description": f"Someone has executed a wizard operation on the developer portal",
117+
"description": "Someone has executed a wizard operation on the developer portal",
119118
"thumbnail": {
120119
"url": "https://dev-portal.rebble.io/res/img/large_icon_launchpad.svg",
121120
"height": 80,
@@ -149,9 +148,9 @@ def report_app_flag(reported_by, app_name, developer_name, app_id, affected_app_
149148

150149
request_data = {
151150
"embeds": [{
152-
"title": f"New Flagged App Report 🚩",
151+
"title": "New Flagged App Report 🚩",
153152
"color": int("0xFF4745", 0),
154-
"description": f"An end user has reported an app on the appstore from within a mobile app.",
153+
"description": "An end user has reported an app on the appstore from within a mobile app.",
155154
"thumbnail": {
156155
"url": "https://i.imgur.com/5f6rGQ9.png",
157156
"height": 80,

appstore/locker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sqlalchemy.orm.exc import NoResultFound
77

88
from .settings import config
9-
from .models import App, LockerEntry, Release, db
9+
from .models import App, LockerEntry, db
1010
from .api import api
1111
from .utils import get_uid, generate_pbw_url, asset_fallback, generate_image_url, plat_dimensions, jsonify_companion, get_access_token
1212

appstore/pbw.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import zipfile
1010
import datetime
1111
import hashlib
12-
from .models import Binary, App, Release, db
12+
from .models import Binary, Release, db
1313
from .utils import id_generator
1414

1515
PLATFORMS = ['aplite', 'basalt', 'chalk', 'diorite', 'emery', 'flint']
@@ -49,9 +49,9 @@ def __init__(self, pbw, platform):
4949
self.platform = platform
5050
# pbw can be file path or bytes bundle. Determine which
5151
if isinstance(pbw, str):
52-
bundle = os.path.abspath(bundle_path)
53-
if not os.path.exists(bundle):
54-
raise Exception("Bundle does not exist: " + bundle_path)
52+
bundle_abs_path = os.path.abspath(pbw)
53+
if not os.path.exists(bundle_abs_path):
54+
raise Exception("Bundle does not exist: " + pbw)
5555

5656
self.path = bundle_abs_path
5757
else:
@@ -185,7 +185,7 @@ def get_capabilities(self):
185185
def create_binary(self, release):
186186
if not self.has_platform:
187187
return
188-
metadata = self.get_app_metadata();
188+
metadata = self.get_app_metadata()
189189
binary = Binary(release=release, platform=self.platform,
190190
sdk_major=metadata['sdk_version_major'], sdk_minor=metadata['sdk_version_minor'],
191191
process_info_flags=metadata['flags'], icon_resource_id=metadata['icon_resource_id'])

appstore/s3.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import json
22
import boto3
3-
from botocore.exceptions import ClientError
4-
from .models import Binary
53
from .settings import config
64
from .utils import id_generator
75

@@ -17,7 +15,7 @@
1715
aws_secret_access_key=config['AWS_SECRET_KEY'],
1816
)
1917
s3_endpoint = config['S3_ENDPOINT']
20-
except:
18+
except Exception:
2119
pass
2220

2321

@@ -41,7 +39,7 @@
4139
aws_session_token=creds['Credentials'].get('SessionToken'),
4240
)
4341
s3_endpoint = creds.get('S3Endpoint')
44-
except:
42+
except Exception:
4543
pass
4644

4745
if not session:
@@ -74,7 +72,7 @@ def upload_asset(file, mime_type = None):
7472
elif file.endswith(".png"):
7573
mime_type = "image/png"
7674
else:
77-
raise Exception(f"Unknown or unsupported mime_type for file provided to update_asset")
75+
raise Exception("Unknown or unsupported mime_type for file provided to update_asset")
7876

7977
s3 = session.client('s3', endpoint_url=s3_endpoint)
8078
s3.upload_file(file, config['S3_ASSET_BUCKET'], filename, ExtraArgs = {'ContentType': mime_type})

0 commit comments

Comments
 (0)