Skip to content

Commit 60b9448

Browse files
authored
WIP: vspec2markdown
Signed-off-by: GitHub <[email protected]>
1 parent c4af280 commit 60b9448

9 files changed

+444
-28
lines changed

.gitignore

+8-1
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,11 @@ fabric.properties
305305

306306
# End of https://www.toptal.com/developers/gitignore/api/hugo,node,macos,webstorm
307307

308-
scripts/
308+
scripts/
309+
310+
vss/output
311+
vss/vehicle_signal_specification
312+
vss/release
313+
vss/master
314+
vss/gh-pages
315+
vss/vss-tools

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Pre-Requisites:
2626

2727
Building the documentation (in devcontainer):
2828

29+
- Change to `vss/` and run `./build-vss-docs.sh` to generate the VSS reference documentation
2930
- Run hugo: `hugo server`
3031
- Open browser at [http://localhost:1313/](http://localhost:1313/)
3132

config.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
13
baseURL = "https://eclipse-leda.github.io/leda/"
24
title = "Eclipse Leda Documentation"
35

@@ -10,7 +12,7 @@ theme = ["docsy"]
1012
enableGitInfo = true
1113

1214
# Language settings
13-
contentDir = "content/en"
15+
# contentDir = "content/en"
1416
defaultContentLanguage = "en"
1517
defaultContentLanguageInSubdir = false
1618
# Useful when translating.
@@ -222,6 +224,9 @@ permalinkable = false
222224
[module.hugoVersion]
223225
extended = true
224226
min = "0.73.0"
227+
[[module.mounts]]
228+
source = 'content/en'
229+
target = 'content'
225230
[[module.mounts]]
226231
source = 'assets'
227232
target = 'assets'
@@ -240,4 +245,8 @@ min = "0.73.0"
240245
[[module.mounts]]
241246
source = 'static'
242247
target = 'static'
248+
[[module.mounts]]
249+
source = 'vss/output/Vehicle'
250+
lang = 'en'
251+
target = 'content/docs/vss'
243252

package-lock.json

+24-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"format": "prettier --write assets/scss/*"
55
},
66
"devDependencies": {
7-
"autoprefixer": "^10.4.13",
7+
"autoprefixer": "^10.4.14",
88
"hugo-extended": "^0.100.2",
99
"postcss": "^8.4.21",
1010
"postcss-cli": "^9.1.0",

vss/build-vss-docs.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# /********************************************************************************
3+
# * Copyright (c) 2023 Contributors to the Eclipse Foundation
4+
# *
5+
# * See the NOTICE file(s) distributed with this work for additional
6+
# * information regarding copyright ownership.
7+
# *
8+
# * This program and the accompanying materials are made available under the
9+
# * terms of the Apache License 2.0 which is available at
10+
# * https://www.apache.org/licenses/LICENSE-2.0
11+
# *
12+
# * SPDX-License-Identifier: Apache-2.0
13+
# ********************************************************************************/
14+
#
15+
# Setup:
16+
# sudo apt-get install python3.10
17+
# sudo apt-get update
18+
# sudo apt-get install pip
19+
# pip install vss-tools
20+
# git clone https://github.com/COVESA/vss-tools.git
21+
22+
# git clone --recurse-submodules https://github.com/COVESA/vehicle_signal_specification
23+
# pushd vehicle_signal_specification
24+
# git checkout --detach
25+
# git for-each-ref refs/remotes/origin --format='../%(refname:lstrip=3) %(refname:lstrip=3)'|grep -v ' HEAD$' |xargs -n 2 git worktree add
26+
# popd
27+
28+
./vspecjson2markdown.py -I release/3.1/spec -i VehicleSignalSpecification.vspec -u release/3.1/spec/units.yaml -o output
29+

vss/vspecjson2markdown.py

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env python3
2+
# /********************************************************************************
3+
# * Copyright (c) 2023 Contributors to the Eclipse Foundation
4+
# *
5+
# * See the NOTICE file(s) distributed with this work for additional
6+
# * information regarding copyright ownership.
7+
# *
8+
# * This program and the accompanying materials are made available under the
9+
# * terms of the Apache License 2.0 which is available at
10+
# * https://www.apache.org/licenses/LICENSE-2.0
11+
# *
12+
# * SPDX-License-Identifier: Apache-2.0
13+
# ********************************************************************************/
14+
#
15+
# https://pypi.org/project/json-stream/
16+
# Requires: pip install json-stream
17+
18+
import argparse
19+
import json
20+
import os
21+
import json_stream
22+
from enum import Enum
23+
from vspec.model.vsstree import VSSNode, Unit
24+
from vspec.model.constants import VSSTreeType
25+
from vspec.loggingconfig import initLogging
26+
from anytree import Node, RenderTree, AsciiStyle
27+
import logging
28+
import sys
29+
import vspec
30+
31+
from io import StringIO
32+
from mako.template import Template
33+
from mako.runtime import Context
34+
from mako.lookup import TemplateLookup
35+
36+
initLogging()
37+
38+
parser = argparse.ArgumentParser(
39+
prog='vspecjson2markdown.py',
40+
description='Convert VSS VSpec-JSON to Markdown pages',
41+
epilog='This utility is part of the Eclipse Leda project')
42+
43+
parser.add_argument('-I', '--include',
44+
action='append',
45+
type=str,
46+
default=[],
47+
required=True,
48+
help='The Vehicle Signal Specification include directory search list')
49+
50+
parser.add_argument('-i', '--input',
51+
required=True,
52+
help='The Vehicle Signal Specification .vspec file')
53+
54+
parser.add_argument('-u', '--units',
55+
action='append',
56+
metavar='unit_file',
57+
type=str,
58+
default=[],
59+
required=False,
60+
help='The Vehicle Signal Specification units.yaml file')
61+
62+
parser.add_argument('-o', '--output',
63+
required=True,
64+
help='The output directory where to store the generated Markdown files')
65+
66+
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
67+
68+
args = parser.parse_args()
69+
70+
print("Arguments:")
71+
print("Verbose: %s" % args.verbose)
72+
print("VSpec Include Directory: %s" % args.include)
73+
print("VSpec Input file: %s" % args.input)
74+
print("VSpec Units file: %s" % args.units)
75+
print("Output directory: %s" % args.output)
76+
77+
vspec_dir = os.path.dirname(os.path.realpath(args.input))
78+
print("VSpec Directory: %s" % vspec_dir)
79+
80+
vspec.load_units(args.input,args.units)
81+
82+
data_type_tree = None
83+
tree = vspec.load_tree(args.input, args.include, VSSTreeType.SIGNAL_TREE)
84+
vspec.check_type_usage(tree, VSSTreeType.SIGNAL_TREE, data_type_tree)
85+
vspec.expand_tree_instances(tree)
86+
vspec.clean_metadata(tree)
87+
vspec.verify_mandatory_attributes(tree, abort_on_unknown_attribute=True)
88+
89+
outputdir=os.path.realpath(args.output)
90+
print("Absolute output directory: %s" % outputdir)
91+
os.makedirs(args.output, mode=0o777, exist_ok=True)
92+
93+
def export_node(node : VSSNode):
94+
print("Exporting: %s" % node.qualified_name())
95+
96+
outfilename=node.qualified_name().replace(".",os.path.sep) + os.path.sep + "_index.md"
97+
outfilepath=os.path.join(outputdir, outfilename)
98+
os.makedirs(os.path.dirname(outfilepath), mode=0o777, exist_ok=True)
99+
100+
mytemplate = Template(filename='vss.mako.md')
101+
buf = StringIO()
102+
103+
unit=""
104+
if node.has_unit():
105+
unit = Unit.from_str(node.get_unit())
106+
ctx = Context(buf, node=node, unit=unit)
107+
108+
mytemplate.render_context(ctx)
109+
outfile = open(outfilepath, "w")
110+
outfile.write(buf.getvalue())
111+
112+
for child in node.children:
113+
export_node(child)
114+
115+
export_node(tree)
116+
117+
print("Done")

0 commit comments

Comments
 (0)