Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions samm2yaml2md/bin/make_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def reformatMultiParagraph2(l, indent):
m = re.sub("\n-", "\n{}-".format(" " * indent), l)
l = re.sub("\n\*", "\n{}*".format(" " * indent), m)
#pdb.set_trace()
m = re.sub(r"\n\n([A-Za-z].+)", r"\n\n{}\1".format(" " * indent), l)
m = re.sub(r"\n\n(?!\s)([\w].*)", r"\n\n{}\1".format(" " * indent), l, flags=re.UNICODE)
return m

"""
Expand Down Expand Up @@ -168,15 +168,30 @@ def get_short_filename(original_string):

new_name = sections[0] + '-' + ''.join(part[0] for part in sections[1:])
return new_name

def get_original_eng_practice_name_from_filename(filename):
# Get the base name of the file (without the directory path and extension)
basename = os.path.splitext(os.path.basename(filename))[0]

# Split the filename by the first hyphen
parts = basename.split('-', 1)

# If there was a hyphen, return the part after it, converted to lowercase
if len(parts) > 1:
result = parts[1].lower()
return result
else:
return filename

if __name__ == '__main__':
if len(sys.argv) != 3:
if len(sys.argv) != 3 and len(sys.argv) != 4:
print("Usage: %s <yaml.namespace> <template.markdown>" % sys.argv[0])
sys.exit(1)

logging.basicConfig(level = logging.INFO)
arg_ns = sys.argv[1]
arg_tmpl = sys.argv[2]
language = sys.argv[3] if len(sys.argv) > 3 else None
no_ns='NO_NS'

yamlData = {}
Expand Down Expand Up @@ -211,7 +226,32 @@ def get_short_filename(original_string):
basename = os.path.basename(file)
filename_without_extension = os.path.splitext(basename)[0]
yamlData[ns]["filename"] = filename_without_extension
yamlData[ns]["lowercaseFilename"] = filename_without_extension.lower()
'''
TODO
Previously the urls for the security practices and business functions were derived from the name. That worked until we had translations in other languages
because now strategy-and-metrics is going to be different in different languages. That way we will have multiple urls for each language.
I changed the logic to use the filenames which are always in English. However, the security practice filenames are different from the practice names.
Example - Requirements-driven Testing is in filename D-Requirements-Testing. Strategy and Metrics is in filename Strategy-Metrics, etc.
Using the practice filename as url is going to change and break existing links (url will be requirements-testing instead of requirements-driven-testing).
One of my suggestions is to change the filenames to be correct and derive the URL from there (see function get_original_eng_practice_name_from_filename).
Other possibility is using some config file from the website repository that will tell us which practice/function from what URL should be served
or hardcoding the urls here. Until we made a decision I am going to use the filenames as URL and hardcode those URLs of practices that have difference between the filename and practice name.
'''
practiceUrl = get_original_eng_practice_name_from_filename(file)
if ns == 'practice' or ns.startswith('practice_'):
practiceId = yamlData[ns]['id']
if practiceId == "32b3bdd85d3a4d53827960004f9d1c7e":
practiceUrl = "strategy-and-metrics"
if practiceId == "483a0a1b78264cafbc470ce72d557332":
practiceUrl = "education-and-guidance"
if practiceId == "66fb99798fe946e4979a2de98e9d6f8b":
practiceUrl = "requirements-driven-testing"
if practiceId == "be9e7ddb98b84abe8b9e185b979ccf60":
practiceUrl = "policy-and-compliance"
yamlData[ns]["originalPracticeEngName"] = practiceUrl
yamlData[ns]["shortFilename"] = get_short_filename(filename_without_extension)
yamlData[ns]["langPrefix"] = '' if language is None else f'/{language}'

except Exception as err:
logging.error("EE: failed to parse yaml file %s: %s" % (file, err))
Expand Down
16 changes: 10 additions & 6 deletions samm2yaml2md/bin/make_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(self, model):
def writeWebBusinessFunctions(self, namespaceBase):

for function in self.model.getBusinessFunctions(ordered=True):
_namespace = open("{}{}.ns".format(namespaceBase, function.getName()) , 'w')
functionName = function.getOriginalEngFileNameNoExt()
_namespace = open("{}{}.ns".format(namespaceBase, functionName) , 'w')
logging.debug("writing ns %s\n" % _namespace.name)

_namespace.write("function:%s\n" % function.getYamlFile())
Expand Down Expand Up @@ -72,8 +73,9 @@ def writeWebPractices(self, *, namespaceBase):
trace = False

for function in self.model.getBusinessFunctions(ordered=True):
functionName = function.getOriginalEngFileNameNoExt()
for practice in self.model.getPracticesBy(function=function):
_namespace = open("{}{}-{}.ns".format(namespaceBase, function.getName(), practice.getShortName()), 'w')
_namespace = open("{}{}-{}.ns".format(namespaceBase, functionName, practice.getShortName()), 'w')
logging.debug("writing ns {}\n".format(_namespace.name))

_namespace.write("function: %s\n" % function.getYamlFile())
Expand Down Expand Up @@ -101,10 +103,11 @@ def writeWebActivityStreams(self, *, namespaceBase):
trace = False

for function in self.model.getBusinessFunctions(ordered=True):
functionName = function.getOriginalEngFileNameNoExt()
for practice in self.model.getPracticesBy(function=function):
for stream in self.model.getStreamsBy(practice=practice):

_namespace = open("{}{}-{}-{}.ns".format(namespaceBase, function.getName(), practice.getShortName(), stream.getLetter()), 'w')
_namespace = open("{}{}-{}-{}.ns".format(namespaceBase, functionName, practice.getShortName(), stream.getLetter()), 'w')
logging.debug("writing ns {}\n".format(_namespace.name))

_namespace.write("function: {}\n".format(function.getYamlFile()))
Expand Down Expand Up @@ -428,6 +431,10 @@ def getData(self):

def getYamlFile(self):
return self.filename

def getOriginalEngFileNameNoExt(self):
basename = os.path.basename(self.filename)
return os.path.splitext(basename)[0]

class BusinessFunction(ModelObject):
@staticmethod
Expand Down Expand Up @@ -473,9 +480,6 @@ def getName(self):
class MaturityLevel(ModelObject):
@staticmethod
def itsme(obj):
"""
no easy way of identifying it. has 3 keys, id, number, description.
"""
try:
return obj['type'] == 'MaturityLevel'
except KeyError:
Expand Down
3 changes: 2 additions & 1 deletion samm2yaml2md/create_make_web_markdown_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test -z "$1" && echo "usage: $0 <web directory> <output_script>" && exit 1

pfx="$1"
outputsh="$2"
language="$3"

test -e "$pfx" || (echo "Invalid directory $pfx" && exit)
rm -f "$outputsh"
Expand All @@ -20,7 +21,7 @@ rm -f "$outputsh"
#
for f in "$pfx"/namespaces/*.ns; do
_f=$(basename $f)
echo "$makemarkdown" "$f" "$pfx"/templates/"$(cat "$pfx"/ns2template.mapping/"$_f")" ">" "$pfx"/markdown/"$(basename "$f" .ns)".md >> "$outputsh"
echo "$makemarkdown" "$f" "$pfx"/templates/"$(cat "$pfx"/ns2template.mapping/"$_f")" "$language" ">" "$pfx"/markdown/"$(basename "$f" .ns)".md >> "$outputsh"
done

chmod 755 "$outputsh"
Expand Down
9 changes: 6 additions & 3 deletions samm2yaml2md/make_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
# USAGE STATEMENT
function usage() {
cat << EOF
usage: $0 -d Datafiles_dir -o output_dir
usage: $0 -d Datafiles_dir -o output_dir -l language_short_code

EOF
}


while getopts "d:o:" OPTION; do
while getopts "d:o:l:" OPTION; do
case $OPTION in
d)
DATAFILES=$OPTARG
;;
o)
OUTPUT=$OPTARG
;;
l)
LANGUAGE=$OPTARG
;;
?)
echo "ERROR: Invalid Option $OPTION Provided!"
echo
Expand Down Expand Up @@ -60,7 +63,7 @@ $BASEDIR/bin/map_web_ns2template.sh $OUTPUT
echo creating ./run_make_markdown_script.sh
# generate the script that automates the calls to "make_markdown.py namespaces/foo.ns templates/generic.template"

$BASEDIR/create_make_web_markdown_script.sh $OUTPUT $BASEDIR/run_make_web_markdown_script.sh
$BASEDIR/create_make_web_markdown_script.sh $OUTPUT $BASEDIR/run_make_web_markdown_script.sh $LANGUAGE
test $? -ne 0 && echo "create_make_web_markdown_script.sh failed" && exit

echo runing ./run_make_web_markdown_script.sh
Expand Down
12 changes: 6 additions & 6 deletions samm2yaml2md/web/static.templates/activity.template
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: {{stream:name}}
type: stream
url: model/{{function:name}}/{{practice:name}}/stream-{{stream:letter}}/
url: ./model/{{function:lowercaseFilename}}/{{practice:originalPracticeEngName}}/stream-{{stream:letter}}/
business_function: {{function:name}}
business_function_url: {{function:name}}
business_function_url: {{function:lowercaseFilename}}
practice: {{practice:name}}
stream: {{stream:letter}}
description: {{function:name}} / {{practice:name}}
keywords: ["Business function", "Practice", "{{function:name}}", "{{practice:name}}"]
aliases:
- /model/{{stream:filename}}-{{maturity-1:number}}
- /model/{{stream:filename}}-{{maturity-2:number}}
- /model/{{stream:filename}}-{{maturity-3:number}}
- /model/{{stream:filename}}
- {{stream:langPrefix}}/model/{{stream:filename}}-{{maturity-1:number}}
- {{stream:langPrefix}}/model/{{stream:filename}}-{{maturity-2:number}}
- {{stream:langPrefix}}/model/{{stream:filename}}-{{maturity-3:number}}
- {{stream:langPrefix}}/model/{{stream:filename}}

maturity_levels:
level1:
Expand Down
8 changes: 4 additions & 4 deletions samm2yaml2md/web/static.templates/function.template
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: {{function:name}}
url: ./model/{{function:name}}/
url: ./model/{{function:lowercaseFilename}}/
description: {{function:name}} business function

practice_1: {{practice_1:name}}
practice_1_url: {{practice_1:name}}
practice_1_url: {{practice_1:originalPracticeEngName}}
practice_2: {{practice_2:name}}
practice_2_url: {{practice_2:name}}
practice_2_url: {{practice_2:originalPracticeEngName}}
practice_3: {{practice_3:name}}
practice_3_url: {{practice_3:name}}
practice_3_url: {{practice_3:originalPracticeEngName}}

keywords: ["Business function"]
---
Expand Down
6 changes: 3 additions & 3 deletions samm2yaml2md/web/static.templates/practice.template
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: {{practice:name}}
url: ./model/{{function:name}}/{{practice:name}}/
url: ./model/{{function:lowercaseFilename}}/{{practice:originalPracticeEngName}}/
business_function: "{{function:name}}"
business_function_url: "{{function:name}}"
business_function_url: "{{function:lowercaseFilename}}"
keywords: ["Business function", "Practice", "{{practice:name}}"]
aliases:
- /model/{{practice:shortFilename}}
- {{practice:langPrefix}}/model/{{practice:shortFilename}}
type: practice

practice_maturity_1_description: {{practiceLevel-1:objective}}
Expand Down