Skip to content

Instantly share code, notes, and snippets.

@KevinMGranger
Last active February 16, 2017 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KevinMGranger/02b54c95e4022a38fa8ae9bf8bcede9d to your computer and use it in GitHub Desktop.
Save KevinMGranger/02b54c95e4022a38fa8ae9bf8bcede9d to your computer and use it in GitHub Desktop.
Parsing qpid-config exchanges outpu
def parse_bindings(output):
ex = None
for line in filter(None, map(str.strip, output.split('\n'))):
if ex is not None:
binding = parse_binding(line)
if binding is None:
yield ex
else:
ex['bindings'].append(binding)
continue
ex = parse_exchange(line)
if ex is None:
raise Exception("Line was neither binding nor exchange: " + line)
def parse_exchange(line):
match = re.search(r"Exchange '(\S*)' \((\S+)\)", line)
if match is not None:
name, type_ = match.groups()
return dict(name=name, type=type_, bindings=[])
return None
def parse_binding(line):
match = re.search(r"bind \[([^\]]*)] => (\S+)", line)
if match is not None:
binding, queue = match.groups()
return dict(binding=binding, queue=queue)
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment