Skip to content

Commit 9456e11

Browse files
committed
Update build.py
1 parent 9934ff0 commit 9456e11

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

pcm/build.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ def findReplace(directory, find, replace, filePattern):
1818
for path, dirs, files in os.walk(os.path.abspath(directory)):
1919
for filename in fnmatch.filter(files, filePattern):
2020
filepath = os.path.join(path, filename)
21-
with open(filepath) as f:
21+
with open(filepath, 'rb') as f:
2222
s = f.read()
2323
s = s.replace(find, replace)
24-
with open(filepath, "w") as f:
24+
with open(filepath, 'wb') as f:
2525
f.write(s)
2626

2727
# ======================================================
2828

29-
# Delete build and recreate
29+
# Delete build content and recreate
3030
try:
3131
shutil.rmtree(build_path)
3232
except FileNotFoundError:
@@ -36,20 +36,19 @@ def findReplace(directory, find, replace, filePattern):
3636
os.chdir(build_path)
3737

3838
# Copy symbols, footprints and 3dmodels
39-
shutil.copytree(path.join(src_path,'symbols'), path.join('content'))
40-
shutil.copytree(path.join(src_path,'footprints'), path.join('content'))
41-
shutil.copytree(path.join(src_path,'3dmodels'), path.join('content'))
39+
shutil.copytree(path.join(src_path,'symbols'), path.join('content','symbols'), dirs_exist_ok = True)
40+
shutil.copytree(path.join(src_path,'footprints'), path.join('content','footprints'), dirs_exist_ok = True)
41+
shutil.copytree(path.join(src_path,'3dmodels'), path.join('content','3dmodels'), dirs_exist_ok = True)
4242

4343
# Replace every occurrence of "(model "${SPARKFUN_KICAD_LIBRARY}/3dmodels/3d-library.3dshapes/"
4444
# with "(model "${KICAD9_3RD_PARTY}/3dmodels/com_github_sparkfun_sparkfun-kicad-libraries/3d-library.3dshapes/"
45-
findReplace(path.join('content'), '(model "${SPARKFUN_KICAD_LIBRARY}/3dmodels/3d-library.3dshapes/',
46-
'(model "${KICAD9_3RD_PARTY}/3dmodels/com_github_sparkfun_SparkFun-KiCad-Libraries/3d-library.3dshapes/', '*.*')
45+
findReplace(path.join('content'), b'(model "${SPARKFUN_KICAD_LIBRARY}/3dmodels/3d-library.3dshapes/',
46+
b'(model "${KICAD9_3RD_PARTY}/3dmodels/com_github_sparkfun_SparkFun-KiCad-Libraries/3d-library.3dshapes/', '*.*')
4747

4848
# This is the with-PCM_ version
49-
# Replace every occurrence of "(symbol "SparkFun-"
50-
# with "(symbol "PCM_SparkFun-"
51-
findReplace(path.join('content'), "(symbol \"SparkFun-",
52-
"(symbol \"PCM_SparkFun-", "*.*")
49+
# Replace every occurrence of ""Footprint" "SparkFun-"
50+
# with ""Footprint" "PCM_SparkFun-"
51+
findReplace(path.join('content'), b'"Footprint" "SparkFun-', b'"Footprint" "PCM_SparkFun-', '*.*')
5352

5453
# Copy icon
5554
shutil.copytree(resources_path, path.join('content','resources'))
@@ -96,14 +95,14 @@ def findReplace(directory, find, replace, filePattern):
9695
os.mkdir(path.join('content'))
9796

9897
# Copy symbols, footprints and 3dmodels
99-
shutil.copytree(path.join(src_path,'symbols'), path.join('content'))
100-
shutil.copytree(path.join(src_path,'footprints'), path.join('content'))
101-
shutil.copytree(path.join(src_path,'3dmodels'), path.join('content'))
98+
shutil.copytree(path.join(src_path,'symbols'), path.join('content','symbols'), dirs_exist_ok = True)
99+
shutil.copytree(path.join(src_path,'footprints'), path.join('content','footprints'), dirs_exist_ok = True)
100+
shutil.copytree(path.join(src_path,'3dmodels'), path.join('content','3dmodels'), dirs_exist_ok = True)
102101

103102
# Replace every occurrence of "(model "${SPARKFUN_KICAD_LIBRARY}/3dmodels/3d-library.3dshapes/"
104103
# with "(model "${KICAD9_3RD_PARTY}/3dmodels/com_github_sparkfun_sparkfun-kicad-libraries/3d-library.3dshapes/"
105-
findReplace(path.join('content'), '(model "${SPARKFUN_KICAD_LIBRARY}/3dmodels/3d-library.3dshapes/',
106-
'(model "${KICAD9_3RD_PARTY}/3dmodels/com_github_sparkfun_SparkFun-KiCad-Libraries/3d-library.3dshapes/', '*.*')
104+
findReplace(path.join('content'), b'(model "${SPARKFUN_KICAD_LIBRARY}/3dmodels/3d-library.3dshapes/',
105+
b'(model "${KICAD9_3RD_PARTY}/3dmodels/com_github_sparkfun_SparkFun-KiCad-Libraries/3d-library.3dshapes/', '*.*')
107106

108107
# Copy icon
109108
shutil.copytree(resources_path, path.join('content','resources'))

0 commit comments

Comments
 (0)