Yes, that is correct. Pierre
Le sam. 3 août 2019 à 17:36, honas grael <honasgraeym...@gmail.com> a écrit : > > Awesome, thanks! I'll give that a go. but perfect. > that syntax return props.getProperty("baselines")[2] I would not have > guessed. I was thinking baselines[2], > but thanks for putting me right. > 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 > would be return props.getProperty("baselines")['my_custom_key'] > Is that correct > > Many thanks already. Will give this a try shortly. > > Regards > On Sat, Aug 3, 2019 at 1:12 PM Pierre Tardy <tar...@gmail.com> wrote: >> >> You need to use SetPropertyFromCommand if you want to parse output of a >> command. >> >> def glob2list(rc, stdout, stderr): >> baselines = [l.strip() for l in stdout.split('\n')] >> return {'baselines': baselines} # this sets property 'baselines' >> to the splitted list of baselines >> >> f.addStep(steps.SetPropertyFromCommand(command=['ccm', 'baseline', >> '-list'], extract_fn=get_release_function'])) >> >> @util.renderer >> def get_third_baseline(props): >> return props.getProperty("baselines")[2] >> >> # get_third_baseline will be invoked at build runtime, and at that >> time the props variables will be known, so that we can get the third >> element of the baselines list >> f.addStep(steps.ShellCommand(command=['ccm', 'baseline', '-checkout', >> get_third_baseline])) >> >> Pierre >> >> Le ven. 2 août 2019 à 22:35, honas grael <honasgraeym...@gmail.com> a écrit : >> > >> > umm yes, basically in my case (please feel free to suggest something >> > better) I have >> > >> > def get_release_function(rc, stdout, sterr) >> > .... release_list = [l.strip() for l in stdout.split('\n')] >> > >> > return {'list_of_releases': release_list} >> > >> > >> > f.addStep(steps.ShellCommand(command=['ccm baseline -list >> > extract_fn=get_release_function'])) >> > >> > 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) >> > >> > 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. >> > >> > that is at the heart of what I am trying (i.e set a property, then later >> > on retrieve elements of that property) >> > >> > On Fri, Aug 2, 2019 at 9:24 PM Pierre Tardy <tar...@gmail.com> wrote: >> >> >> >> Ok, so this is only a parameter of SetPropertyFromCommand, not a >> >> generic parameter for all steps. >> >> >> >> Pierre >> >> >> >> Le ven. 2 août 2019 à 22:23, honas grael <honasgraeym...@gmail.com> a >> >> écrit : >> >> > >> >> > Thank you Pierre, >> >> > >> >> > 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. >> >> > But probably best once I have tried a few things and then I can give a >> >> > better answer >> >> > >> >> > extract_fn is in the documentation >> >> > http://docs.buildbot.net/current/manual/configuration/buildsteps.html?highlight=extract_fn >> >> > >> >> > ... 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. >> >> > >> >> > Note that passing in extract_fn will set includeStderr to True. >> >> > >> >> > def glob2list(rc, stdout, stderr): >> >> > jpgs = [l.strip() for l in stdout.split('\n')] >> >> > return {'jpgs': jpgs} >> >> > >> >> > f.addStep(SetPropertyFromCommand(command="ls -1 *.jpg", >> >> > extract_fn=glob2list)) >> >> > >> >> > >> >> > >> >> > >> >> > 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 >> >> > >> >> > But thank you for responding >> >> > >> >> > On Fri, Aug 2, 2019 at 7:36 PM Pierre Tardy <tar...@gmail.com> wrote: >> >> >> >> >> >> Hi, >> >> >> >> >> >> I you want to use list based version of ShellCommand, you need to use >> >> >> one word per string. >> >> >> Your version probably worked, because of implementation details of the >> >> >> windows worker. >> >> >> >> >> >> Then, you need to use util.renderer. >> >> >> >> >> >> def get_release_function(props): >> >> >> return props.getProperty("branch"): >> >> >> >> >> >> f.addStep(steps.ShellCommand(command=['ccm', 'baseline', '-list', >> >> >> util.renderer(get_release_function)])) >> >> >> >> >> >> Not sure where you heard about extract_fn. >> >> >> >> >> >> Regards >> >> >> Pierre >> >> >> >> >> >> Le ven. 2 août 2019 à 00:26, honas grael <honasgraeym...@gmail.com> a >> >> >> écrit : >> >> >> > >> >> >> > 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. >> >> >> > To that end I am using ShellCommand. Something like this >> >> >> > >> >> >> > f.addStep(steps.ShellCommand(command=['ccm baseline -list >> >> >> > local_release_x'])) >> >> >> > >> >> >> > >> >> >> > This works and basically lists all the baselines in local_release_x. >> >> >> > >> >> >> > Notice that it is a single string. >> >> >> > >> >> >> > In the example above local_release_x is a hardcoded string value. >> >> >> > >> >> >> > I would like to make it dynamic i.e create a local_release_x >> >> >> > property. >> >> >> > >> >> >> > >> >> >> > I think a custom function get_release_function() is what I am >> >> >> > looking to implement, where the function returns a variable >> >> >> > ('local_release_x') >> >> >> > >> >> >> > that can be plugged into the shell command. >> >> >> > >> >> >> > >> >> >> > f.addStep(steps.ShellCommand(command=['ccm baseline -list >> >> >> > extract_fn=get_release_function'])) >> >> >> > >> >> >> > >> >> >> > Can anyone suggest how I can do this? >> >> >> > >> >> >> > I don't seem to understand how/if I can use command.extend or if I >> >> >> > should/could be using interpolate/extract_fn >> >> >> > >> >> >> > >> >> >> > Please advise. >> >> >> > >> >> >> > >> >> >> > Regards >> >> >> > >> >> >> > _______________________________________________ >> >> >> > users mailing list >> >> >> > users@buildbot.net >> >> >> > https://lists.buildbot.net/mailman/listinfo/users _______________________________________________ users mailing list users@buildbot.net https://lists.buildbot.net/mailman/listinfo/users