TousstNicolas / JLC2KiCad_lib

JLC2KICAD_lib is a python script that generate a component library (schematic, footprint and 3D model ) for KiCad from the JLCPCB/easyEDA library.
MIT License
228 stars 42 forks source link

Fix for #27 (appending item outside of structure) was lost #46

Closed vvuk closed 1 year ago

vvuk commented 1 year ago

It looks like the fix that was merged in issue #27 was lost; it's not present in the current symbol.py (and the problem occurs).

vvuk commented 1 year ago

Digging more into this -- it looks like even if I bring back the fix, it's not correct; the issue now seems to be that my existing library file is 43191 bytes, but when the contents are read into python, the length of the string is 43188. This is presumably because there are some actual UTF-8 sequences in there... so a rfind will find the right string index for the paren, but will be the wrong offset for the lseek().

I've locally changed this to just do the append as a string and write out the file:

            new_content = file_content[:file_content.rfind(")")]
             new_content = new_content + template_lib_component + template_lib_footer
             lib_file.seek(0)
             lib_file.write(new_content.encode())

not great, but it solves the issue.

TousstNicolas commented 1 year ago

Thanks for reporting this issue. This is indeed an issue I already encountered before. I did not found any better solution. So I will do it as you did. It should solve another similar issue.