So people don't have to install python-unversioned-command on Fedora. It saves you 11 kB of disk space, worth it. :P
32 lines
1 KiB
Python
Executable file
32 lines
1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import argparse, sys, yaml
|
|
|
|
TEMPLATE_DIR="../../image-builder/templates/dashboards/grafana-dashboard-insights-image-builder-general.configmap.yml"
|
|
OUTPUT_DIR="config/grafana/dashboards/"
|
|
|
|
def load_config(config_filepath):
|
|
with open(config_filepath, "r") as stream:
|
|
try:
|
|
return yaml.safe_load(stream)['data']['grafana.json']
|
|
except yaml.YAMLError as e:
|
|
print("Error parsing configmap: {}\n".format(str(e)))
|
|
sys.exit(1)
|
|
|
|
def write_dashboard(dashboard, output_filepath):
|
|
with open(output_filepath, 'w') as f:
|
|
try:
|
|
f.write(dashboard)
|
|
f.close()
|
|
except Exception as e:
|
|
print("Error saving dashboard: {}\n".format(str(e)))
|
|
sys.exit(1)
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("-i", "--input", help="Path to the dashboard configmap", type=str)
|
|
parser.add_argument("-o", "--output", help="File path of the output", type=str)
|
|
args = parser.parse_args()
|
|
write_dashboard(load_config(args.input), args.output)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|