-
Notifications
You must be signed in to change notification settings - Fork 452
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
Scheduler: allow negation of regular expressions in plan class XML specs #4390
base: master
Are you sure you want to change the base?
Conversation
Plan class XML specs allow regular expressions for OS, CPU vendor, CPU model, project prefs, and host summary. If any of these starts with a '!', negate the match.
Codecov Report
@@ Coverage Diff @@
## master #4390 +/- ##
===========================================
- Coverage 7.89% 7.89% -0.01%
Complexity 793 793
===========================================
Files 277 277
Lines 35270 35276 +6
Branches 1180 1180
===========================================
Hits 2785 2785
- Misses 32380 32386 +6
Partials 105 105
|
Thanks! It's a good idea to centralize this in an own data type. However in debugging I occasionally found it pretty hard to spot the reason for a missed match when I have to dig through a large plan class spec file for the right regex. Would it be feasible to keep the original regex string as well and print it in the debug message? |
To negate a regex, you should use "negative lookaheads" (http://www.regular-expressions.info/lookaround.html, in particular "Regex Engine Internals" section); the way you implemented it isn't standard regex, e.g. The complication is that the negative match can be used anywhere in the regex, so a naive implementation cannot be used here - unless you deliberately choose to break regex compatibility. |
The initial ! is not standard regex. |
That's my point; shouldn't standard regex be supported? |
? standard regex is supported. And also this notation for negation. |
You are breaking compatibility with standard regex by introducing a special case for the first character being an exclamation mark. You can no longer use patterns that start with an exclamation mark. Since regexes do not necessarily start matching from the beginning of the string (e.g. |
Bernd requested this feature, with this syntax. I think it's fine. |
Actually Rytis requested "negative regex" in #4069. Einstein@Home also had a need for it (long time ago). At that time the POSIX regular expression library that is used here didn't support negation, or at least I wasn't aware of it. So I implemented this in a way that I found reasonably easy to remember and to implement, and offered that implementation in #4069 as an alternative. If, however, the the POSIX regular expression library does support negation (now), I don't think we need this feature implemented separately at all. Did I miss something (now)? |
AFAIK the POSIX interface doesn't support general negation. |
|
The closest to the spec would be using |
This might be a bit more effort to implement (checking for the closing parenthesis at the end and removing it for the regex comp), but should be worth it if it's really standard. Factoring out the regex handling in an own data type is a good idea anyway, and that way it has only to be done once. |
Plan class XML specs allow regular expressions for OS, CPU vendor,
CPU model, project prefs, and host summary.
If any of these starts with a '!', negate the match.
This generalizes #4069.