Skip to content

Instantly share code, notes, and snippets.

@lathiat
Created November 16, 2020 08:47
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 lathiat/3ba7468ec064b7207ab971b9c9c57852 to your computer and use it in GitHub Desktop.
Save lathiat/3ba7468ec064b7207ab971b9c9c57852 to your computer and use it in GitHub Desktop.
Split the output from 'juju-run' into multiple files and process the escaped string
#!/usr/bin/env python3
import os
import re
import pprint
import sys
import yaml
if len(sys.argv) <= 1:
print("Usage: juju-split FILE_NAME")
sys.exit(1)
output_dir = os.path.basename(sys.argv[1])+ "_split"
os.makedirs(output_dir, exist_ok=True)
with open(sys.argv[1], 'r') as my_file:
y = yaml.load(my_file)
for output in y:
machine_fn = re.sub(r'[^a-zA-Z0-9_.]', '-', output['UnitId']) + ".txt"
with open(os.path.join(output_dir, machine_fn), "w") as out_file:
out_file.write(output['Stdout'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment