From a7ef625d48ce4630f4cd3c5f4f30f2fbd490eae2 Mon Sep 17 00:00:00 2001 From: "Jacob E. F. Overgaard" Date: Sat, 7 Mar 2020 22:02:47 +0100 Subject: [PATCH 1/3] Import python regular expressions. This way of finding illegal keyword separators within symbols need python regular expressions. --- schlib/rules/rule.py | 1 + 1 file changed, 1 insertion(+) diff --git a/schlib/rules/rule.py b/schlib/rules/rule.py index ad1d12c3..307e3564 100644 --- a/schlib/rules/rule.py +++ b/schlib/rules/rule.py @@ -2,6 +2,7 @@ import sys import os +import re common = os.path.abspath(os.path.join(sys.path[0], '..', 'common')) From 6894c6c89e8e8e006fb47d14e6456b82a62b58d7 Mon Sep 17 00:00:00 2001 From: "Jacob E. F. Overgaard" Date: Sat, 7 Mar 2020 22:04:04 +0100 Subject: [PATCH 2/3] Add naive approach to finding illegal keyword separators within symbols. A simple approach in finding illegal keyword separators is implemented. It current filters keyword separation based on a regular expression, looking for the following symbols: ,.:;?!<> Maybe a different approach is better, and more symbols may be interesting to filter with. --- schlib/rules/S6_3.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/schlib/rules/S6_3.py b/schlib/rules/S6_3.py index 995f4688..4e6a6b3f 100644 --- a/schlib/rules/S6_3.py +++ b/schlib/rules/S6_3.py @@ -74,6 +74,14 @@ def checkDocumentation(self, name, documentation, alias=False, isGraphicOrPowerS if not link: warnings.append("Datasheet entry '{ds}' does not look like a URL".format(ds=ds)) + # Handle keyword seperator. Right now it filters based on a regular + # expression based on certain symbols. Right now hyphen (-) is still allowed. + keywords = documentation.get('keywords', '') + forbidden_matches = re.findall('[,.:;?!<>]', keywords) + if forbidden_matches: + errors.append("Symbol keywords contain forbidden symbols: {}".format(forbidden_matches)) + + if len(errors) > 0 or len(warnings) > 0: msg = "{cmp} {name} has metadata errors:".format( cmp="ALIAS" if alias else "Component", From bf711aaadf57998b350d84ce02a4763c2aa68756 Mon Sep 17 00:00:00 2001 From: "Jacob E. F. Overgaard" Date: Sat, 7 Mar 2020 22:11:37 +0100 Subject: [PATCH 3/3] Handle empty keywords with a try/except. Some symbols appeared to have no "K" entry within its .dcm file, and thus assigning the variable "keywords" threw an error. Solved this with a try/except and append a warning message to the -vv logger. --- schlib/rules/S6_3.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/schlib/rules/S6_3.py b/schlib/rules/S6_3.py index 4e6a6b3f..db52bb1e 100644 --- a/schlib/rules/S6_3.py +++ b/schlib/rules/S6_3.py @@ -76,10 +76,13 @@ def checkDocumentation(self, name, documentation, alias=False, isGraphicOrPowerS # Handle keyword seperator. Right now it filters based on a regular # expression based on certain symbols. Right now hyphen (-) is still allowed. - keywords = documentation.get('keywords', '') - forbidden_matches = re.findall('[,.:;?!<>]', keywords) - if forbidden_matches: - errors.append("Symbol keywords contain forbidden symbols: {}".format(forbidden_matches)) + try: + keywords = documentation.get('keywords', '') + forbidden_matches = re.findall('[,.:;?!<>]', keywords) + if forbidden_matches: + errors.append("Symbol keywords contain forbidden symbols: {}".format(forbidden_matches)) + except: + warnings.append("Symbol appears to not have any keywords.") if len(errors) > 0 or len(warnings) > 0: