<div dir="ltr"><div dir="ltr">Awesome, thanks! I'll give that a go. but perfect.<br><div>that syntax <b style="color:rgb(166,77,121)">return props.getProperty("baselines")[2] </b><font color="#000000">I would not have guessed. I was thinking </font><b style="color:rgb(166,77,121)">baselines[2],</b></div><div><font color="#000000">but thanks for putting me right.</font></div><div><font color="#000000">Am I correct in thinking if the property baselines was a dictionary, with a number of keys and I wanted to access a key in the dictionary the syntax for accessing the key</font></div><div><font color="#000000">would be </font><b style="color:rgb(166,77,121)">return props.getProperty("baselines")['my_custom_key']</b></div></div>Is that correct<div><br></div><div>Many thanks already. Will give this a try shortly.</div><div><br></div><div>Regards<br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Aug 3, 2019 at 1:12 PM Pierre Tardy <<a href="mailto:tardyp@gmail.com">tardyp@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">You need to use SetPropertyFromCommand if you want to parse output of a command.<br>
<br>
def glob2list(rc, stdout, stderr):<br>
    baselines = [l.strip() for l in stdout.split('\n')]<br>
    return {'baselines': baselines} # this sets property 'baselines'<br>
to the splitted list of baselines<br>
<br>
f.addStep(steps.SetPropertyFromCommand(command=['ccm', 'baseline',<br>
'-list'], extract_fn=get_release_function']))<br>
<br>
@util.renderer<br>
def get_third_baseline(props):<br>
     return props.getProperty("baselines")[2]<br>
<br>
# get_third_baseline will be invoked at build runtime, and at that<br>
time the props variables will be known, so that we can get the third<br>
element of the baselines list<br>
f.addStep(steps.ShellCommand(command=['ccm', 'baseline', '-checkout',<br>
get_third_baseline]))<br>
<br>
Pierre<br>
<br>
Le ven. 2 août 2019 à 22:35, honas grael <<a href="mailto:honasgraeymael@gmail.com" target="_blank">honasgraeymael@gmail.com</a>> a écrit :<br>
><br>
> umm yes, basically in my case (please feel free to suggest something better) I have<br>
><br>
> def get_release_function(rc, stdout, sterr)<br>
>     .... release_list = [l.strip() for l in stdout.split('\n')]<br>
><br>
>     return {'list_of_releases': release_list}<br>
><br>
><br>
> f.addStep(steps.ShellCommand(command=['ccm baseline -list extract_fn=get_release_function']))<br>
><br>
> so the step sets a property 'list_of_releases' with a list of strings. At least that is what I understand. (please correct me if I am wrong)<br>
><br>
> Later on (in a later step) I want to pick out element 3 from the property 'list_of_releases' so that I can use element 3 to do another query on the vcs.<br>
><br>
> that is at the heart of what I am trying (i.e set a property, then later on retrieve elements of that property)<br>
><br>
> On Fri, Aug 2, 2019 at 9:24 PM Pierre Tardy <<a href="mailto:tardyp@gmail.com" target="_blank">tardyp@gmail.com</a>> wrote:<br>
>><br>
>> Ok, so this is only a parameter of SetPropertyFromCommand, not a<br>
>> generic parameter for all steps.<br>
>><br>
>> Pierre<br>
>><br>
>> Le ven. 2 août 2019 à 22:23, honas grael <<a href="mailto:honasgraeymael@gmail.com" target="_blank">honasgraeymael@gmail.com</a>> a écrit :<br>
>> ><br>
>> > Thank you Pierre,<br>
>> ><br>
>> > I will give this a try. I probably have a few other questions. e.g I am not sure how to pass variables from one buildstep to another.<br>
>> > But probably best once I have tried a few things and then I can give a better answer<br>
>> ><br>
>> > extract_fn is in the documentation <a href="http://docs.buildbot.net/current/manual/configuration/buildsteps.html?highlight=extract_fn" rel="noreferrer" target="_blank">http://docs.buildbot.net/current/manual/configuration/buildsteps.html?highlight=extract_fn</a><br>
>> ><br>
>> > ... more advanced usage allows you to specify a function to extract properties from the command output. Here you can use regular expressions, string interpolation, or whatever you would like. In this form, extract_fn should be passed, and not Property. The extract_fn function is called with three arguments: the exit status of the command, its standard output as a string, and its standard error as a string. It should return a dictionary containing all new properties.<br>
>> ><br>
>> > Note that passing in extract_fn will set includeStderr to True.<br>
>> ><br>
>> > def glob2list(rc, stdout, stderr):<br>
>> >     jpgs = [l.strip() for l in stdout.split('\n')]<br>
>> >     return {'jpgs': jpgs}<br>
>> ><br>
>> > f.addStep(SetPropertyFromCommand(command="ls -1 *.jpg", extract_fn=glob2list))<br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > In this example above, i guess it is setting a userdefined property called 'jpgs', with a list of jpegs from stdout. Now if in a later step I wanted to get the third element from the the property 'jpgs' I am not clear exactly how I would get that property<br>
>> ><br>
>> > But thank you for responding<br>
>> ><br>
>> > On Fri, Aug 2, 2019 at 7:36 PM Pierre Tardy <<a href="mailto:tardyp@gmail.com" target="_blank">tardyp@gmail.com</a>> wrote:<br>
>> >><br>
>> >> Hi,<br>
>> >><br>
>> >> I you want to use list based version of ShellCommand, you need to use<br>
>> >> one word per string.<br>
>> >> Your version probably worked, because of implementation details of the<br>
>> >> windows worker.<br>
>> >><br>
>> >> Then, you need to use util.renderer.<br>
>> >><br>
>> >> def get_release_function(props):<br>
>> >>      return props.getProperty("branch"):<br>
>> >><br>
>> >> f.addStep(steps.ShellCommand(command=['ccm', 'baseline', '-list',<br>
>> >> util.renderer(get_release_function)]))<br>
>> >><br>
>> >> Not sure where you heard about extract_fn.<br>
>> >><br>
>> >> Regards<br>
>> >> Pierre<br>
>> >><br>
>> >> Le ven. 2 août 2019 à 00:26, honas grael <<a href="mailto:honasgraeymael@gmail.com" target="_blank">honasgraeymael@gmail.com</a>> a écrit :<br>
>> >> ><br>
>> >> > Hello, I am trying to get to grips with using Buildobt. I am using it with a rather quirky vcs (IBM CM Synergy), which has its own query syntax when you want to checkout code or list baselines.<br>
>> >> > To that end I am using ShellCommand. Something like this<br>
>> >> ><br>
>> >> > f.addStep(steps.ShellCommand(command=['ccm baseline -list local_release_x']))<br>
>> >> ><br>
>> >> ><br>
>> >> > This works and basically lists all the baselines in local_release_x.<br>
>> >> ><br>
>> >> > Notice that it is a single string.<br>
>> >> ><br>
>> >> > In the example above local_release_x is a hardcoded string value.<br>
>> >> ><br>
>> >> > I would like to make it dynamic i.e create a local_release_x property.<br>
>> >> ><br>
>> >> ><br>
>> >> > I think a custom function get_release_function() is what I am looking to implement, where the function returns a variable ('local_release_x')<br>
>> >> ><br>
>> >> >  that can be plugged into the shell command.<br>
>> >> ><br>
>> >> ><br>
>> >> > f.addStep(steps.ShellCommand(command=['ccm baseline -list extract_fn=get_release_function']))<br>
>> >> ><br>
>> >> ><br>
>> >> > Can anyone suggest how I can do this?<br>
>> >> ><br>
>> >> > I don't seem to understand how/if I can use command.extend or if I should/could be using interpolate/extract_fn<br>
>> >> ><br>
>> >> ><br>
>> >> > Please advise.<br>
>> >> ><br>
>> >> ><br>
>> >> > Regards<br>
>> >> ><br>
>> >> > _______________________________________________<br>
>> >> > users mailing list<br>
>> >> > <a href="mailto:users@buildbot.net" target="_blank">users@buildbot.net</a><br>
>> >> > <a href="https://lists.buildbot.net/mailman/listinfo/users" rel="noreferrer" target="_blank">https://lists.buildbot.net/mailman/listinfo/users</a><br>
</blockquote></div></div></div>