Files
chest_strap/kicad/library/library_management.py
T
2026-04-24 19:51:22 -07:00

47 lines
1.4 KiB
Python

import os
import shutil
import zipfile
# for thing in zip files, unzip, put into it's own folder by name
try:
shutil.rmtree("work_dir")
except:
pass
os.makedirs("work_dir")
os.makedirs("work_dir/KiCADv6")
os.makedirs("work_dir/stp_files")
kicad_sym_file = []
for zpf in os.listdir("zip_files"):
with zipfile.ZipFile("zip_files/" + zpf, 'r') as zip_ref:
loc = "work_dir/" + zpf[:-4]
zip_ref.extractall(loc)
shutil.copytree(loc + '/KiCADv6', 'work_dir/KiCADv6', dirs_exist_ok = True)
for e in [e for e in os.listdir("work_dir/KiCADv6") if e[-10:] == '.kicad_sym']:
lines = [e for e in open("work_dir/KiCADv6/" + e, "r").readlines() if not str.isspace(e)]
if kicad_sym_file == []:
kicad_sym_file += lines
else:
kicad_sym_file = kicad_sym_file[:-1] + lines[1:]
for e in os.listdir(loc):
if e[-4:] == '.stp' or e[-5:] == '.step':
shutil.copy(loc + "/" + e, 'work_dir/stp_files/' + e)
with open("work_dir/KiCADv6/CombinedSymbols.kicad_sym","w") as f:
f.writelines(kicad_sym_file)
# move all the footprints.pretty files to one folder under KiCADv6/footprints.pretty
# take the stuff in the date.kicad_sym stuff (lines 1 : -1) and put them in a bigger file
#os.makedirs("")
#if kicad_sym_file == []:
# kicad_sym_file = [e for e in open("work_dir/KiCADv6/" + e,"r").readlines() if not str.isspace(e)]
#else:
# kicad_sym_file = kicad_sym_file[:-1] + [e for e in open("work_dir/KiCADv6/" + e,"r").readlines()[1:]