work on KED Script

master
polymurph 2 years ago
parent 3186e3fd64
commit ccd144c359

106
ked.py

@ -0,0 +1,106 @@
'''
KED Main Script
'''
import sys
import os
import shutil
import subprocess
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def getTargetDeviceList():
os.chdir(os.getcwd() + '\\csl')
# get top level folder names in csl which represent all available target devices
return next(os.walk('.'))[1]
def build(TARGET_DEVICE):
# TODO: ask Kerem what he wanted to to with "CSL_TO_USE"
#CSL_TO_USE = 1
os.system('cmake -S . -B '+ buildDirectory + ' -DCSL_USED=' + TARGET_DEVICE)
os.chdir(buildDirectory)
os.system('make -j4')
def flash(TARGET_DEVICE):
# find out what platform the build is done (e.g. linux, win32, etc.)
if sys.platform == 'linux':
os.system('st-flash write' + TARGET_DEVICE + '.bin 0x08000000')
if sys.platform == 'win32':
# https://www.youtube.com/watch?v=AcrbUOhApd0
os.chdir('C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin')
subprocess.Popen("STM32_Programmer_CLI.exe")
os.chdir(buildDirectory)
print('this platform is not supported by KED!')
###########################################################################################################################
scriptDirectory = os.getcwd()
projectDirectory = scriptDirectory + '\\..'
buildDirectory = projectDirectory + '\\ked_build'
os.chdir(scriptDirectory)
# exit if no argument was passed
argvLen = len(sys.argv)
if argvLen < 2:
print('target device missing as argument!')
sys.exit()
# obtain list of all available targets in KED
targetDevList = getTargetDeviceList()
# user requests help
if sys.argv[1] in ('-h', '-help'):
print('HELP -> TODO!')
sys.exit()
# user request to remove build folder
if sys.argv[1] in ('-rm', '-rmb'):
if os.path.exists(buildDirectory):
shutil.rmtree(buildDirectory)
sys.exit()
# user requests listing of all available target devices
if sys.argv[1] in ('-ls', '-lt', '-lst', '-lsd'):
print('listing all availabel targets...')
for targetDev in targetDevList:
print(targetDev)
sys.exit()
# user requests to clean project by erasing build
if sys.argv[1] in ('-clean', '-c', '-db'):
if os.path.exists(buildDirectory):
shutil.rmtree(buildDirectory)
os.mkdir(buildDirectory)
print('build cleaned!')
sys.exit()
# check if requested target device is supported by KED
if sys.argv[1] not in targetDevList:
print('debug: targt not valid')
sys.exit()
print('building for target device ['+ bcolors.OKGREEN + sys.argv[1] + bcolors.ENDC + ']...')
#create build directory if missing
if not os.path.exists(buildDirectory):
os.mkdir(buildDirectory)
CSL_TO_USE = sys.argv[1]
build(CSL_TO_USE)
flash(CSL_TO_USE)

@ -1,32 +0,0 @@
'''
KED Builder Script
'''
import sys
import os
def build():
argvLen = len(sys.argv)
if argvLen < 2:
print('please enter a valid target device')
print('currently available target devices...')
os.chdir(os.getcwd() + '\\csl')
# get top level folder names in csl which represent all available target devices
dirlist = next(os.walk('.'))[1]
for dir in dirlist:
print(dir)
else:
print('todo')
def autoBuild():
return
scriptDirectory = os.getcwd()
projectDirectory = scriptDirectory + '\\..'
buildDirectory = projectDirectory + '\\ked_build'
os.chdir(scriptDirectory)
build()
Loading…
Cancel
Save