mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-10-19 03:13:34 +08:00
[tools] format python code
This commit is contained in:

committed by
Man, Jianting (Meco)

parent
af82606dd3
commit
eafcdd0bc2
104
tools/sconsui.py
104
tools/sconsui.py
@@ -62,19 +62,19 @@ lock = None
|
||||
|
||||
class CmdExecutor(threading.Thread):
|
||||
def __init__(self, cmd, output):
|
||||
threading.Thread.__init__(self)
|
||||
threading.Thread.__init__(self)
|
||||
self.cmd = cmd
|
||||
self.child = None
|
||||
|
||||
def run(self):
|
||||
global executor, builder, lock
|
||||
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
try:
|
||||
from win32spawn import Win32Spawn
|
||||
subprocess = Win32Spawn(self.cmd)
|
||||
subprocess.start_pipe()
|
||||
|
||||
|
||||
builder.progressbar.start()
|
||||
while not subprocess.is_terminated or subprocess.qsize() > 0:
|
||||
try:
|
||||
@@ -87,7 +87,7 @@ class CmdExecutor(threading.Thread):
|
||||
lock.release()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
builder.progressbar.stop()
|
||||
except:
|
||||
pass
|
||||
@@ -113,7 +113,7 @@ class DirSelectBox(ttk.Frame):
|
||||
self.entry = ttk.Entry(self, textvariable = self.dir_var)
|
||||
self.entry.pack(fill=BOTH, expand=1,side=LEFT)
|
||||
self.entry.configure(width = 50)
|
||||
|
||||
|
||||
self.browser_button = ttk.Button(self, text="Browser", command=self.browser)
|
||||
self.browser_button.pack(side=RIGHT)
|
||||
|
||||
@@ -125,7 +125,7 @@ class DirSelectBox(ttk.Frame):
|
||||
def set_path(self, path):
|
||||
path = path.replace('\\', '/')
|
||||
self.dir_var.set(path)
|
||||
|
||||
|
||||
def get_path(self):
|
||||
return self.dir_var.get()
|
||||
|
||||
@@ -147,31 +147,31 @@ class SconsUI():
|
||||
theme = style.theme_use()
|
||||
default = style.lookup(theme, 'background')
|
||||
master.configure(background=default)
|
||||
|
||||
|
||||
notebook = ttk.Notebook(master)
|
||||
notebook.pack(fill=BOTH, padx=5, pady=5)
|
||||
|
||||
# building page
|
||||
|
||||
# building page
|
||||
page_building = ttk.Frame(notebook)
|
||||
notebook.add(page_building, padding=3)
|
||||
notebook.tab(0, text='Build', underline="-1")
|
||||
self.setup_building_ui(page_building)
|
||||
self.building_page = page_building
|
||||
|
||||
|
||||
# make project page
|
||||
page_project = ttk.Frame(notebook)
|
||||
notebook.add(page_project, padding = 3)
|
||||
notebook.tab(1, text = 'Project', underline = '-1')
|
||||
self.setup_project_ui(page_project)
|
||||
self.project_page = page_project
|
||||
|
||||
# setting page
|
||||
|
||||
# setting page
|
||||
page_setting = ttk.Frame(notebook)
|
||||
notebook.add(page_setting, padding = 3)
|
||||
notebook.tab(2, text = 'Setting', underline = '-1')
|
||||
self.setup_setting_ui(page_setting)
|
||||
self.setting_page = page_setting
|
||||
|
||||
|
||||
padding = ttk.Frame(master)
|
||||
padding.pack(fill=X)
|
||||
quit = ttk.Button(padding, text='Quit', command = self.quit)
|
||||
@@ -179,15 +179,15 @@ class SconsUI():
|
||||
|
||||
# set notebook to self
|
||||
self.notebook = notebook
|
||||
|
||||
# read setting
|
||||
|
||||
# read setting
|
||||
self.read_setting()
|
||||
self.is_makeing_project = False
|
||||
|
||||
|
||||
def read_setting(self):
|
||||
import platform
|
||||
import os
|
||||
|
||||
|
||||
home = ''
|
||||
if platform.system() == 'Windows':
|
||||
driver = os.environ['HOMEDRIVE']
|
||||
@@ -195,7 +195,7 @@ class SconsUI():
|
||||
home = os.path.join(driver, home)
|
||||
else:
|
||||
home = os.environ['HOME']
|
||||
|
||||
|
||||
setting_path = os.path.join(home, '.rtt_scons')
|
||||
if os.path.exists(setting_path):
|
||||
setting = open(os.path.join(home, '.rtt_scons'))
|
||||
@@ -217,10 +217,10 @@ class SconsUI():
|
||||
# set RT-Thread Root Directory according environ
|
||||
if 'RTT_ROOT' in os.environ:
|
||||
self.RTTRoot.set_path(os.environ['RTT_ROOT'])
|
||||
|
||||
|
||||
if self.RTTRoot.get_path() == '':
|
||||
rtt_root = ''
|
||||
# detect RT-Thread directory
|
||||
# detect RT-Thread directory
|
||||
if os.path.exists(os.path.join('..', 'include', 'rtthread.h')):
|
||||
rtt_root = os.path.join('..')
|
||||
elif os.path.exists(os.path.join('..', '..', 'include', 'rtthread.h')):
|
||||
@@ -247,7 +247,7 @@ class SconsUI():
|
||||
if not self.CompilersPath['GCC'].get_path():
|
||||
paths = os.environ['PATH']
|
||||
paths = paths.split(';')
|
||||
|
||||
|
||||
for path in paths:
|
||||
if path.find('CodeSourcery') != -1:
|
||||
self.CompilersPath['GCC'].set_path(path)
|
||||
@@ -269,7 +269,7 @@ class SconsUI():
|
||||
home = os.environ['HOME']
|
||||
|
||||
setting = open(os.path.join(home, '.rtt_scons'), 'w+')
|
||||
# current comiler
|
||||
# current comiler
|
||||
# line = '%s=%s\n' % ('compiler', self.compilers.get()))
|
||||
line = '%s=%s\n' % ('compiler', 'iar')
|
||||
setting.write(line)
|
||||
@@ -296,17 +296,17 @@ class SconsUI():
|
||||
def setup_building_ui(self, frame):
|
||||
padding = ttk.Frame(frame)
|
||||
padding.pack(fill=X)
|
||||
|
||||
|
||||
button = ttk.Button(padding, text='Clean', command=self.do_clean)
|
||||
button.pack(side=RIGHT)
|
||||
button = ttk.Button(padding, text='Build', command=self.do_build)
|
||||
button.pack(side=RIGHT)
|
||||
label = ttk.Label(padding, relief = 'flat', text = 'Click Build or Clean to build or clean system -->')
|
||||
label.pack(side=RIGHT, ipady = 5)
|
||||
|
||||
|
||||
self.progressbar = ttk.Progressbar(frame)
|
||||
self.progressbar.pack(fill=X)
|
||||
|
||||
|
||||
separator = ttk.Separator(frame)
|
||||
separator.pack(fill=X)
|
||||
|
||||
@@ -316,17 +316,17 @@ class SconsUI():
|
||||
def setup_project_ui(self, frame):
|
||||
label = ttk.Label(frame, relief = 'flat', text = 'Choose Integrated Development Environment:')
|
||||
label.pack(fill=X, pady = 5)
|
||||
|
||||
|
||||
separator = ttk.Separator(frame)
|
||||
separator.pack(fill=X)
|
||||
|
||||
|
||||
self.ide = StringVar()
|
||||
self.ide.set("mdk4") # initialize
|
||||
|
||||
|
||||
for text,mode in IDE:
|
||||
radiobutton = ttk.Radiobutton(frame, text=text, variable = self.ide, value = mode)
|
||||
radiobutton.pack(fill=X, padx=10)
|
||||
|
||||
|
||||
bottom = ttk.Frame(frame)
|
||||
bottom.pack(side=BOTTOM, fill=X)
|
||||
button = ttk.Button(bottom, text="Make Project", command = self.do_make_project)
|
||||
@@ -336,26 +336,26 @@ class SconsUI():
|
||||
row = 0
|
||||
label = ttk.Label (frame, relief = 'flat', text='RT-Thread Root Folder:')
|
||||
label.grid(row=row, column=0,ipadx=5, ipady=5, padx = 5)
|
||||
|
||||
|
||||
self.RTTRoot = DirSelectBox(frame)
|
||||
self.RTTRoot.grid(row=row, column=1, sticky=E+W)
|
||||
row = row + 1
|
||||
|
||||
|
||||
label = ttk.Label (frame, relief = 'flat', text='Board Support Folder:')
|
||||
label.grid(row=row, column=0,ipadx=5, ipady=5, padx = 5)
|
||||
|
||||
|
||||
self.BSPRoot = DirSelectBox(frame)
|
||||
self.BSPRoot.grid(row=row, column=1, sticky=E+W)
|
||||
row = row + 1
|
||||
|
||||
|
||||
label = ttk.Label (frame, relief='flat', text='Toolchain:')
|
||||
label.grid(row=row, column=0,ipadx=5, ipady=5, sticky=E+W)
|
||||
row = row + 1
|
||||
|
||||
|
||||
separator = ttk.Separator(frame)
|
||||
separator.grid(row = row, column = 0, columnspan = 2, sticky = E+W)
|
||||
row = row + 1
|
||||
|
||||
|
||||
self.compilers = StringVar()
|
||||
self.compilers.set("GCC") # initialize
|
||||
|
||||
@@ -368,13 +368,13 @@ class SconsUI():
|
||||
self.CompilersPath[compiler] = DirSelectBox(frame)
|
||||
self.CompilersPath[compiler].grid(row=row, column=1, sticky=E+W)
|
||||
row = row + 1
|
||||
|
||||
|
||||
button = ttk.Button(frame, text='Save Setting', command = self.save_setting)
|
||||
button.grid(row = row, column = 1, sticky = E)
|
||||
row = row + 1
|
||||
|
||||
def prepare_build(self):
|
||||
# get compiler
|
||||
# get compiler
|
||||
compiler = self.compilers.get()
|
||||
if compiler == 'GCC':
|
||||
compiler = 'gcc'
|
||||
@@ -385,26 +385,26 @@ class SconsUI():
|
||||
|
||||
# get RTT Root
|
||||
rtt_root = self.RTTRoot.get_path()
|
||||
# get Compiler path
|
||||
# get Compiler path
|
||||
exec_path = self.CompilersPath[self.compilers.get()].get_path()
|
||||
|
||||
|
||||
command = ''
|
||||
|
||||
os.environ['RTT_ROOT'] = rtt_root
|
||||
os.environ['RTT_CC'] = compiler
|
||||
os.environ['RTT_EXEC_PATH'] = exec_path
|
||||
|
||||
return command
|
||||
|
||||
|
||||
return command
|
||||
|
||||
def check_path(self):
|
||||
result = True
|
||||
|
||||
|
||||
if self.BSPRoot.get_path() == '':
|
||||
result = False
|
||||
|
||||
|
||||
if self.RTTRoot.get_path() == '':
|
||||
result = False
|
||||
|
||||
|
||||
if not result:
|
||||
tkMessageBox.showinfo("RT-Thread SCons UI",
|
||||
"Folder is empty, please choose correct directory.")
|
||||
@@ -423,8 +423,8 @@ class SconsUI():
|
||||
|
||||
self.output.delete(1.0, END)
|
||||
self.output.insert(END, 'building project...\n')
|
||||
ExecCmd(command)
|
||||
|
||||
ExecCmd(command)
|
||||
|
||||
def do_clean(self):
|
||||
self.prepare_build()
|
||||
command = 'scons -c'
|
||||
@@ -438,18 +438,18 @@ class SconsUI():
|
||||
self.output.delete(1.0, END)
|
||||
self.output.insert(END, 'clean project...\n')
|
||||
ExecCmd(command)
|
||||
|
||||
|
||||
def do_make_project(self):
|
||||
ide = self.ide.get()
|
||||
self.prepare_build()
|
||||
command = 'scons --target=%s -s' % ide
|
||||
|
||||
|
||||
if not self.check_path():
|
||||
return
|
||||
|
||||
# select build page
|
||||
|
||||
# select build page
|
||||
self.notebook.select(self.building_page)
|
||||
|
||||
|
||||
bsp = self.BSPRoot.get_path()
|
||||
os.chdir(bsp)
|
||||
|
||||
|
Reference in New Issue
Block a user