Skip to content
Snippets Groups Projects
Commit a3f83482 authored by Krisjanis Rijnieks's avatar Krisjanis Rijnieks :lion_face:
Browse files

Add test, check if footprint is mapped to a symbol in lib

parent 88dcb054
No related branches found
No related tags found
No related merge requests found
# Contributing
Please follow the [KiCad Library Convention](https://kicad-pcb.org/libraries/klc/) before contributing.
Please follow the [KiCad Library Convention](https://kicad-pcb.org/libraries/klc/) before contributing.
TODO: Use official [KiCad Library Utilities](https://github.com/kicad/kicad-library-utils) to check and fix libraries.
......@@ -10,13 +10,14 @@ Take a look at the [KiCad File Format DEF](https://en.wikibooks.org/wiki/Kicad/f
- Leave passive components not filled.
- Adjust the footprints so that they are easy to hand-solder.
> Run `test.py` before pushing changes to reposotory.
> Run `test.py` before pushing changes to reposotory.
It will check if everything is right. It will help you fix errors if any. The script is run automatically when push to the repository happens. However it is best to do it before pushing locally. The following is a list of what the script does.
- [x] Match symbol DEF name with its F1 name
- [x] Check if the footprint entry has a library field (fab:Part_Name)
- [x] Check if the footprint fab.pretty/footprint.kicad_mod file exists
- [x] Check if footprint is mapped to a symbol in the library
- [ ] Check if the footprint file name matches the name in the file
- [ ] Check if footprints are visible also on layers F.Cu F.Paste F.Mask
- [ ] Check naming structure PartName_SizeXYZmm_Pitch
......@@ -123,7 +124,4 @@ If you've created the symbol in the Symbol Editor, you will need to define the f
Save the library and go back to KiCad, you have your symbol and footprint up and running.
## Make sure they are connected and they work fine
Before uploading the new component into this repository, please, make sure they are well connected and referenced and that the footprint works with the physical component, this library will be used by the students so we have to ensure that they work fine.
\ No newline at end of file
Before uploading the new component into this repository, please, make sure they are well connected and referenced and that the footprint works with the physical component, this library will be used by the students so we have to ensure that they work fine.
......@@ -23,6 +23,11 @@ def errorOnLine(lineNum, message):
errorCount = errorCount + 1
print('\033[1;31;40mERROR LINE', str(lineNum) + ':\033[0;37;40m', message)
def error(message):
global errorCount
errorCount = errorCount + 1
print('\033[1;31;40mERROR:\033[0;37;40m', message)
def checkPartName(partDEFName, partF1Name):
if partF1Name != partDEFName:
errorOnLine(lineNum, 'Part DEF name and F1 name do not match')
......@@ -50,6 +55,7 @@ def checkDescription(symbolName):
f.close()
errorOnLine(lineNum, 'Part description not found in .dcm file:' + symbolName)
# Read the library file
with open(libraryName + '.lib', 'r') as f:
lines = f.readlines()
f.close()
......@@ -71,9 +77,24 @@ for l in lines:
if words[0] == 'F2':
checkFootprint(lineNum, words[1].strip('"'))
def checkSymbolMapping(footprintName):
with open(libraryName + '.lib', 'r') as f, \
mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as s:
if s.find(footprintName.encode('utf8')) != -1:
return True
f.close()
error('Symbol mapping not found for footprint ' + footprintName)
# Read all footprints in *.pretty directory
files = os.listdir(libraryName + '.pretty')
for f in files:
footprintName = f.replace('.kicad_mod', '')
checkSymbolMapping(footprintName)
if errorCount > 0:
print('TOTAL ERRORS in ' + libraryName + '.lib:', errorCount)
exit(1)
print(libraryName + '.lib is \033[1;32;40mOK!')
exit(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment