Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Update metadatacheck to fit v5.1 #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
92 changes: 89 additions & 3 deletions schlib/rules/S6_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Rule(KLCRule):
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Component fields contain the correct information')
super(Rule, self).__init__(component, 'Symbols contain the correct metadata and field values')

def checkVisibility(self, field):
return field['visibility'] == 'V'
Expand Down Expand Up @@ -93,12 +93,69 @@ def checkDatasheet(self):

# Datasheet field must be empty
if not self.checkEmpty(ds):
self.error("Datasheet field must be EMPTY")
self.error("Datasheet field (.lib file) must be EMPTY")
fail = True

return fail

def check(self):
def checkDocumentation(self, name, documentation, alias=False, isGraphicOrPowerSymbol=False):

errors = []
warnings = []

if not documentation:
errors.append("Missing all metadata information in the .dcm file (datasheet, keyword and description)")
elif (not documentation['description'] or
poeschlr marked this conversation as resolved.
Show resolved Hide resolved
not documentation['keywords'] or
not documentation['datasheet']):

if (not documentation['description']):
errors.append("Missing DESCRIPTION entry (in dcm file)")
if (not documentation['keywords']):
errors.append("Missing KEYWORDS entry (in dcm file)")
if (not isGraphicOrPowerSymbol) and (not documentation['datasheet']):
errors.append("Missing DATASHEET entry (in dcm file)")

if (documentation['description'] and
documentation['keywords']):
self.only_datasheet_missing = True

# Symbol name should not appear in the description
desc = documentation.get('description', '')
if desc and name.lower() in desc.lower():
warnings.append("Symbol name should not be included in description")

# Datasheet field should look like a a datasheet
ds = documentation.get('datasheet', '')

if ds and len(ds) > 2:
link = False
links = ['http', 'www', 'ftp']
if any([ds.startswith(i) for i in links]):
poeschlr marked this conversation as resolved.
Show resolved Hide resolved
link = True
elif ds.endswith('.pdf') or '.htm' in ds:
link = True

if not link:
warnings.append("Datasheet entry '{ds}' does not look like a URL".format(ds=ds))

if len(errors) > 0 or len(warnings) > 0:
msg = "{cmp} {name} has metadata errors:".format(
cmp="ALIAS" if alias else "Component",
name=name)
if len(errors) == 0:
self.warning(msg)
else:
self.error(msg)

for err in errors:
self.errorExtra(err)
for warn in warnings:
self.warningExtra(warn)

return len(errors) > 0

def check_lib_file(self):

# Check for required fields
n = len(self.component.fields)
Expand Down Expand Up @@ -134,6 +191,35 @@ def check(self):
extraFields
])

def check_dcm_file(self):
"""
Proceeds the checking of the rule.
The following variables will be accessible after checking:
* only_datasheet_missing
"""

self.only_datasheet_missing = False
invalid_documentation = 0

# check part itself
if self.checkDocumentation(self.component.name, self.component.documentation, False, self.component.isGraphicSymbol() or self.component.isPowerSymbol()):
invalid_documentation += 1

# check all its aliases too
if self.component.aliases:
invalid = []
for alias in self.component.aliases.keys():
if self.checkDocumentation(alias, self.component.aliases[alias], True, self.component.isGraphicSymbol() or self.component.isPowerSymbol()):
invalid_documentation += 1

return invalid_documentation > 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No real reason to keep a counter since the result ultimately goes to a Boolean. But I guess in the future it could be handy and it works now too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other scripts use counters


def check(self):
lib_result = self.check_lib_file()
dcm_result = self.check_dcm_file()

return lib_result or dcm_result

def fix(self):
"""
Proceeds the fixing of the rule, if possible.
Expand Down
97 changes: 0 additions & 97 deletions schlib/rules/S6_3.py

This file was deleted.

1 change: 0 additions & 1 deletion schlib/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"S5_2",

"S6_2",
"S6_3",

"S7_1",
"S7_2",
Expand Down