Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 1 | from pyparsing import * |
| 2 | |
| 3 | class Parser: |
| 4 | test_pattern = "{{{" + SkipTo("}}}",include=True) |
| 5 | test_pattern.setParseAction(lambda x:{"test":x[1][0]}) |
| 6 | |
| 7 | test_pattern2 = "1" + SkipTo(LineEnd(),include=True) + SkipTo(LineEnd(),include=True) + "2" |
| 8 | test_pattern2.setParseAction(lambda x:{"test":x[1]}) |
| 9 | |
| 10 | ansible = "TASK [" + SkipTo(']',include=True) + SkipTo(LineEnd(),include=True) + oneOf('changed ok failed error unreachable') + ': ' + SkipTo(LineEnd(),include=True) |
| 11 | ansible.setParseAction(lambda x:{"task":x[1][0],"status":x[3],"subject": x[5][0],"ansible":1}) |
| 12 | |
| 13 | ansible2 = "TASK [" + SkipTo(']',include=True) + SkipTo(LineEnd(),include=True) + SkipTo(LineEnd(),include=True) + oneOf('changed ok failed error unreachable') + ': ' + SkipTo(LineEnd(),include=True) |
| 14 | ansible2.setParseAction(lambda x:{"task":x[1][0],"status":x[4],"subject": x[6][0],"ansible":1}) |
| 15 | |
| 16 | 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) |
| 17 | ansible3.setParseAction(lambda x:{"task":x[1][0],"status":x[5],"subject": x[7][0],"ansible":1}) |
| 18 | |
| 19 | # Vagrant |
| 20 | vagrant_start = Literal("[") + SkipTo("]",include=True) + "Importing base box '" + SkipTo("'",include=True) + SkipTo(LineEnd(),include=True) |
| 21 | vagrant_start.setParseAction(lambda x:{"vm":x[1][0],"image":x[3][0],"vagrant":1,"global":"Booting VM"}) |
| 22 | |
| 23 | vagrant_start = Literal("[") + SkipTo("]",include=True) + "Machine booted and ready!" + SkipTo(LineEnd(), include=True) |
| 24 | vagrant_start.setParseAction(lambda x:{"vm":x[1][0], "vagrant":1, "global":"VM Booted up"}) |
| 25 | |
| 26 | gradle_start = "Downloading https://services.gradle.org" + SkipTo(LineEnd(), include=True) |
| 27 | gradle_start.setParseAction(lambda x:{"gradle":1, "global":"Gradle started"}) |
| 28 | |
| 29 | debian_preparing = "Preparing to unpack" + Word(printables) + SkipTo(LineEnd(), include=True) |
| 30 | debian_preparing.setParseAction(lambda x:{"debian":1, "package":x[1]}) |
| 31 | |