-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically generate category constants for Java and schema validation #416
Merged
Merged
Changes from 43 commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
62c59c4
Add gencode Category
grafnu 3bcab40
category.json
grafnu 617e733
Basic validation of categories
grafnu cec5107
Cleanup gencode
grafnu 560470c
Initial gencode files
grafnu 9564141
Basic category handling
grafnu 5df1e7a
Merge branch 'master' into categories
grafnu 76f8ad1
Basic schema catagory generator
grafnu 9b6994e
One round of cleanup
grafnu fb24f33
Fix category generation
grafnu b8269f8
Fixing discovery events
grafnu a9bfe86
Merge remote-tracking branch 'faucet/master' into categories
grafnu 5acb4a7
Fixing blobset and others
grafnu 5eeeb6a
Fixing blob and bacnet
grafnu 8a915a5
Fixing discovery
grafnu df8f353
Add java gencode
grafnu 416a350
Working gencode java
grafnu edc473c
Fixing gencode
grafnu 0ee5ebe
Fix gencode docs
grafnu 5893005
Fix gencode levels
grafnu c23feba
Fixing hash
grafnu b17c0a5
Fix error count
grafnu a68b850
Fix simple trace test
grafnu 467a519
Make sequencer verbose
grafnu 8ad7c64
FIxing some pubber logging
grafnu 51d0aec
Linty
grafnu 4d6ed16
Cleanup logging and broken sequence
grafnu 2f665dc
Linty
grafnu 96c9717
Update line indexing
grafnu 8fc6a2d
Adding testing junk
grafnu 5fa2cd5
Linty
grafnu f46dd23
Fix name type
grafnu 201f01a
Augment logging
grafnu b2b3fd6
Syntax
grafnu 5bdb6e4
Don't tag null
grafnu a24430c
Method ordering
grafnu ab1705a
Fix tagging for config updates
grafnu dfabc92
Augment pubber logging
grafnu ea2cf19
Adjust test out
grafnu 8f5e070
Some logging cleanup
grafnu 00748a9
Augment sequencer logging
grafnu b3c07bd
Pubber log detail
grafnu 194e12e
Verbose sequencing
grafnu 79267b2
Validating debug
grafnu 82d4b62
Streamline categories
grafnu 047195a
Better stack-trace representation
grafnu cf82509
Removing rogue file
grafnu ec612ca
Tag reset_config for sequence name
grafnu dec85bc
Making testing part of system block to avoid reset configuration errors
grafnu f6814bc
reset debug
grafnu dde53e3
Clean reset
grafnu 0f91a40
Add config/state update counts
grafnu 92538bd
Cleaning break_config
grafnu b5bfc8c
broken_config logic
grafnu 2502e4d
Local prefix logging
grafnu 2251bf7
Fix reset_config
grafnu 43fc5de
Add long timeout to broken_config test
grafnu bb10d87
Test timing
grafnu 5edd12e
Cleanup loglevel checks
grafnu 8b6c9ad
Fix typo
grafnu a3ee0bd
Fix style
grafnu a5a9b92
Make test public
grafnu 4b9a1e1
Add update
grafnu 6c57fa6
Adding expectations
grafnu 81e02f8
Import cleanup
grafnu 26ba640
Add sequencer test run debug
grafnu 17772c6
Diagnostics
grafnu 6efafd9
Add sequence name to reset configs
grafnu d961dc4
Adding some wiggleroom
grafnu 2f5e0d8
Adding system event
grafnu fb1a4a4
Add delay debug
grafnu f499804
Fix syntax
grafnu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -128,4 +128,4 @@ jobs: | |
if: ${{ always() }} | ||
run: | | ||
cat pubber.out || true | ||
more out/*.json | ||
more pubber/out/*.json |
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,96 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import hashlib | ||
import json | ||
import re | ||
import os | ||
import shutil | ||
import sys | ||
|
||
GENCODE_MARKER = '@@ ' | ||
CATEGORY_MARKER = '* ' | ||
CATEGORY_REGEX = ' *\\* _([a-z]+)_: (\(\*\*([A-Z]+)\*\*\) )?(.*)' | ||
JSON_FORMAT = '%s%s{ "pattern": "^%s$" }' | ||
|
||
JAVA_DESCRIPTION = "\n%s// %s\n" | ||
JAVA_TARGET = '%spublic static final String %s = "%s";\n' | ||
JAVA_LEVEL = '%spublic static final Level %s_LEVEL = %s;\n' | ||
JAVA_MAP_ADD = '%sstatic { LEVEL.put(%s, %s); }\n' | ||
|
||
doc_in = os.path.join('docs/specs/categories.md') | ||
schema_in = os.path.join('etc/category.json') | ||
schema_out = os.path.join('schema/category.json') | ||
java_in = os.path.join('etc/Category.java') | ||
java_out = os.path.join('gencode/java/udmi/schema/Category.java') | ||
|
||
def read_categories(): | ||
categories = [] | ||
prefix = [] | ||
previous = -1 | ||
group = None | ||
with open(doc_in) as doc: | ||
while line := doc.readline(): | ||
indent = line.find(CATEGORY_MARKER)//2 | ||
match = re.match(CATEGORY_REGEX, line) | ||
if indent < 0 or not match: | ||
continue | ||
if indent < previous: | ||
for _ in range(indent, previous): | ||
rem = prefix.pop(len(prefix) - 1) | ||
elif indent > previous: | ||
if group: | ||
prefix.append(group) | ||
previous = indent | ||
group = match.group(1) | ||
category = '.'.join(prefix + [group]) | ||
level = match.group(3) | ||
description = match.group(4) | ||
if level: | ||
entry = (category, level, description) | ||
categories.append(entry) | ||
return categories | ||
|
||
def write_schema_out(categories): | ||
with open(schema_in) as inp: | ||
with open(schema_out, 'w') as out: | ||
while line := inp.readline(): | ||
index = line.find(GENCODE_MARKER) | ||
if index > 0: | ||
write_schema_categories(out, line[0:index], categories) | ||
else: | ||
out.write(line) | ||
|
||
def write_schema_categories(out, indent, categories): | ||
prefix = '' | ||
for category in categories: | ||
target = category[0].replace('.', '\\\\.') | ||
out.write(JSON_FORMAT % (prefix, indent, target)) | ||
prefix = ',\n' | ||
out.write('\n') | ||
|
||
def write_java_out(categories): | ||
os.makedirs(os.path.dirname(java_out), exist_ok=True) | ||
with open(java_in) as inp: | ||
with open(java_out, 'w') as out: | ||
while line := inp.readline(): | ||
if line.strip().startswith(GENCODE_MARKER): | ||
indent = line[0:line.find(GENCODE_MARKER)] | ||
write_java_categories(out, indent, categories) | ||
else: | ||
out.write(line) | ||
|
||
def write_java_categories(out, indent, categories): | ||
for category in categories: | ||
target = category[0] | ||
level = category[1] | ||
desc = category[2] | ||
const = target.replace('.', '_').upper() | ||
out.write(JAVA_DESCRIPTION % (indent, desc)) | ||
out.write(JAVA_TARGET % (indent, const, target)) | ||
out.write(JAVA_LEVEL % (indent, const, level)) | ||
out.write(JAVA_MAP_ADD % (indent, const, level)) | ||
|
||
|
||
categories = read_categories() | ||
write_schema_out(categories) | ||
write_java_out(categories) |
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
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
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
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
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
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
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,18 @@ | ||
package udmi.schema; | ||
|
||
import static udmi.schema.Level.DEBUG; | ||
import static udmi.schema.Level.INFO; | ||
import static udmi.schema.Level.NOTICE; | ||
import static udmi.schema.Level.WARNING; | ||
import static udmi.schema.Level.ERROR; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
// This class is manually curated, auto-generated, and then copied into the gencode directory. | ||
// Look for the proper source and don't be fooled! Ultimately sourced from docs/specs/categories.md | ||
public class Category { | ||
public static final Map<String, Level> LEVEL = new HashMap(); | ||
|
||
@@ gencode stuff goes here | ||
} |
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,6 @@ | ||
{ | ||
"$comment": "Auto-generated category mappings from bin/gencode_categories.", | ||
"oneOf": [ | ||
@@ gencode stuff goes here | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here to? re: find() change