-
Notifications
You must be signed in to change notification settings - Fork 2
/
pre_script.py
58 lines (42 loc) · 1.8 KB
/
pre_script.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
52
53
54
55
56
57
58
import configparser
from shutil import copyfile
from os.path import basename
import sys
import datetime
import os
Import("env")
DESTINY = "\\\\lumrasp8\\srv\\firmware\\"
def set_value_in_property_file(file_path, section, key, value):
config = configparser.RawConfigParser()
config.read(file_path)
if (not config.has_section(section)):
config.add_section(section)
config.set(section, key, value)
cfgfile = open(file_path, 'w')
# use flag in case case you need to avoid white space.
config.write(cfgfile, space_around_delimiters=False)
cfgfile.close()
def publish_firmware(source, target, env):
firmware_path = str(source[0])
firmware_name = basename(firmware_path)
VERSION = env.GetProjectOption("custom_version")
VERSION = VERSION[0:VERSION.rindex('.')+1]
VERSION_FILE = '.version'
filter = env.GetProjectOption("src_filter")[0][2:-1]
srcdir = env.get("PROJECTSRC_DIR")+os.sep + filter+os.sep
if os.path.exists(srcdir+VERSION_FILE):
FILE = open(srcdir+VERSION_FILE)
VERSION_PATCH_NUMBER = FILE.readline()
VERSION_PATCH_NUMBER = int(VERSION_PATCH_NUMBER)
else:
VERSION_PATCH_NUMBER = 0
VERSION = VERSION + str(VERSION_PATCH_NUMBER)
print("Uploading {0}. Version: {1}".format(firmware_name, VERSION))
copyfile(firmware_path, DESTINY + firmware_name)
package = env.GetProjectOption("custom_name")
set_value_in_property_file(DESTINY+"firmware.ini", package, 'file', firmware_name)
set_value_in_property_file(DESTINY+"firmware.ini", package, 'version', VERSION)
set_value_in_property_file(DESTINY+"firmware.ini", package, 'date',datetime.datetime.now())
print("The firmware has been successfuly copied!")
# Custom upload command and program name
env.Replace(UPLOADCMD=publish_firmware)