-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathset_version.py
51 lines (45 loc) · 1.4 KB
/
set_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Highly specialized program to update version and date in KiCad .sch files
# Fortunately it's really short.
# Suggest running this script, and committing the result,
# in preparation for a release.
from glob import glob
from os import rename
from sys import argv
from datetime import datetime
from re import sub
def sch_version(f, new_ver, new_date):
print(f)
of = open("temp", "w")
for ll in open(f).readlines():
if ll.startswith("Rev "):
aa = ll.split(' ')
of.write(aa[0] + ' "' + new_ver + '"\n')
elif ll.startswith("Date ") and new_date is not None:
aa = ll.split(' ')
of.write(aa[0] + ' "' + new_date + '"\n')
else:
of.write(ll)
of.close()
rename("temp", f)
def pcb_version(f, new_ver, new_date):
# still to-do: date?
print(f)
of = open("temp", "w")
for ll in open(f).readlines():
if 'gr_text "tag: ' in ll:
ll2 = sub(r'"tag: [^"]+"', '"tag: ' + new_ver + '"', ll)
of.write(ll2)
else:
of.write(ll)
of.close()
rename("temp", f)
if __name__ == "__main__":
if len(argv) < 2:
print("no version")
exit(1)
new_ver = argv[1]
new_date = datetime.now().strftime('%Y-%m-%d')
for f in glob("*.sch"):
sch_version(f, new_ver, new_date)
for f in glob("*.kicad_pcb"):
pcb_version(f, new_ver, new_date)