Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternative for %r mentioned in FAQ #17

Open
baallan opened this issue Feb 17, 2017 · 0 comments
Open

alternative for %r mentioned in FAQ #17

baallan opened this issue Feb 17, 2017 · 0 comments

Comments

@baallan
Copy link

baallan commented Feb 17, 2017

I have a suggestion if the %r mentioned in the FAQ is still open for discussion.
I have implemented on the application end a generalization of the idea of %r.
Let attribute values contain additional nodename format strings of the form %NT.
N is an integer value 0-9. At present, even a cray does not use more than 10 segments in a name.
T is a segment type
%NT is replaced by the Nth segment of type T appearing in the node name.

In my initial implementation the supported values of T are 'd' (integer substrings), 'm' (substrings separated by '-'), and 'u' (substrings separated by '_'). Note that multiple separators of the - or _ types are collapsed to one, so '--' is equivalent to '-' in this scheme.

E.g.

node-gw23 fastnet=node-gw%0d-ib 
node-gw23 otherthing=ot-%1m

yields

node-gw23 fastnet=node-gw23-ib 
node-gw23 otherthing=ot-gw23

This notation allows collapsing definitions in a manner similar to the FAQ %r idea, but with more control.

The exact semantics are given by a bash script below. Equivalent c/c++ are not hard to cook up (I have a c++ version).

gender_substitute () {
        ghost=$1
        val=$2
        if test -z $2; then
                echo ""
                return
        fi
        ilist=$(echo $ghost | sed -e 's/[-_a-zA-Z]*/ /g')
        wlist=$(echo $ghost | sed -e 's/-/ /g')
        ulist=$(echo $ghost | sed -e 's/_/ /g')
        vnew=$val
        n=0
        for i in $ilist; do
                sub="%${n}d"
                vnew=$(echo ${vnew//$sub/$i})
                ((n++))
        done
        n=0
        for w in $wlist; do
                sub="%${n}m"
                vnew=$(echo ${vnew//$sub/$w})
                ((n++))
        done
        n=0
        for u in $ulist; do
                sub="%${n}u"
                vnew=$(echo ${vnew//$sub/$u})
                ((n++))
        done
        echo $vnew
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant