regression ui: add missing functionalities for setup, version and update.

pull/859/head
Kim Kulling 2016-04-19 16:01:21 +02:00
parent 0ec1e91722
commit 3659570292
2 changed files with 207 additions and 24 deletions

View File

@ -41,64 +41,249 @@
# ---------------------------------------------------------------------------
from tkinter import *
import sys
import os
import platform
import run
import subprocess
import result_checker as rc
INFO = 0
WARN = 1
ERROR = 2
# -------------------------------------------------------------------------------
def log( sev, msg ):
"""
This function is used to log info, warnings and errors.
"""
logEntry = ""
if sev == 0:
logEntry = logEntry + "[INFO]: "
elif sev == 1:
logEntry = logEntry + "[WARN]: "
elif sev == 2:
logEntry = logEntry + "[ERR] : "
logEntry = logEntry + msg
print( logEntry )
# -------------------------------------------------------------------------------
class BaseDialog( Toplevel ):
"""
Helper base class for dialogs used in the UI.
"""
def __init__(self, parent, title = None, buttons=""):
"""
Constructor
"""
Toplevel.__init__( self, parent )
self.transient(parent)
if title:
self.title(title)
self.parent = parent
self.result = None
body = Frame(self)
self.initial_focus = self.body(body)
body.pack(padx=5, pady=5)
self.buttonbox(buttons)
self.grab_set()
if not self.initial_focus:
self.initial_focus = self
self.protocol("WM_DELETE_WINDOW", self.cancel)
self.geometry("+%d+%d" % (parent.winfo_rootx() + 50,
parent.winfo_rooty() + 50))
self.initial_focus.focus_set()
self.wait_window(self)
def body(self, master):
# create dialog body. return widget that should have
# initial focus. this method should be overridden
pass
def buttonbox(self, buttons):
# add standard button box. override if you don't want the
# standard buttons
box = Frame(self)
w = Button(box, text="OK", width=40, command=self.ok, default=ACTIVE)
w.pack(side=LEFT, padx=5, pady=5)
self.bind("<Return>", self.ok)
box.pack()
def ok(self, event=None):
if not self.validate():
self.initial_focus.focus_set() # put focus back
return
self.withdraw()
self.update_idletasks()
self.apply()
self.cancel()
def cancel(self, event=None):
# put focus back to the parent window
self.parent.focus_set()
self.destroy()
def validate(self):
return 1 # override
def apply(self):
pass # override
# -------------------------------------------------------------------------------
class VersionDialog( BaseDialog ):
"""
This class is used to create the info dialog.
"""
def body(self, master):
# info will be read from assimp command line tool
version = "Asset importer lib version unknown"
exe = run.getEnvVar( "assimp_path" )
if len( exe ) != 0:
command = [exe, "version" ]
log( INFO, "command = " + str(command))
stdout = subprocess.check_output(command)
for line in stdout.splitlines():
pos = str(line).find( "Version" )
if -1 != pos:
version = line
Label(master, text=version).pack()
def apply(self):
pass
# -------------------------------------------------------------------------------
class SetupDialog( BaseDialog ):
"""
This class is used to create the setup dialog.
"""
def body(self, master):
Label(master, justify=LEFT, text="Assimp: " ).grid(row=0, column=0)
Label(master, justify=LEFT, text=run.getEnvVar("assimp_path")).grid(row=0, column=1)
Label(master, text="New executable:").grid(row=1)
self.e1 = Entry(master)
self.e1.grid(row=1, column=1)
return self.e1 # initial focus
def apply(self):
exe = str( self.e1.get() )
if len( exe ) == 0:
return 0
if os.path.isfile( exe ):
log( INFO, "Set executable at " + exe)
self.assimp_bin_path = exe
run.setEnvVar("assimp_path", self.assimp_bin_path)
else:
log( ERROR, "Executable not found at "+exe )
return 0
# -------------------------------------------------------------------------------
class RegDialog( object ):
"""
This class is used to create a simplified user interface for running the regression test suite.
"""
def __init__(self, bin_path ):
self.assimp_bin_path = bin_path
"""
Constructs the dialog, you can define which executable shal be used.
@param bin_path [in] Path to assimp binary.
"""
run.setEnvVar( "assimp_path", bin_path )
self.b_run_ = None
self.b_update_ = None
self.b_res_checker_ = None
self.b_quit_ = None
self.editor = "notepad"
self.root = None
self.width=40
def run_reg(self):
print( "run_reg" )
run.setEnvVar( "assimp_path", self.assimp_bin_path )
log(INFO, "Starting regression test suite.")
run.run_test()
rc.run()
self.b_update_.config( state=ACTIVE )
return 0
def reg_update(self):
print( "ToDo!" )
assimp_exe = run.getEnvVar( "assimp_path" )
if len( assimp_exe ) == 0:
return 1
exe = "python"
command = [ exe, "gen_db.py", assimp_exe ]
log(INFO, "command = " + str(command))
stdout = subprocess.call(command)
log(INFO, stdout)
return 0
def shop_diff( self ):
log(WARN, "ToDo!")
return 0
def open_log(self):
command = [ self.editor, "../results/run_regression_suite_output.txt", ]
print( "command = " + str( command ) )
log(INFO, "command = " + str( command ) )
r = subprocess.call(command)
return 0
def show_version( self ):
d = VersionDialog( self.root )
return 0
def setup(self):
d = SetupDialog( self.root )
return 0
def quit(self):
print( "quit" )
log( INFO, "quit" )
sys.exit( 0 )
def initUi(self):
root = Tk()
root.title( "Assimp-Regression")
self.b_run_ = Button( root, text="Run regression ", command=self.run_reg, width = 50 )
self.b_update_ = Button( root, text="Update database", command=self.reg_update, width = 50 )
self.b_log_ = Button( root, text="Open log", command=self.open_log, width = 50 )
self.b_quit_ = Button( root, text="Quit ", command=self.quit, width = 50 )
self.b_run_.grid( row = 0, column = 0, sticky = W+E)
self.b_update_.grid( row = 1, column = 0, sticky = W+E)
self.b_log_.grid( row = 2, column = 0, sticky = W+E )
self.b_quit_.grid( row = 3, column = 0, sticky = W+E)
self.b_update_.config( state=DISABLED )
root.mainloop()
# create the frame with buttons
self.root = Tk()
self.root.title( "Assimp-Regression UI")
self.b_run_ = Button( self.root, text="Run regression ", command=self.run_reg, width = self.width )
self.b_update_ = Button( self.root, text="Update database", command=self.reg_update, width = self.width )
self.b_show_diff_ = Button( self.root, text="Show diff", command=self.shop_diff, width = self.width )
self.b_log_ = Button( self.root, text="Open log", command=self.open_log, width = self.width )
self.b_setup_ = Button( self.root, text="Setup", command=self.setup, width = self.width )
self.b_version_ = Button( self.root, text="Show version", command=self.show_version, width = self.width )
self.b_quit_ = Button( self.root, text="Quit", command=self.quit, width = self.width )
# define the used grid
self.b_run_.grid( row=0, column=0, sticky=W+E )
self.b_update_.grid( row=1, column=0, sticky=W+E )
self.b_show_diff_.grid( row=2, column=0, sticky=W+E )
self.b_log_.grid( row=3, column=0, sticky=W+E )
self.b_setup_.grid( row=4, column=0, sticky=W+E )
self.b_version_.grid( row=5, column=0, sticky=W+E )
self.b_quit_.grid( row=6, column=0, sticky=W+E )
#self.b_update_.config( state=DISABLED )
self.b_show_diff_.config( state=DISABLED )
# run mainloop
self.root.mainloop()
# -------------------------------------------------------------------------------
def getDefaultExecutable():
assimp_bin_path = ""
if platform.system() == "Windows":
assimp_bin_path = '..\\..\\bin\\debug\\assimpd.exe'
elif platform.system() == "Linux":
assimp_bin_path = '../../bin/assimp'
return assimp_bin_path
# -------------------------------------------------------------------------------
if __name__ == "__main__":
if len(sys.argv) > 1:
assimp_bin_path = sys.argv[1]
else:
assimp_bin_path = '..\\..\\bin\\debug\\assimpd.exe'
print( 'Using assimp binary: ' + assimp_bin_path )
assimp_bin_path = getDefaultExecutable()
log( INFO, 'Using assimp binary: ' + assimp_bin_path )
dlg = RegDialog(assimp_bin_path)
dlg.initUi()

View File

@ -159,6 +159,7 @@ class results:
# -------------------------------------------------------------------------------
def setEnvVar( var, value ):
print ( "set var " + var +" to" + value)
Environment[ var ] = value
# -------------------------------------------------------------------------------
@ -218,7 +219,6 @@ def process_dir(d, outfile_results, zipin, result ):
outfile_results.write("assimp dump "+"-"*80+"\n")
outfile_results.flush()
assimp_bin_path = getEnvVar("assimp_path")
print( "assimp_bin_path = " + assimp_bin_path )
command = [assimp_bin_path,
"dump",
fullpath, outfile_actual, "-b", "-s", "-l" ] +\
@ -290,7 +290,6 @@ def run_test():
try:
zipin = zipfile.ZipFile(settings.database_name + ".zip",
"r", zipfile.ZIP_STORED)
except IOError:
print("Regression database ", settings.database_name,
".zip was not found")
@ -307,7 +306,6 @@ def run_test():
return 0
# -------------------------------------------------------------------------------
if __name__ == "__main__":
if len(sys.argv) > 1: