Merge ~sylvain-pineau/checkbox-ng:special_functions_in_templates into checkbox-ng:master

Proposed by Sylvain Pineau
Status: Rejected
Rejected by: Sylvain Pineau
Proposed branch: ~sylvain-pineau/checkbox-ng:special_functions_in_templates
Merge into: checkbox-ng:master
Diff against target: 23 lines (+5/-0)
1 file modified
plainbox/impl/unit/validators.py (+5/-0)
Reviewer Review Type Date Requested Status
Checkbox Developers Pending
Review via email: mp+389650@code.launchpad.net

Description of the change

Allow a combination of the template resource parameters and use of special functions such as __checkbox_env__ in templated jobs.

Use case developed in the checkbox-desktop snap where the resource creates jobs for each GTK theme but the snap channel is decided via config.:

unit: template
template-engine: jinja2
template-resource: gtk_theme
id: snaps/gnome-characters-{{ __checkbox_env__.get("SNAP_CHANNEL_GNOME_CHARACTERS", "stable") }}-{{ theme }}.jpg
plugin: attachment
depends: snaps/gnome-characters-{{ __checkbox_env__.get("SNAP_CHANNEL_GNOME_CHARACTERS", "stable") }}
command:
  [ -f $PLAINBOX_SESSION_SHARE/gnome-characters-{{ __checkbox_env__.get("SNAP_CHANNEL_GNOME_CHARACTERS", "stable") }}-{{ theme }}.jpg ] &&
  cat $PLAINBOX_SESSION_SHARE/gnome-characters-{{ __checkbox_env__.get("SNAP_CHANNEL_GNOME_CHARACTERS", "stable") }}-{{ theme }}.jpg

To post a comment you must log in.
Revision history for this message
Jonathan Cave (jocave) wrote :

Why is a special function desirable for this purpose as opposed to being able to access a parameter from another resource (e.g. the environment resource)?

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

you cannot template from multiple resources

Revision history for this message
Jonathan Cave (jocave) wrote :

No you can't, but I don't understand why you should be allowed to do this as a workaround

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Let's ignore this patch. Dropping the parameter from the id field (the one from __checkbox_env__) did it!

Unmerged commits

4506e0f... by Sylvain Pineau

validators: Allow a combination of template parameters and special functions

such as __checkbox_env__, __system_env__ and __on_ubuntucore__.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/plainbox/impl/unit/validators.py b/plainbox/impl/unit/validators.py
2index af027f8..da3d9d2 100644
3--- a/plainbox/impl/unit/validators.py
4+++ b/plainbox/impl/unit/validators.py
5@@ -474,6 +474,9 @@ class TemplateVariantFieldValidator(FieldValidatorBase):
6 parameter it references is defined in the particular unit being validated.
7 """
8
9+ _special_parameters = [
10+ '__checkbox_env__', '__system_env__', '__on_ubuntucore__']
11+
12 def check(self, parent, unit, field):
13 # Non-parametric units are always valid
14 if unit.is_parametric:
15@@ -491,6 +494,8 @@ class TemplateVariantFieldValidator(FieldValidatorBase):
16 unit, field, Problem.constant, self.message)
17 # Each parameter must be present in the unit
18 for param_name in param_set:
19+ if param_name in self._special_parameters:
20+ continue
21 if param_name not in unit.parameters:
22 message = _(
23 "reference to unknown parameter {!r}"

Subscribers

People subscribed via source and target branches