From 043540e91414e24fff609d60047132e6f15fd474 Mon Sep 17 00:00:00 2001 From: Joseph Kenny Date: Thu, 7 Mar 2024 11:18:06 -0800 Subject: [PATCH 1/2] Added sst-snippets.py script which creates source code snippets useful for documentation. --- Makefile.am | 2 ++ scripts/sst-snippets.py | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100755 scripts/sst-snippets.py diff --git a/Makefile.am b/Makefile.am index 5cb88eaea..babc636c8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,3 +31,5 @@ EXTRA_DIST = \ VERSION.md include tests/Makefile.inc + +bin_SCRIPTS = scripts/sst-snippets.py diff --git a/scripts/sst-snippets.py b/scripts/sst-snippets.py new file mode 100755 index 000000000..fafdf36c5 --- /dev/null +++ b/scripts/sst-snippets.py @@ -0,0 +1,64 @@ +#! /usr/bin/env python3 + +import os +import sys +import json + +if not os.path.exists("snippets"): + os.mkdir("snippets") + +srcpath = os.path.dirname(sys.argv[1]) + +configFile = open(sys.argv[1],'r') +config = json.load(configFile) + +for tag in config["snippets"]: + snip = config["snippets"][tag] + + # python or c++? + language = "c++" + try: + if snip["language"] == "python": + language = "python" + except: pass + + # a unique tag + scoped_tag = "SSTSnippet::" + tag + + # read the input file + infile = open( os.path.join(srcpath, snip["file"]), 'r') + lines = infile.readlines() + + # open the output file + outfile = open( "snippets/" + snip["file"].replace("/","-") + '-' + tag, 'w') + + snippeting = False + for line in lines: + if line.find(scoped_tag) != -1: + if line.find("start") != -1: + snippeting = True + elif line.find("pause") != -1: + snippeting = False + elif line.find("end") != -1: + break + + if line.find("highlight") != -1: + if (language == "python"): + outfile.write("#") + else: + outfile.write("//") + if line.find("highlight-start") != -1: + outfile.write("highlight-start") + elif line.find("highlight-stop") != -1: + outfile.write("highlight-stop") + else: + outfile.write("highlight-next-line\n") + elif snippeting and line.find("SSTSnippet::") == -1: + outfile.write(line) + + infile.close() + outfile.close() + +configFile.close() + + From 834bcd75ec987b5e2e9aca6c28e10b100ab093a2 Mon Sep 17 00:00:00 2001 From: Joseph Kenny Date: Thu, 7 Mar 2024 17:21:49 -0800 Subject: [PATCH 2/2] make dist fix --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index babc636c8..48033f035 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,4 +32,4 @@ EXTRA_DIST = \ include tests/Makefile.inc -bin_SCRIPTS = scripts/sst-snippets.py +dist_bin_SCRIPTS = scripts/sst-snippets.py