Ticket #2165 (closed enhancement: fixed)
Support ternary substitution in WithProperties
| Reported by: | jaredgrubb | Owned by: | jaredgrubb |
|---|---|---|---|
| Priority: | minor | Milestone: | 0.8.+ |
| Version: | 0.8.5 | Keywords: | sprint |
| Cc: |
Description
I think it would be nice to have support for "if (prop) then substitute X else substitute Y".
Python supports back-references in a regex, so I'm imagining that a possible syntax would be:
:? + delimiter + true_substitution + delimiter + false_substitution
For example:
- %(prop:?:sub_true:sub_false)s
- %(prop:?|sub_true|sub_false)s
- %(prop:?Asub_trueAsub_false)s
I'm not sure if ":?" would check the property based on existence (i.e. as ":+" does) or on true-ness (i.e. as ":~" does), or whether it would be nice to support both options?
Change History
comment:2 Changed 17 months ago by jaredgrubb
The regex comment was that this could easily be implemented in regex like the others since Python supports back-references.
As for the existence vs trueness distinction, one idea I had was to borrow "#" from printf's "alternate format" modifier. So:
- ":?" means if prop exists
- ":#?" means if prop is true
And then another idea is that you could add ":#+" as an alias for ":~"; I personally have trouble telling ~ and - apart in font.
The other alternative is to just add another character: ":?" vs ":!".
Any preferences?
I could do this; it's a pretty easy patch.
comment:3 Changed 17 months ago by dustin
I like the additional-character idea, including the alias. ~ and - are pretty difficult to distinguish, and I certainly don't remember which is which without looking it up!
comment:5 Changed 14 months ago by jaredgrubb
- Owner set to jaredgrubb
- Status changed from new to assigned
I have a patch ready for this.
comment:6 Changed 12 months ago by Jared Grubb
- Status changed from assigned to closed
- Resolution set to fixed
Fixes #2165: Add 'ternary' interpolation for WithProperties?
Changeset: d2bc38106ddfcc9e1aa0a892a5632d4d1fe2f417
comment:7 Changed 12 months ago by Dustin J. Mitchell
Merge branch 'ternary-interpolation' of git://github.com/jaredgrubb/buildbot
- 'ternary-interpolation' of git://github.com/jaredgrubb/buildbot: ternary-sub: add docs Fixes #2165: Add 'ternary' interpolation for WithProperties? Changeset: 5cf757d57f5bc1c42c197c29adb4099f899663e0
comment:8 Changed 8 months ago by Tom Prince
Revert "Fixes #2165: Add 'ternary' interpolation for WithProperties?"
This reverts commit d2bc38106ddfcc9e1aa0a892a5632d4d1fe2f417.
Changeset: a7fbe09d7d544692496f4bd91631f380e20927ce
comment:9 Changed 8 months ago by Tom Prince
Revert "Fixes #2165: Add 'ternary' interpolation for WithProperties?"
This reverts commit d2bc38106ddfcc9e1aa0a892a5632d4d1fe2f417.
Changeset: a7fbe09d7d544692496f4bd91631f380e20927ce
comment:10 Changed 8 months ago by Tom Prince
Revert "Fixes #2165: Add 'ternary' interpolation for WithProperties?"
This reverts commit d2bc38106ddfcc9e1aa0a892a5632d4d1fe2f417.
Changeset: a7fbe09d7d544692496f4bd91631f380e20927ce
![[Buildbot Logo]](/chrome/site/header-text-transparent.png)
I don't think Python's regex syntax is relevant, but this is a great idea. Probably different introductory characters should be used to make the distinction?
Will you be able to work on this?