Changeset View
Changeset View
Standalone View
Standalone View
contrib/teamcity/build-configurations.py
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | def load(self, build_name): | ||||
"{} is not a valid build identifier. Valid identifiers are {}".format( | "{} is not a valid build identifier. Valid identifiers are {}".format( | ||||
self.name, list(config.keys()) | self.name, list(config.keys()) | ||||
) | ) | ||||
) | ) | ||||
# Get a list of the templates, if any | # Get a list of the templates, if any | ||||
templates = config.get("templates", {}) | templates = config.get("templates", {}) | ||||
# If the build references a template, merge the configurations | # If the build references some templates, merge all the configurations. | ||||
template_name = build.get("template", None) | # The merge is applied in the same order as the templates are declared | ||||
if template_name: | # in the template list. | ||||
template_config = {} | |||||
template_names = build.get("templates", []) | |||||
for template_name in template_names: | |||||
# Raise an error if the template does not exist | # Raise an error if the template does not exist | ||||
if template_name not in templates: | if template_name not in templates: | ||||
raise AssertionError( | raise AssertionError( | ||||
"Build {} configuration inherits from template {}, but the template does not exist.".format( | "Build {} configuration inherits from template {}, but the template does not exist.".format( | ||||
self.name, | self.name, | ||||
template_name | template_name | ||||
) | ) | ||||
) | ) | ||||
always_merger.merge(template_config, templates.get(template_name)) | |||||
# If the template exists, apply the build configuration on top of the | self.config = always_merger.merge(template_config, build) | ||||
# template. Otherwise it is equivalent to the build configuration | |||||
# alone. | |||||
self.config = always_merger.merge( | |||||
templates.get(template_name, {}), build) | |||||
# Make sure there is a script file associated with the build... | # Make sure there is a script file associated with the build... | ||||
script = self.config.get("script", None) | script = self.config.get("script", None) | ||||
if script is None: | if script is None: | ||||
raise AssertionError( | raise AssertionError( | ||||
"No script provided for the build {}".format( | "No script provided for the build {}".format( | ||||
self.name | self.name | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 278 Lines • Show Last 20 Lines |