Last active
November 14, 2016 07:35
-
-
Save bryanwb/4e405d7b70152d4c01a1bbe02f24d211 to your computer and use it in GitHub Desktop.
parse the ouput of the condor_status command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fn.monad import Option | |
from toolz.itertoolz import get | |
example1 = '''Name OpSys Arch State Activity LoadAv Mem ActvtyTime | |
gce-xxxxx LINUX X86_64 Unclaimed Idle 0.010 3700 0+00:00:02 | |
gce-xxxx LINUX X86_64 Unclaimed Idle 0.000 3700 0+00:00:02 | |
Total Owner Claimed Unclaimed Matched Preempting Backfill | |
X86_64/LINUX 2 0 0 2 0 0 0 | |
Total 2 0 0 2 0 0 0''' | |
def parse_int_from_stdout(output): | |
return Option(output)\ | |
.filter(lambda s: s.strip() != '')\ | |
.map(lambda s: s.split('\n'))\ | |
.map(lambda lines: get(-1, lines, None))\ | |
.map(lambda s: get(1, s.split(), None))\ | |
.map(lambda s: int(s))\ | |
.get_or(0) | |
def test_examples(): | |
''' | |
These examples parse an example string for the integer value of Total | |
If Total is not present, 0 is returned | |
''' | |
assert parse_int_from_stdout(example1) == 2 | |
assert parse_int_from_stdout('\n') == 0 | |
assert parse_int_from_stdout('') == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment