Matteo Scandolo | 60b640f | 2017-08-08 13:05:22 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 17 | from pyparsing import * |
| 18 | |
| 19 | class Parser: |
| 20 | test_pattern = "{{{" + SkipTo("}}}",include=True) |
| 21 | test_pattern.setParseAction(lambda x:{"test":x[1][0]}) |
| 22 | |
| 23 | test_pattern2 = "1" + SkipTo(LineEnd(),include=True) + SkipTo(LineEnd(),include=True) + "2" |
| 24 | test_pattern2.setParseAction(lambda x:{"test":x[1]}) |
| 25 | |
| 26 | ansible = "TASK [" + SkipTo(']',include=True) + SkipTo(LineEnd(),include=True) + oneOf('changed ok failed error unreachable') + ': ' + SkipTo(LineEnd(),include=True) |
| 27 | ansible.setParseAction(lambda x:{"task":x[1][0],"status":x[3],"subject": x[5][0],"ansible":1}) |
| 28 | |
| 29 | ansible2 = "TASK [" + SkipTo(']',include=True) + SkipTo(LineEnd(),include=True) + SkipTo(LineEnd(),include=True) + oneOf('changed ok failed error unreachable') + ': ' + SkipTo(LineEnd(),include=True) |
| 30 | ansible2.setParseAction(lambda x:{"task":x[1][0],"status":x[4],"subject": x[6][0],"ansible":1}) |
| 31 | |
| 32 | ansible3 = "TASK [" + SkipTo(']',include=True) + SkipTo(LineEnd(),include=True) + SkipTo(LineEnd(),include=True) + SkipTo(LineEnd(),include=True) + oneOf('changed ok failed error unreachable') + ': ' + SkipTo(LineEnd(),include=True) |
| 33 | ansible3.setParseAction(lambda x:{"task":x[1][0],"status":x[5],"subject": x[7][0],"ansible":1}) |
| 34 | |
| 35 | # Vagrant |
| 36 | vagrant_start = Literal("[") + SkipTo("]",include=True) + "Importing base box '" + SkipTo("'",include=True) + SkipTo(LineEnd(),include=True) |
| 37 | vagrant_start.setParseAction(lambda x:{"vm":x[1][0],"image":x[3][0],"vagrant":1,"global":"Booting VM"}) |
| 38 | |
| 39 | vagrant_start = Literal("[") + SkipTo("]",include=True) + "Machine booted and ready!" + SkipTo(LineEnd(), include=True) |
| 40 | vagrant_start.setParseAction(lambda x:{"vm":x[1][0], "vagrant":1, "global":"VM Booted up"}) |
| 41 | |
| 42 | gradle_start = "Downloading https://services.gradle.org" + SkipTo(LineEnd(), include=True) |
| 43 | gradle_start.setParseAction(lambda x:{"gradle":1, "global":"Gradle started"}) |
| 44 | |
| 45 | debian_preparing = "Preparing to unpack" + Word(printables) + SkipTo(LineEnd(), include=True) |
| 46 | debian_preparing.setParseAction(lambda x:{"debian":1, "package":x[1]}) |
| 47 | |