-
Notifications
You must be signed in to change notification settings - Fork 7
/
plugin_init.py
38 lines (30 loc) · 942 Bytes
/
plugin_init.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
# coding=utf-8
'''
@ Summary: platform plugin init, such as x-cube-ai
@ Update: add decode stm_info
@ file: plugin_init.py
@ version: 1.0.0
@ Author: Lebhoryi@gmail.com
@ Date: 2020/12/16 20:08
'''
import os
import logging
import subprocess
def set_env(plugin_path):
""" set plugin_path Path"""
assert os.path.exists(plugin_path), 'No {} here'.format(plugin_path)
# set stm32ai system env
os.environ['PATH'] = plugin_path
# validate
p = subprocess.Popen("stm32ai --version", shell=True, stdout=subprocess.PIPE).stdout
stm_info = p.read().split(b"\r\n")[0]
stm_info = stm_info.decode("utf-8")
if not stm_info:
raise Exception("Set plugin env wrong???")
else:
logging.info(stm_info)
if __name__ == "__main__":
plugin = r"D:\Program Files (x86)\stm32ai-windows-5.2.0\windows"
logging.getLogger().setLevel(logging.INFO)
set_env(plugin)
print("u a right...")