From 65609dc630cb49a6d5813aaf62b276a11c64881e Mon Sep 17 00:00:00 2001 From: samkay01 Date: Tue, 27 Sep 2022 12:01:01 -0500 Subject: [PATCH 1/9] comments.md added --- .gitignore | 1 + parser.py | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c31942f..37d86d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pdf /result.md test-*.log +/comments.md diff --git a/parser.py b/parser.py index dfe145c..a3e86bb 100755 --- a/parser.py +++ b/parser.py @@ -327,6 +327,8 @@ def matches_crit(test, crit): def apply_rules(cross_check, conf): # Prepare statistics counters stats = {} + comments = 0 + gen_comments('comments.md') for r in conf: stats[r['rule']] = 0 @@ -352,6 +354,18 @@ def apply_rules(cross_check, conf): 'Updated by': rule, }) + if 'comments' in r['update']: + comments += 1 + append_comments( + 'comments.md', + f"guid: {r['criteria']['guid']} \ + comment: {r['update']['comments']}\n" + ) + logging.info( + f"guid: {r['criteria']['guid']} \ + comment: {r['update']['comments']}" + ) + stats[rule] += 1 break @@ -367,6 +381,28 @@ def apply_rules(cross_check, conf): logging.info( f"Updated {n} {maybe_plural(n, 'test')} out of {s}" f" after applying {r} {maybe_plural(r, 'rule')}") + if comments: + logging.info( + f"{comments} {maybe_plural(comments, 'comment')}" + f" added to comments.md") + + +# Generate the md file for comments +def gen_comments(md): + # Create comments.md if it does not exist + logging.debug(f'Generate comments.md') + + if os.path.exists("comments.md"): + os.remove("comments.md") + + open('comments.md', 'w+') + + +# Append comments to the comments file +def append_comments(md, comment): + with open(md, 'a+') as resultfile: + logging.debug('Writing comment') + resultfile.write(comment) # Load YAML configuration file @@ -920,7 +956,7 @@ def meta_data(argv, here): } cp = subprocess.run( - f"git -C '{here}' describe --always --abbrev=12 --dirty", shell=True, + f"git -C {here} describe --always --abbrev=12 --dirty", shell=True, capture_output=True) logging.debug(cp) -- GitLab From 627ea8fb3bc2ae5de29c54e94301c909722572c6 Mon Sep 17 00:00:00 2001 From: samkay01 Date: Wed, 28 Sep 2022 11:23:27 -0500 Subject: [PATCH 2/9] comment only on --debug --- parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parser.py b/parser.py index a3e86bb..cca8c7e 100755 --- a/parser.py +++ b/parser.py @@ -361,7 +361,7 @@ def apply_rules(cross_check, conf): f"guid: {r['criteria']['guid']} \ comment: {r['update']['comments']}\n" ) - logging.info( + logging.debug( f"guid: {r['criteria']['guid']} \ comment: {r['update']['comments']}" ) @@ -386,7 +386,7 @@ def apply_rules(cross_check, conf): f"{comments} {maybe_plural(comments, 'comment')}" f" added to comments.md") - + # Generate the md file for comments def gen_comments(md): # Create comments.md if it does not exist @@ -394,7 +394,7 @@ def gen_comments(md): if os.path.exists("comments.md"): os.remove("comments.md") - + open('comments.md', 'w+') -- GitLab From 38c238abe15aa17363e353ba71fd98c59e7a6da9 Mon Sep 17 00:00:00 2001 From: samkay01 Date: Tue, 4 Oct 2022 12:54:46 -0500 Subject: [PATCH 3/9] Fixed linting errors --- parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser.py b/parser.py index cca8c7e..d4ef557 100755 --- a/parser.py +++ b/parser.py @@ -390,7 +390,7 @@ def apply_rules(cross_check, conf): # Generate the md file for comments def gen_comments(md): # Create comments.md if it does not exist - logging.debug(f'Generate comments.md') + logging.debug(f"Generate {md}") if os.path.exists("comments.md"): os.remove("comments.md") -- GitLab From 0e0f7284ed0c256e95eb239d7207b16f5d5f2c6d Mon Sep 17 00:00:00 2001 From: samkay01 Date: Tue, 11 Oct 2022 11:35:34 -0500 Subject: [PATCH 4/9] Missing quotes subprocess.run --- parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser.py b/parser.py index d4ef557..e686d69 100755 --- a/parser.py +++ b/parser.py @@ -956,7 +956,7 @@ def meta_data(argv, here): } cp = subprocess.run( - f"git -C {here} describe --always --abbrev=12 --dirty", shell=True, + f"git -C '{here}' describe --always --abbrev=12 --dirty", shell=True, capture_output=True) logging.debug(cp) -- GitLab From 7949647ee65a9938ee73a0bdc0e5212cb08a6229 Mon Sep 17 00:00:00 2001 From: samkay01 Date: Tue, 27 Sep 2022 12:01:01 -0500 Subject: [PATCH 5/9] comments.md added Missing quotes subprocess.run Fixed linting errors --- .gitignore | 1 + parser.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/.gitignore b/.gitignore index c31942f..37d86d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pdf /result.md test-*.log +/comments.md diff --git a/parser.py b/parser.py index dfe145c..9084c6a 100755 --- a/parser.py +++ b/parser.py @@ -327,6 +327,8 @@ def matches_crit(test, crit): def apply_rules(cross_check, conf): # Prepare statistics counters stats = {} + comments = 0 + gen_comments('comments.md') for r in conf: stats[r['rule']] = 0 @@ -352,6 +354,18 @@ def apply_rules(cross_check, conf): 'Updated by': rule, }) + if 'comments' in r['update']: + comments += 1 + append_comments( + 'comments.md', + f"guid: {r['criteria']['guid']} \ + comment: {r['update']['comments']}\n" + ) + logging.info( + f"guid: {r['criteria']['guid']} \ + comment: {r['update']['comments']}" + ) + stats[rule] += 1 break @@ -367,6 +381,28 @@ def apply_rules(cross_check, conf): logging.info( f"Updated {n} {maybe_plural(n, 'test')} out of {s}" f" after applying {r} {maybe_plural(r, 'rule')}") + if comments: + logging.info( + f"{comments} {maybe_plural(comments, 'comment')}" + f" added to comments.md") + + +# Generate the md file for comments +def gen_comments(md): + # Create comments.md if it does not exist + logging.debug(f"Generate {md}") + + if os.path.exists("comments.md"): + os.remove("comments.md") + + open('comments.md', 'w+') + + +# Append comments to the comments file +def append_comments(md, comment): + with open(md, 'a+') as resultfile: + logging.debug('Writing comment') + resultfile.write(comment) # Load YAML configuration file -- GitLab From eb0f1d6701b32190b79a5a67fed5fd881f49b3fa Mon Sep 17 00:00:00 2001 From: samkay01 Date: Wed, 28 Sep 2022 11:23:27 -0500 Subject: [PATCH 6/9] comment only on --debug --- parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parser.py b/parser.py index 9084c6a..e686d69 100755 --- a/parser.py +++ b/parser.py @@ -361,7 +361,7 @@ def apply_rules(cross_check, conf): f"guid: {r['criteria']['guid']} \ comment: {r['update']['comments']}\n" ) - logging.info( + logging.debug( f"guid: {r['criteria']['guid']} \ comment: {r['update']['comments']}" ) @@ -386,7 +386,7 @@ def apply_rules(cross_check, conf): f"{comments} {maybe_plural(comments, 'comment')}" f" added to comments.md") - + # Generate the md file for comments def gen_comments(md): # Create comments.md if it does not exist @@ -394,7 +394,7 @@ def gen_comments(md): if os.path.exists("comments.md"): os.remove("comments.md") - + open('comments.md', 'w+') -- GitLab From ab992a7341d113ed9ddf547c376102cd8c8af9c2 Mon Sep 17 00:00:00 2001 From: samkay01 Date: Fri, 13 Jan 2023 11:26:00 -0600 Subject: [PATCH 7/9] Added command line option to enable comments output Moved comment generation into a function separate from apply_rules --- README.md | 11 ++++++++ parser.py | 75 ++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2e483b7..0bd0624 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,18 @@ $ pandoc -oresult.html result.md See [Dependencies]. +### Comments + +For some rules, comments are included with common solutions to test failures or warnings. + +To generate `comments.md`, use the `--comments` option. + +``` {.sh} +$ ./parser.py --comments ... +``` + ### Custom search + For a custom Key:value search, the next two arguments *MUST be included together.* The program will search and display files that met that constraint, without the crosscheck, and display the names, guid, and key:value to the command line. `python3 parser.py ` you can use the `test_dict` below to see available keys. diff --git a/parser.py b/parser.py index e686d69..7848235 100755 --- a/parser.py +++ b/parser.py @@ -327,8 +327,6 @@ def matches_crit(test, crit): def apply_rules(cross_check, conf): # Prepare statistics counters stats = {} - comments = 0 - gen_comments('comments.md') for r in conf: stats[r['rule']] = 0 @@ -354,37 +352,72 @@ def apply_rules(cross_check, conf): 'Updated by': rule, }) + stats[rule] += 1 + break + + # Statistics + n = 0 + + for rule, cnt in stats.items(): + logging.debug(f"{cnt} matche(s) for rule `{rule}'") + n += cnt + + if n: + r = len(conf) + logging.info( + f"Updated {n} {maybe_plural(n, 'test')} out of {s}" + f" after applying {r} {maybe_plural(r, 'rule')}") + + +# Pull comments from the rules +def check_comments(cross_check, conf): + stats = {} + comments = 0 + md = 'comments.md' + + gen_comments(md) + + for r in conf: + stats[r['rule']] = 0 + + s = len(cross_check) + + for i in range(s): + test = cross_check[i] + + for r in conf: + if not matches_crit(test, r['criteria']): + continue + + rule = r['rule'] + if 'comments' in r['update']: comments += 1 append_comments( - 'comments.md', + md, f"guid: {r['criteria']['guid']} \ comment: {r['update']['comments']}\n" ) - logging.debug( - f"guid: {r['criteria']['guid']} \ - comment: {r['update']['comments']}" - ) + # Dont know if I need this part anymore + # since I'm printing after the summary anyways + # logging.debug( + # f"guid: {r['criteria']['guid']} \ + # comment: {r['update']['comments']}" + # ) stats[rule] += 1 break - # Statistics n = 0 for rule, cnt in stats.items(): - logging.debug(f"{cnt} matche(s) for rule `{rule}'") n += cnt if n: - r = len(conf) - logging.info( - f"Updated {n} {maybe_plural(n, 'test')} out of {s}" - f" after applying {r} {maybe_plural(r, 'rule')}") - if comments: + if comments and md: logging.info( f"{comments} {maybe_plural(comments, 'comment')}" - f" added to comments.md") + f" added to {md}") # Generate the md file for comments @@ -392,10 +425,10 @@ def gen_comments(md): # Create comments.md if it does not exist logging.debug(f"Generate {md}") - if os.path.exists("comments.md"): - os.remove("comments.md") + if os.path.exists(f"{md}"): + os.remove(f"{md}") - open('comments.md', 'w+') + open(f'{md}', 'w+') # Append comments to the comments file @@ -1010,6 +1043,8 @@ if __name__ == '__main__': parser.add_argument( '--seq-db', help='Known sequence files database filename', default=f'{here}/seq_db.yaml') + parser.add_argument( + '--comments', action='store_true', help='Output comments') parser.add_argument('log_file', nargs='?', help='Input .ekl filename') parser.add_argument('seq_file', nargs='?', help='Input .seq filename') parser.add_argument('find_key', nargs='?', help='Search key') @@ -1129,6 +1164,10 @@ if __name__ == '__main__': # Print a one-line summary print_summary(bins, res_keys) + # Check for and print comments + if args.comments: + check_comments(cross_check, conf) + # Print meta-data if args.print_meta: print() -- GitLab From 7fef2bec8f564573f083215f17a5afe2e80f9684 Mon Sep 17 00:00:00 2001 From: samkay01 Date: Fri, 27 Jan 2023 11:02:59 -0600 Subject: [PATCH 8/9] Sample comment added for make check tests --- parser.py | 19 +++++++++++-------- sample/sample.yaml | 1 + schemas/template-schema.yaml | 2 +- tests/test-parser | 3 +++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/parser.py b/parser.py index 7848235..4e8e678 100755 --- a/parser.py +++ b/parser.py @@ -327,6 +327,7 @@ def matches_crit(test, crit): def apply_rules(cross_check, conf): # Prepare statistics counters stats = {} + comments = 0 for r in conf: stats[r['rule']] = 0 @@ -343,6 +344,9 @@ def apply_rules(cross_check, conf): rule = r['rule'] + if 'comments' in r['update']: + comments += 1 + logging.debug( f"Applying rule `{rule}'" f" to test {i} `{test['name']}'") @@ -368,6 +372,11 @@ def apply_rules(cross_check, conf): f"Updated {n} {maybe_plural(n, 'test')} out of {s}" f" after applying {r} {maybe_plural(r, 'rule')}") + if comments and not args.comments: + logging.info( + f"{comments} comments present, use '--comments'" + f" to output them to file.") + # Pull comments from the rules def check_comments(cross_check, conf): @@ -397,13 +406,7 @@ def check_comments(cross_check, conf): md, f"guid: {r['criteria']['guid']} \ comment: {r['update']['comments']}\n" - ) - # Dont know if I need this part anymore - # since I'm printing after the summary anyways - # logging.debug( - # f"guid: {r['criteria']['guid']} \ - # comment: {r['update']['comments']}" - # ) + ) stats[rule] += 1 break @@ -417,7 +420,7 @@ def check_comments(cross_check, conf): if comments and md: logging.info( f"{comments} {maybe_plural(comments, 'comment')}" - f" added to {md}") + f" added to {md}, please have a look.") # Generate the md file for comments diff --git a/sample/sample.yaml b/sample/sample.yaml index ceacfb5..2ef6c2f 100644 --- a/sample/sample.yaml +++ b/sample/sample.yaml @@ -22,4 +22,5 @@ sub set: PlatformSpecificElements test set: EFICompliantTest update: + comments: Sample comment result: IGNORED diff --git a/schemas/template-schema.yaml b/schemas/template-schema.yaml index b19728f..281b3a0 100644 --- a/schemas/template-schema.yaml +++ b/schemas/template-schema.yaml @@ -321,7 +321,7 @@ items: - const: '' Updated by: type: string - additionalProperties: false + additionalProperties: true minProperties: 1 update: type: object diff --git a/tests/test-parser b/tests/test-parser index 2ed50f6..ed6c5f2 100755 --- a/tests/test-parser +++ b/tests/test-parser @@ -71,6 +71,9 @@ md="$tmp/out.md" parser.py "${args[@]}" --md "$md" |& tee "$out" grep -q '# SCT Summary' "$md" +echo -n 'comments, '>&3 +parser.py "${args[@]}" --comments |& tee "$out" + echo -n 'yaml, ' >&3 yaml="$tmp/out.yaml" parser.py "${args[@]}" --yaml "$yaml" |& tee "$out" -- GitLab From 523127eea0093e043000d38356ba92bfeb7fec18 Mon Sep 17 00:00:00 2001 From: samkay01 Date: Fri, 27 Jan 2023 11:22:56 -0600 Subject: [PATCH 9/9] More proper implementation of sample comment in sample.yaml --- sample/sample.yaml | 17 ++++++++++++++++- tests/test-parser | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sample/sample.yaml b/sample/sample.yaml index 2ef6c2f..808ff39 100644 --- a/sample/sample.yaml +++ b/sample/sample.yaml @@ -22,5 +22,20 @@ sub set: PlatformSpecificElements test set: EFICompliantTest update: - comments: Sample comment result: IGNORED + +- rule: A sample rule to force a comment + criteria: + descr: UEFI Compliant Test + device path: No device path + group: GenericTest + guid: B27660E2-0E87-4794-82F1-E6BDBD8B7442 + log: EfiCompliantBBTestPlatform_uefi.c + name: UEFI Compliant - IPsec protocols must be implemented + result: WARNING + revision: '0x00010001' + set guid: A0A8BED3-3D6F-4AD8-907A-84D52EE1543B + sub set: PlatformSpecificElements + test set: EFICompliantTest + update: + comments: Sample Comment diff --git a/tests/test-parser b/tests/test-parser index ed6c5f2..d005d18 100755 --- a/tests/test-parser +++ b/tests/test-parser @@ -33,7 +33,7 @@ out="$tmp/out" args=(--config sample/sample.yaml sample/sample.ekl sample/sample.seq) parser.py "${args[@]}" |& tee "$out" grep -q 'Identified.* as "Test sample' "$out" -grep -q 'Updated 1 test.* after applying 1 rule' "$out" +grep -q 'Updated 2 test.* after applying 2 rule' "$out" grep -q 'Meta-data' result.md echo -n 'null config, ' >&3 -- GitLab