| Index: sitescripts/extensions/web/adblockbrowserUpdates.py |
| =================================================================== |
| --- a/sitescripts/extensions/web/adblockbrowserUpdates.py |
| +++ b/sitescripts/extensions/web/adblockbrowserUpdates.py |
| @@ -25,7 +25,7 @@ |
| from sitescripts.utils import get_config |
| from sitescripts.web import url_handler |
| -_MANIFEST_TEMPLATE = Template("""<?xml version="1.0"?> |
| +_MANIFEST_TEMPLATE = Template('''<?xml version="1.0"?> |
| <updates> |
| {% if build %} |
| <update buildID="{{ build.build_id }}"> |
| @@ -38,19 +38,19 @@ |
| {% endif %} |
| </updates> |
| -""", autoescape=True) |
| +''', autoescape=True) |
| def _get_latest_build(builds_dir): |
| - latest_build = {"id": 0} |
| - for json_path in glob.glob(os.path.join(builds_dir, "adblockbrowser-*.json")): |
| + latest_build = {'id': 0} |
| + for json_path in glob.glob(os.path.join(builds_dir, 'adblockbrowser-*.json')): |
| with open(json_path) as json_file: |
| - build_id = int(json.loads(json_file.read())["buildid"]) |
| - if build_id > latest_build["id"]: |
| - latest_build["id"] = build_id |
| - apk_path = os.path.splitext(json_path)[0] + ".apk" |
| - latest_build["path"] = os.path.join(builds_dir, apk_path) |
| - if latest_build["id"] == 0: |
| + build_id = int(json.loads(json_file.read())['buildid']) |
| + if build_id > latest_build['id']: |
| + latest_build['id'] = build_id |
| + apk_path = os.path.splitext(json_path)[0] + '.apk' |
| + latest_build['path'] = os.path.join(builds_dir, apk_path) |
| + if latest_build['id'] == 0: |
| return {} |
| return latest_build |
| @@ -59,16 +59,16 @@ |
| if not build: |
| return _MANIFEST_TEMPLATE.render() |
| - build_url = "%s/%s?update" % (builds_url, os.path.basename(build["path"])) |
| - with open(build["path"], "rb") as build_file: |
| + build_url = '%s/%s?update' % (builds_url, os.path.basename(build['path'])) |
| + with open(build['path'], 'rb') as build_file: |
| build_content = build_file.read() |
| return _MANIFEST_TEMPLATE.render({ |
| - "build": { |
| - "build_id": build["id"], |
| - "url": build_url, |
| - "hash_function": "SHA512", |
| - "hash_value": hashlib.sha512(build_content).hexdigest(), |
| - "size": len(build_content) |
| + 'build': { |
| + 'build_id': build['id'], |
| + 'url': build_url, |
| + 'hash_function': 'SHA512', |
| + 'hash_value': hashlib.sha512(build_content).hexdigest(), |
| + 'size': len(build_content) |
| } |
| }) |
| @@ -78,43 +78,43 @@ |
| return _render_manifest() |
| latest_build = _get_latest_build(builds_dir) |
| - if not latest_build or current_build_id >= latest_build["id"]: |
| + if not latest_build or current_build_id >= latest_build['id']: |
| return _render_manifest() |
| return _render_manifest(latest_build, builds_url) |
| def _handle_request(environ, start_response, builds_dir, builds_url): |
| - params = parse_qs(environ.get("QUERY_STRING", "")) |
| + params = parse_qs(environ.get('QUERY_STRING', '')) |
| try: |
| - version = params.get("addonVersion", [""])[0] |
| - build_id = int(re.search(r"(\d+)$", version).group(1)) |
| + version = params.get('addonVersion', [''])[0] |
| + build_id = int(re.search(r'(\d+)$', version).group(1)) |
| except: |
| - start_response("400 Processing Error", [("Content-Type", "text/plain")]) |
| - return ["Failed to parse addonVersion."] |
| + start_response('400 Processing Error', [('Content-Type', 'text/plain')]) |
| + return ['Failed to parse addonVersion.'] |
| manifest = _get_update_manifest(build_id, builds_dir, builds_url) |
| - response = manifest.encode("utf-8") |
| - start_response("200 OK", [("Content-Type", "application/xml; charset=utf-8")]) |
| + response = manifest.encode('utf-8') |
| + start_response('200 OK', [('Content-Type', 'application/xml; charset=utf-8')]) |
| return [response] |
| -@url_handler("/adblockbrowser/updates.xml") |
| +@url_handler('/adblockbrowser/updates.xml') |
| def adblockbrowser_updates(environ, start_response): |
| config = get_config() |
| - builds_dir = config.get("extensions", "downloadsDirectory") |
| - builds_url = config.get("extensions", "downloadsURL").rstrip("/") |
| + builds_dir = config.get('extensions', 'downloadsDirectory') |
| + builds_url = config.get('extensions', 'downloadsURL').rstrip('/') |
| return _handle_request(environ, start_response, builds_dir, builds_url) |
| -@url_handler("/devbuilds/adblockbrowser/updates.xml") |
| +@url_handler('/devbuilds/adblockbrowser/updates.xml') |
| def adblockbrowser_devbuild_updates(environ, start_response): |
| config = get_config() |
| - nightlies_dir = config.get("extensions", "nightliesDirectory") |
| - builds_dir = os.path.join(nightlies_dir, "adblockbrowser") |
| + nightlies_dir = config.get('extensions', 'nightliesDirectory') |
| + builds_dir = os.path.join(nightlies_dir, 'adblockbrowser') |
| - nightlies_url = config.get("extensions", "nightliesURL").rstrip("/") |
| - builds_url = "%s/adblockbrowser" % nightlies_url |
| + nightlies_url = config.get('extensions', 'nightliesURL').rstrip('/') |
| + builds_url = '%s/adblockbrowser' % nightlies_url |
| return _handle_request(environ, start_response, builds_dir, builds_url) |