-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokitto_pre.py
69 lines (58 loc) · 3 KB
/
pokitto_pre.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
59
60
61
62
63
64
65
66
67
68
69
import requests
import os
import filecmp
#the following is needed, because at this stage PLATFORMIO_HOME_DIR is undefined
from os.path import expanduser
home = expanduser("~")
if os.name == 'nt': # Windows
basePath = home + '\.platformio'
else:
basePath = home + '/.platformio'
patchPath = basePath + '/packages/framework-mbed/targets/TARGET_NXP/TARGET_LPC11U6X/device/TOOLCHAIN_GCC_ARM/TARGET_LPC11U68/'
#get the latest startup files from github
print("Comparing startup_LPC11U68.cpp to PokittoLib repository...")
url = 'https://raw.githubusercontent.com/pokitto/PokittoIO/master/src/hal/LPC11U68/mbed_patches/arm_gcc/startup_LPC11U68.cpp'
r = requests.get(url, allow_redirects=True, headers={'Cache-Control': 'no-cache'})
open(patchPath + 'startup_LPC11U68.tmp', 'wb').write(r.content)
#check if startup_LPC11U68.bak exists
if not (os.path.exists(patchPath + 'startup_LPC11U68.bak')):
#first run, so create a backup
print('Creating backup of original startup_LPC11U68.cpp')
os.rename(patchPath + 'startup_LPC11U68.cpp', patchPath + 'startup_LPC11U68.bak')
#compare new .tmp file(s) to existing files
if (os.path.exists(patchPath + 'startup_LPC11U68.cpp')):
if not filecmp.cmp(patchPath + 'startup_LPC11U68.tmp', patchPath + 'startup_LPC11U68.cpp'):
#they are different, so update
print('New version found. Saving it as startup_LPC11U68.cpp')
open(patchPath + 'startup_LPC11U68.cpp', 'wb').write(r.content)
else:
#missing completely, so save
print('Saving startup_LPC11U68.cpp')
open(patchPath + 'startup_LPC11U68.cpp', 'wb').write(r.content)
#delete temporary file(s)
if (os.path.exists(patchPath + 'startup_LPC11U68.tmp')):
os.remove(patchPath+'startup_LPC11U68.tmp')
#get the latest linker file from github
print("Comparing linker file LPC11U68.ld to PokittoLib repository...")
url = 'https://raw.githubusercontent.com/pokitto/PokittoIO/master/src/hal/LPC11U68/mbed_patches/arm_gcc/LPC11U68.ld'
r = requests.get(url, allow_redirects=True, headers={'Cache-Control': 'no-cache'})
open(patchPath + 'LPC11U68.tmp', 'wb').write(r.content)
#check if LPC11U68.bak exists
if not (os.path.exists(patchPath + 'LPC11U68.bak')):
#first run, so create a backup
if (os.path.exists(patchPath + 'LPC11U68.ld')):
print('Creating backup of original LPC11U68.ld')
os.rename(patchPath + 'LPC11U68.ld', patchPath + 'LPC11U68.bak')
#compare new .tmp file(s) to existing files
if (os.path.exists(patchPath + 'LPC11U68.ld')):
if not filecmp.cmp(patchPath + 'LPC11U68.tmp', patchPath + 'LPC11U68.ld'):
#they are different, so update
print('New version found. Saving it as LPC11U68.ld')
open(patchPath + 'LPC11U68.ld', 'wb').write(r.content)
else:
#missing completely, so save
print('Saving LPC11U68.ld')
open(patchPath + 'LPC11U68.ld', 'wb').write(r.content)
#delete temporary file(s)
if (os.path.exists(patchPath + 'LPC11U68.tmp')):
os.remove(patchPath+'LPC11U68.tmp')