From e87a49c66a3f7d522d89faffe021ac937be3a3a3 Mon Sep 17 00:00:00 2001 From: Bernd Wachter Date: Wed, 27 Mar 2013 21:40:16 +0200 Subject: [PATCH] Add support for := variable substitution --- libssu/ssuvariables.cpp | 13 +++++++++++++ repos.ini | 3 +++ rpm/ssu.changes | 3 +++ rpm/ssu.spec | 2 +- tests/ut_variables/variablestest.cpp | 5 +++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libssu/ssuvariables.cpp b/libssu/ssuvariables.cpp index dd0a9f9..4132e4f 100644 --- a/libssu/ssuvariables.cpp +++ b/libssu/ssuvariables.cpp @@ -103,6 +103,19 @@ QString SsuVariables::resolveVariable(QString variable, QHash if (variableValue != "") return variableSub.toString(); break; + case '=': { + // %(%(foo):=bar?foobar|baz) + // if foo == bar then return foobar, else baz + QString sub = variableSub.toString(); + QString a = sub.left(sub.indexOf("?")); + QString b = sub.right(sub.length() - sub.indexOf("?") - 1); + if (b.indexOf("|") == -1) + return b; + if (variableName == a) + return b.left(b.indexOf("|")); + else + return b.right(b.length() - b.indexOf("|") - 1); + } } // no proper substitution found -> return default value diff --git a/repos.ini b/repos.ini index 556bfbc..9118324 100644 --- a/repos.ini +++ b/repos.ini @@ -22,6 +22,9 @@ # Basic variable substitution is supported: # %(foo:+bar) -- expands to "" if foo is set, bar otherwise # %(foo:-bar) -- expands to %(foo) if foo is set, bar otherwise +# %(%(foo):=bar?foobar|baz) -- expands to foobar if %(foo) == bar, to baz +# otherwise. %(foo) should only be alphanumeric. It must not +# contain the character '?'. # # Repository lookup will happen based on the 'repo' parameter in repository # URLs. For RnD repositories order will be -> rnd -> all, for diff --git a/rpm/ssu.changes b/rpm/ssu.changes index b22a2e8..de62ee3 100644 --- a/rpm/ssu.changes +++ b/rpm/ssu.changes @@ -1,3 +1,6 @@ +* Wed Mar 27 2013 Bernd Wachter - 0.27 +- Add support for := in variable substitution + * Wed Mar 27 2013 Bernd Wachter - 0.26 - Take all adaptations from adaptation-repos list, allow freeform variables for adaptations diff --git a/rpm/ssu.spec b/rpm/ssu.spec index d633925..ac75cfc 100644 --- a/rpm/ssu.spec +++ b/rpm/ssu.spec @@ -1,5 +1,5 @@ Name: ssu -Version: 0.26 +Version: 0.27 Release: 1 Summary: SSU enabler for RND Group: System/Base diff --git a/tests/ut_variables/variablestest.cpp b/tests/ut_variables/variablestest.cpp index adc826b..94b9ab7 100644 --- a/tests/ut_variables/variablestest.cpp +++ b/tests/ut_variables/variablestest.cpp @@ -44,6 +44,11 @@ void VariablesTest::initTestCase(){ // substitution of variable with empty variable + /set -- should substitute to "" urls.insert("%(rndProtocol)://%(unsetDomain:+%(unsetDomain)/set)/nemo/%(release)-%(flavourName)/platform/%(arch)/", "https:///nemo/devel-flavour/platform/armv8/"); + // test := + urls.insert("%(%(rndProtocol):=https?https://%(releaseDomain)/%(release)-%(flavourName)|http://%(releaseDomain)/%(release)-%(flavourName))", + "https://releases.example.com/devel-flavour"); + urls.insert("%(%(rndProtocol):=http?https://%(releaseDomain)/%(release)-%(flavourName)|http://%(releaseDomain)/%(release)-%(flavourName))", + "http://releases.example.com/devel-flavour"); }