-
Notifications
You must be signed in to change notification settings - Fork 44
/
prebuild.py
41 lines (30 loc) · 1.03 KB
/
prebuild.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
#!/usr/bin/env python
"""
Write version and date information to a .c file, so compiles can be updated
authors: ronf, fgb, apullin
"""
import time, os, sys, re
VER_STR_LENGTH_MAX = 80
if len(sys.argv) < 2:
print("Not enough arguments given. Need path to settings.h file.")
sys.exit()
settingsFile = sys.argv[1] # path to settings.h
infile = open(settingsFile, 'r') #read only
#infile = open('settings.h')
for line in infile:
if '#define IDENT_STR' in line:
identStrLine = line
infile.close()
break
identStr = re.findall(r'"(.*?)"', line)[0]
timestamp = time.strftime("%a %b %d %H:%M:%S %Y")
verStr = identStr + " " + timestamp
verStrClip = verStr[0:VER_STR_LENGTH_MAX]
# Write string to header file
filename = 'source/version-string.h'
fileout = open(filename,'w')
fileout.write(
'/* automatically generated by version.py - do not edit! Do not enter into SCM! */\n\n' + \
'#define VERSION_STRING "'+ verStrClip + '"\n\n' )
fileout.close()
print('updated ' + os.getcwd() + os.sep + filename)