Skip to content

Commit

Permalink
Add support for := variable substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Wachter committed Mar 27, 2013
1 parent b6ba584 commit e87a49c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions libssu/ssuvariables.cpp
Expand Up @@ -103,6 +103,19 @@ QString SsuVariables::resolveVariable(QString variable, QHash<QString, QString>
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
Expand Down
3 changes: 3 additions & 0 deletions repos.ini
Expand Up @@ -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 <flavour> -> rnd -> all, for
Expand Down
3 changes: 3 additions & 0 deletions rpm/ssu.changes
@@ -1,3 +1,6 @@
* Wed Mar 27 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 0.27
- Add support for := in variable substitution

* Wed Mar 27 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 0.26
- Take all adaptations from adaptation-repos list, allow freeform variables for adaptations

Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
5 changes: 5 additions & 0 deletions tests/ut_variables/variablestest.cpp
Expand Up @@ -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");

}

Expand Down

0 comments on commit e87a49c

Please sign in to comment.