Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parse the ouput of the condor_status command
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