Created
November 16, 2020 08:47
-
-
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
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
#!/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