From a3f83482a27a1c5703ee1d4dba5c5f2715ca5503 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks <krisjanis.rijnieks@gmail.com> Date: Sun, 25 Apr 2021 13:14:23 +0300 Subject: [PATCH] Add test, check if footprint is mapped to a symbol in lib --- CONTRIBUTING.md | 10 ++++------ test.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e1e11ed..3026b72 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # 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. diff --git a/test.py b/test.py index 1823e2d..03620a2 100644 --- a/test.py +++ b/test.py @@ -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) -- GitLab