1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
def _generate_show_url(context, entry):
url = entry["url"]
return {
"actions": "showURL",
"openURL": url.format(**context),
}
def _generate_product_details(context, entry):
url = entry["url"]
return {
"detailsURL": url.format(**context),
"type": "minor",
}
_FIELD_TYPES = {
"show-url": _generate_show_url,
"product-details": _generate_product_details,
}
def _generate_conditions(context, entry):
if (
"release-types" in entry
and context["release-type"] not in entry["release-types"]
):
return None
if "blob-types" in entry and context["blob-type"] not in entry["blob-types"]:
return None
if "products" in entry and context["product"] not in entry["products"]:
return None
conditions = {}
if "locales" in entry:
conditions["locales"] = entry["locales"]
if "versions" in entry:
conditions["versions"] = [
version.format(**context) for version in entry["versions"]
]
if "update-channel" in entry:
conditions["channels"] = [
entry["update-channel"] + suffix
for suffix in ("", "-localtest", "-cdntest")
]
if "build-ids" in entry:
conditions["buildIDs"] = [
buildid.format(**context) for buildid in entry["build-ids"]
]
return conditions
def generate_update_properties(context, config):
result = []
for entry in config:
fields = _FIELD_TYPES[entry["type"]](context, entry)
conditions = _generate_conditions(context, entry.get("conditions", {}))
if conditions is not None:
result.append(
{
"fields": fields,
"for": conditions,
}
)
return result
|