C#: Add python script for generating YAML files containing data extensions.

This commit is contained in:
Michael Nebel
2022-10-11 15:49:30 +02:00
parent 4972839b69
commit e6a8019c2b
3 changed files with 170 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import json
import os
import shutil
import subprocess
# Shared strings.
summaryModelPredicate = "extSummaryModel"
sinkModelPredicate = "extSinkModel"
sourceModelPredicate = "extSourceModel"
addsToTemplate = """
- addsTo:
pack: {0}
extensible: {1}
data:
{2}
"""
def remove_dir(dirName):
if os.path.isdir(dirName):
shutil.rmtree(dirName)
print("Removed directory:", dirName)
def run_cmd(cmd, msg="Failed to run command"):
print('Running ' + ' '.join(cmd))
if subprocess.check_call(cmd):
print(msg)
exit(1)
def readData(workDir, bqrsFile):
generatedJson = os.path.join(workDir, "out.json")
print('Decoding BQRS to JSON.')
run_cmd(['codeql', 'bqrs', 'decode', bqrsFile, '--output', generatedJson, '--format=json'], "Failed to decode BQRS.")
with open(generatedJson) as f:
results = json.load(f)
try:
return results['#select']['tuples']
except KeyError:
print('Unexpected JSON output - no tuples found')
exit(1)