Index: sitescripts/extensions/web/adblockbrowserUpdates.py |
=================================================================== |
--- a/sitescripts/extensions/web/adblockbrowserUpdates.py |
+++ b/sitescripts/extensions/web/adblockbrowserUpdates.py |
@@ -15,7 +15,9 @@ |
# You should have received a copy of the GNU General Public License |
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+import glob |
import hashlib |
+import json |
import os |
import re |
from urlparse import parse_qs |
@@ -42,24 +44,27 @@ |
def _get_latest_build(builds_dir): |
latest_build = {"id": 0} |
- for file in os.listdir(builds_dir): |
- match = re.search(r"^adblockbrowser-.*?(\d+)-\w+\.apk$", file) |
- if match: |
- build_id = int(match.group(1)) |
- if build_id > latest_build["id"]: |
- latest_build["id"] = build_id |
- latest_build["path"] = os.path.join(builds_dir, file) |
+ 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 = re.sub(r"\.json$", ".apk", json_path) |
Sebastian Noack
2015/11/13 22:07:39
Checking for the file extension here is redundant.
Felix Dahlke
2015/11/14 00:41:05
Done.
|
+ latest_build["path"] = os.path.join(builds_dir, apk_path) |
if latest_build["id"] == 0: |
return {} |
return latest_build |
-def _render_manifest(build=None): |
+def _render_manifest(build=None, devbuild=False): |
if not build: |
return _MANIFEST_TEMPLATE.render() |
- nightlies_url = get_config().get("extensions", "nightliesURL") |
- build_url = "%s/adblockbrowser/%s?update" % (nightlies_url.rstrip("/"), |
- os.path.basename(build["path"])) |
+ if devbuild: |
+ nightlies_url = get_config().get("extensions", "nightliesURL") |
+ builds_url = "%s/adblockbrowser" % nightlies_url.rstrip("/") |
Sebastian Noack
2015/11/13 22:07:39
rstrip("/") is duplicated. How about moving it bel
Felix Dahlke
2015/11/14 00:41:05
How would that look? Note that I need to call rstr
|
+ else: |
+ builds_url = get_config().get("extensions", "downloadsURL").rstrip("/") |
+ 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({ |
@@ -72,19 +77,22 @@ |
} |
}) |
-def _get_update_manifest(current_build_id): |
- nightlies_dir = get_config().get("extensions", "nightliesDirectory") |
- builds_dir = os.path.join(nightlies_dir, "adblockbrowser") |
+def _get_update_manifest(current_build_id, devbuild): |
+ if devbuild: |
+ nightlies_dir = get_config().get("extensions", "nightliesDirectory") |
+ builds_dir = os.path.join(nightlies_dir, "adblockbrowser") |
+ else: |
+ builds_dir = get_config().get("extensions", "downloadsDirectory") |
+ |
if not os.path.isdir(builds_dir): |
return _render_manifest() |
latest_build = _get_latest_build(builds_dir) |
if not latest_build or current_build_id >= latest_build["id"]: |
return _render_manifest() |
- return _render_manifest(latest_build) |
+ return _render_manifest(latest_build, devbuild) |
-@url_handler("/devbuilds/adblockbrowser/updates.xml") |
-def adblockbrowser_updates(environ, start_response): |
+def _handle_request(environ, start_response, devbuild): |
params = parse_qs(environ.get("QUERY_STRING", "")) |
try: |
version = params.get("addonVersion", [""])[0] |
@@ -92,7 +100,15 @@ |
except: |
start_response("400 Processing Error", [("Content-Type", "text/plain")]) |
return ["Failed to parse addonVersion."] |
- manifest = _get_update_manifest(build_id) |
+ manifest = _get_update_manifest(build_id, devbuild) |
response = manifest.encode("utf-8") |
start_response("200 OK", [("Content-Type", "application/xml; charset=utf-8")]) |
return [response] |
+ |
+@url_handler("/adblockbrowser/updates.xml") |
+def adblockbrowser_updates(environ, start_response): |
+ return _handle_request(environ, start_response, False) |
Sebastian Noack
2015/11/13 22:07:39
I think the code flow would be simpler when you de
Felix Dahlke
2015/11/14 00:41:05
Done.
|
+ |
+@url_handler("/devbuilds/adblockbrowser/updates.xml") |
+def adblockbrowser_devbuild_updates(environ, start_response): |
+ return _handle_request(environ, start_response, True) |