-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sst-snippets.py script which creates source code snippets usefu…
…l for documentation.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ EXTRA_DIST = \ | |
VERSION.md | ||
|
||
include tests/Makefile.inc | ||
|
||
bin_SCRIPTS = scripts/sst-snippets.py |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
||
|