-
-
Save KevinMGranger/02b54c95e4022a38fa8ae9bf8bcede9d to your computer and use it in GitHub Desktop.
Parsing qpid-config exchanges outpu
This file contains 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
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