Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 30.02 KB | None | 0 0
  1. # -*- coding: latin-1 -*-
  2. """ Scheduler plugin for RIDE ( Robotframework )
  3.  
  4. Created by Josu Rodriguez Vilda
  5. Changes Contributed by Thomas Robinson
  6. """
  7. import sys, os, wx, threading, datetime, subprocess, time,random,sqlite3
  8. from subprocess import Popen, PIPE
  9. #import fileviewer
  10.  
  11. import robot
  12. from robotide.version import VERSION
  13. from robotide.pluginapi import Plugin, ActionInfo, RideSaved, RideOpenSuite, RideTreeSelection
  14.  
  15.  
  16.  
  17. ver="Ver. 1.09"
  18. today = datetime.date.today().strftime("%Y%m%d")
  19.  
  20. if os.name == "nt":
  21.     systemdrive=os.environ["SystemDrive"]
  22.     COMPUTERNAME=os.environ["COMPUTERNAME"]
  23.     allusersprofile = os.environ["ALLUSERSPROFILE"]
  24.     version = "".join(sys.winver.split('.'))
  25.     SchedulerDB = allusersprofile+"\scheduler-ride.db"
  26.     runners = {'pybot': systemdrive + "\python" + version + "\\scripts\\pybot.bat",
  27.                'jybot': systemdrive + "\python" + version + "\\scripts\\jybot.bat" }
  28. elif os.name == "posix" :
  29.     runners = {'pybot': 'pybot',
  30.                'jybot': 'jybot' }
  31.  
  32. conn = sqlite3.connect(SchedulerDB)
  33. try:
  34.     conn.execute("SELECT * FROM tasks")
  35. except:
  36.     conn.execute('''CREATE TABLE [tasks]
  37.     ([id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
  38.     [date] VARCHAR(50)  NULL,
  39.     [command] VARCHAR(300)  NULL,
  40.     [state] VARCHAR(30)  NULL,
  41.     [log] vaRCHAR(300)  NULL,
  42.     [report] varCHAR(300)  NULL,
  43.     [debug] varCHAR(300)  NULL  )''')
  44.  
  45. class MyImageRenderer(wx.grid.PyGridCellRenderer):
  46.     def __init__(self, img):
  47.         wx.grid.PyGridCellRenderer.__init__(self)
  48.         self.img = img
  49.  
  50.     def Draw(self, grid, attr, dc, rect, row, col, isSelected):
  51.         image = wx.MemoryDC()
  52.         image.SelectObject(self.img)
  53.         dc.SetBackgroundMode(wx.SOLID)
  54.         if isSelected:
  55.             dc.SetBrush(wx.Brush(wx.BLUE, wx.SOLID))
  56.             dc.SetPen(wx.Pen(wx.BLUE, 1, wx.SOLID))
  57.         else:
  58.             dc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
  59.             dc.SetPen(wx.Pen(wx.WHITE, 1, wx.SOLID))
  60.         dc.DrawRectangleRect(rect)
  61.         width, height = self.img.GetWidth(), self.img.GetHeight()
  62.         if width > rect.width - 2:
  63.             width = rect.width - 2
  64.         if height > rect.height - 2:
  65.             height = rect.height - 2
  66.         dc.Blit(rect.x + 1, rect.y + 1, width, height, image, 0, 0, wx.COPY, True)
  67.  
  68.  
  69. class SchedulerPlugin(Plugin):
  70.     """ Ver. 1.09
  71.     Displays a tab where you can program different testcase execution, and test suites.
  72.     The executions are stored in database and its implementation to give the possibility to continue running after closing the program or after a restart.
  73.     Compatibility with RobotFramework 2.5
  74.     """
  75.  
  76.     def __init__(self, application):
  77.         Plugin.__init__(self, application, default_settings = {'Name': "Scheduler-plugin-for-RIDE",
  78.                                                             'Creator': "Josu Rodriguez Vilda",
  79.                                                             'Contributed':"Thomas Robinson",
  80.                                                                'Date': "13/12/2010",
  81.                                                             'Version': "1.09"})
  82.         self._panel = None
  83.  
  84.     def add_to_grid(self,arg1,arg2,arg3,arg4,arg5,arg6):
  85.        
  86.         conn.execute("INSERT INTO tasks VALUES (Null,'"+arg1+"','"+arg2+"','"+arg3+"','"+arg4+"','"+arg5+"','"+arg6+"')")
  87.         conn.commit()
  88.         last = conn.execute("SELECT last_insert_rowid() ")
  89.         return last.fetchall()[0][0]
  90.    
  91.     def button_add(self, event):
  92.  
  93.         path = self.model.suite.source
  94.         #path = os.path.dirname(path)
  95.         print path
  96.         selection = self.test_suite_tree.GetSelections()
  97.         row = self.task_grid.GetNumberRows()
  98.         for item in selection:
  99.             command = self.make_command(str(self.test_suite_tree.GetString(item)).lstrip())
  100.             bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_OTHER, (16, 16))
  101.             imageRenderer = MyImageRenderer(bmp)
  102.             last = self.add_to_grid('', command, "Paused.", "", "", "")
  103.             self.task_grid.AppendRows()
  104.             self.task_grid.SetCellRenderer(row, 0, imageRenderer)
  105.             self.task_grid.SetRowSize(row, bmp.GetHeight() + 2)
  106.             self.task_grid.SetCellValue(row, 0, str(last))
  107.             self.task_grid.SetCellValue(row, 1, command)
  108.             self.task_grid.SetCellValue(row, 2, "Paused.")
  109.             row += 1       
  110.  
  111.      
  112.     def button_empty(self, event):                
  113.         self.db_query("DELETE FROM tasks")
  114.         conn = sqlite3.connect(SchedulerDB)
  115.         c = conn.cursor()
  116.         print c.rowcount
  117.         conn.close()
  118.         self.refresh_grid()
  119.    
  120.        
  121.    
  122.     def button_run(self, event):
  123.         if threading.activeCount() < 2:
  124.             self.thread1=threading.Thread(target=self.thread, name="WoW", args=( None, ))
  125.             self.thread1.start()
  126.      
  127.  
  128.            
  129.     def db_query(self, query):
  130.         conn = sqlite3.connect(SchedulerDB)
  131.         c = conn.cursor()
  132.         c.execute(query)
  133.         conn.commit()
  134.         conn.close()
  135.         return c
  136.        
  137.     def disable(self):
  138.         self.unregister_actions()
  139.         self.delete_tab(self._panel)
  140.         self._panel = None
  141.  
  142.     def dump_suite(self, suite, indent):
  143.         print "Suite: %s" % suite
  144.         try:
  145.             #print "suite name: %s" % suite.name
  146.             #print "suite Directory: %s" % suite.directory
  147.            
  148.             self.li.append(str(indent * " " + " + " + str(suite.name)))  
  149.             for test in suite.children:
  150.                 if test.has_tests()!="True":
  151.                     self.dump_suite(test, indent+6)
  152.                 else:
  153.                     self.li.append(str(indent*" "+"    - "+str(test.name)))
  154.             for test in suite.testcase_table.tests:
  155.                 self.li.append(str(indent*" "+"    - "+str(test.name)))
  156.            
  157.         except:
  158.             print "dump_suite: Pass"
  159.             pass
  160.  
  161.     def enable(self):
  162.  
  163.         self.register_action(ActionInfo('&Scheduler', 'View', self.show, doc = 'Displays a tab Scheduler.'))
  164.         self.register_action(ActionInfo('Scheduler', 'Update', self.update, doc = ''))
  165.         self.register_action(ActionInfo('Scheduler', 'Run Paused Tasks', self.menu_execution,
  166.                                         icon = wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, (16, 16)),
  167.                                         doc = 'Adds the selection to existing programming.',
  168.                                         shortcut = "Ctrl-E"))
  169.  
  170.         self.subscribe(self.update, RideSaved, RideOpenSuite)
  171.         self.subscribe(self.on_tree_selection, RideTreeSelection)
  172.         self.show()
  173.  
  174.            
  175.     def execution(self, event, content): # en via de modificación por la realizacion de make command - Eliminar cuando este finalizado.
  176.         path = self.model.suite.source
  177.         try:
  178.             runner = runners[self.execution_combo.GetStringSelection()]
  179.             rows = self.task_grid.GetNumberRows()
  180.         except:
  181.             pass
  182.  
  183.         for item in content:
  184.             now = str(time.time()) + str(random.random())
  185.             selection = item
  186.             GuiIncludeValue = str(self.include_text.GetValue())
  187.             GuiExcludeValue = str(self.exclude_text.GetValue())
  188.             GuiVariableValue = str(self.variable_text.GetValue())  
  189.             GuiLogLevelValue = str(self.output_text.GetValue())
  190.             GuiCheckDebug = self.debug_cb.IsChecked()
  191.            
  192.             if selection[0] == "+":
  193.                 command = " --suite \"" + selection[2:] + "\""
  194.             else :              
  195.                 command = " --test \"" + selection[2:] + "\""
  196.                
  197.             if GuiIncludeValue != "":
  198.                 command += " --include " + GuiIncludeValue
  199.             if GuiExcludeValue != "":
  200.                 command += " --exclude " + GuiExcludeValue
  201.             if GuiVariableValue != "":
  202.                 command += " --variable " + GuiVariableValue
  203.            
  204.             command += " -W 90 "
  205.             if GuiLogLevelValue != "":
  206.                 if GuiCheckDebug:
  207.                     command += " -b \"" + GuiLogLevelValue + "\\"+COMPUTERNAME + ".txt\""
  208.                 command += " --outputdir \""+GuiLogLevelValue+"\""
  209.             command += " --log \"" + selection[2:] + now + ".html\" --report \"" + selection[2:] + \
  210.                                 "-report" + now + ".html\" --output \"" + selection[2:] + now + ".xml\""
  211.             self.task_grid.AppendRows()
  212.             #img = wx.Bitmap("python-logo.png", wx.BITMAP_TYPE_PNG)
  213.             bmp = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_OTHER, (16, 16))
  214.             imageRenderer = MyImageRenderer(bmp)
  215.             last = self.add_to_grid('', runner + command + " \"" + path + "\"", "Paused.", GuiLogLevelValue + \
  216.                                 "\\" + selection[2:] + now + ".html", GuiLogLevelValue + "\\" + selection[2:] + \
  217.                                 "-report" + now + ".html", GuiLogLevelValue + "\\" + COMPUTERNAME + ".txt")
  218.            
  219.            
  220.             self.task_grid.SetCellRenderer(rows, 0, imageRenderer)
  221.             self.task_grid.SetRowSize(rows, bmp.GetHeight() + 2)
  222.             self.task_grid.SetCellValue(rows, 0, str(last))
  223.             self.task_grid.SetCellValue(rows, 1, runner + command + " \"" + path + "\"")
  224.             self.task_grid.SetCellValue(rows, 2, "Paused.")
  225.             self.task_grid.SetCellValue(rows, 4, GuiLogLevelValue + "\\" + selection[2:] + "-report" + now + ".html")
  226.             self.task_grid.SetCellValue(rows, 3, GuiLogLevelValue + "\\" + selection[2:] + now + ".html")
  227.             if GuiCheckDebug:
  228.                 self.task_grid.SetCellValue(rows, 5, GuiLogLevelValue + "\\" + COMPUTERNAME + ".txt")
  229.            
  230.             rows += 1
  231.        
  232.         self.thread1 = threading.Thread(target=self.thread, name="WoW", args=( None, ))
  233.         if threading.activeCount() < 2:
  234.             self.thread1.start()
  235.  
  236.     def make_command(self, item):
  237.         path = self.model.suite.source
  238.         #path = os.path.dirname(path)
  239.         runner = runners[self.execution_combo.GetStringSelection()]
  240.         now = str(time.time()) + str(random.random())
  241.         GuiIncludeValue = str(self.include_text.GetValue())
  242.         GuiExcludeValue = str(self.exclude_text.GetValue())
  243.         GuiVariableValue = str(self.variable_text.GetValue())  
  244.         GuiLogLevelValue = str(self.output_text.GetValue())
  245.         GuiCheckDebug = str(self.debug_cb.IsChecked())
  246.        
  247.         if item[0] == "+":
  248.             command = " --suite \""+item[2:]+"\""
  249.         else :              
  250.             command = " --test \""+item[2:]+"\""
  251.         if GuiIncludeValue != "":
  252.             command += " --include " + GuiIncludeValue
  253.         if GuiExcludeValue != "":
  254.             command += " --exclude " + GuiExcludeValue
  255.         if GuiVariableValue != "":  
  256.             command += " --variable " + GuiVariableValue
  257.         command += " -W 90 --loglevel " + self.loglevel_combo.GetStringSelection()
  258.         #if (GuiLogLevelValue!=""): command = command+" --loglevel TRACE "
  259.         if (GuiCheckDebug == "True"):
  260.             command = command+" -b \""+GuiLogLevelValue+"\\"+COMPUTERNAME+".txt\""
  261.             command = command+" --outputdir \""+GuiLogLevelValue+"\""
  262.         #else :
  263.         #    command = command+" --loglevel TRACE -T "
  264.         command = runner+command+" --log \""+item[2:]+now+".html\" --report \""+item[2:]+"-report"+now+".html\" --output \""+item[2:]+now+".xml\" \""+path+"\""
  265.        
  266.         return command
  267.            
  268.     def menu_execution(self, event):
  269.         content = []
  270.         nodo = Plugin.get_selected_item(self)
  271.         if str(type(nodo)) == "<class 'robotide.model.tcuk.TestCase'>":
  272.             content.append("- "+str(nodo.name))
  273.         elif str(type(nodo)) == "<type 'NoneType'>":
  274.             return "There is nothing selected."
  275.         else:
  276.             try:
  277.                 content.append("+ "+str(Plugin.get_selected_datafile(self).longname))
  278.             except:
  279.                 return "The task is not executable."
  280.         self.execution(None,content)
  281.      
  282.     def on_cell_selection(self, event):
  283.         # Select cell, range of cells, rows and column and right click on the grid
  284.         row=event.GetRow()
  285.         col=event.GetCol()
  286.         event.Skip()
  287.         if col>2 and col<5:
  288.             if self.task_grid.GetCellValue(row, col)!="":
  289.                 #print self.task_grid.GetCellValue(row, col)
  290.                 sp = subprocess
  291.                 pr = subprocess.Popen("\""+self.task_grid.GetCellValue(row, col)+"\"", stdout=sp.PIPE, stderr=sp.STDOUT,shell=True)
  292.         if col == 5:
  293.             if self.task_grid.GetCellValue(row, col)!="":
  294.                 sp = subprocess
  295.                 pr = subprocess.Popen("python -m fileviewer \""+self.task_grid.GetCellValue(row, col)+"\"", stdout=sp.PIPE, stderr=sp.STDOUT,shell=True)
  296.                
  297.         if col==0:
  298.             task=[self.task_grid.GetCellValue(row, col)]
  299.             res=self.remove_confirmation(task)
  300.             if res == 5103 :
  301.                 for a in range(3,5):
  302.                    
  303.                     if self.task_grid.GetCellValue(row, a) != "" :  
  304.                         try:
  305.                             os.remove( self.task_grid.GetCellValue(row, a));
  306.                         except:
  307.                             print "NO se ha borrado"+self.task_grid.GetCellValue(row, a)
  308.                 print self.task_grid.GetCellValue(row, 0)
  309.                 conn.execute("DELETE FROM tasks WHERE id = " + str(self.task_grid.GetCellValue(row, 0)))
  310.                 conn.commit()
  311.                 self.task_grid.DeleteRows(row, 1)
  312.    
  313.     def on_ctrl_a(self, event):
  314.         self.debug_text.SelectAll()
  315.      
  316.     def on_delete(self, event):
  317.         fr, to = self.debug_text.GetSelection()
  318.         self.debug_text.Remove(fr, to)
  319.                
  320.     def on_remote_cb_check(self,event):
  321.         if self.remote_cb.IsChecked():
  322.             self.remoteuser_label.Enable()
  323.             self.remotepassword_label.Enable()
  324.             self.remotepc_text.Enable()
  325.             self.remoteuser_text.Enable()
  326.             self.remotepassword_text.Enable()
  327.         else:
  328.             self.remoteuser_label.Disable()
  329.             self.remotepassword_label.Disable()
  330.             self.remotepc_text.Disable()
  331.             self.remoteuser_text.Disable()
  332.             self.remotepassword_text.Disable()
  333.  
  334.  
  335.     def on_scheduler_cb_check(self,event):
  336.         if self.scheduler_cb.IsChecked():
  337.             self.scheduler_runtasks_label.Enable()
  338.             self.times_to_run.Enable()
  339.             self.scheduler_timesat_label.Enable()
  340.             self.date_to_run.Enable()
  341.         else:
  342.             self.scheduler_runtasks_label.Disable()
  343.             self.times_to_run.Disable()
  344.             self.scheduler_timesat_label.Disable()
  345.             self.date_to_run.Disable()
  346.    
  347.     def on_tree_selection(self, event):
  348.         if "Edit" in self.notebook.GetPageText(self.notebook.GetSelection()):
  349.             return
  350.         for i in range(self.notebook.GetPageCount()):
  351.             if "Edit" in self.notebook.GetPageText(i):
  352.                 print self.notebook.GetPage(i)
  353.                 self.notebook.show_tab(self.notebook.GetPage(i))
  354.            
  355.     def readlines(self,fd):
  356.         while True:
  357.             line = fd.readline()
  358.             if not line:
  359.                 break
  360.             yield line
  361.      
  362.     def refresh_grid(self):
  363.         rows = self.task_grid.GetNumberRows()
  364.        
  365.         if (rows > 0) :
  366.             self.task_grid.DeleteRows(0, rows)
  367.         index = 0
  368.         for n in conn.execute("SELECT * FROM tasks"):
  369.             if n[3] == "Running.":
  370.                 continue
  371.             self.task_grid.AppendRows()
  372.             self.task_grid.SetCellValue(index, 0, str(n[0]))
  373.             self.task_grid.SetCellValue(index, 1, str(n[2]))
  374.             self.task_grid.SetCellValue(index, 2, str(n[3]))
  375.             self.task_grid.SetCellValue(index, 3, str(n[4]))
  376.             self.task_grid.SetCellValue(index, 4, str(n[5]))
  377.             self.task_grid.SetCellValue(index, 5, str(n[6]))
  378.             bmp = None
  379.             if n[3] == "Passed.":
  380.                 bmp = wx.ArtProvider.GetBitmap(wx.ART_TICK_MARK, wx.ART_OTHER, (16, 16))
  381.                 self.task_grid.SetCellBackgroundColour(index, 3, "green")
  382.                 self.task_grid.SetCellBackgroundColour(index, 4, "green")
  383.                 self.task_grid.SetCellBackgroundColour(index, 5, "green")
  384.             elif n[3] == "Failed.":
  385.                 bmp = wx.ArtProvider.GetBitmap(wx.ART_ERROR, wx.ART_OTHER, (16, 16))
  386.                 self.task_grid.SetCellBackgroundColour(index, 3, "red")
  387.                 self.task_grid.SetCellBackgroundColour(index, 4, "red")
  388.                 self.task_grid.SetCellBackgroundColour(index, 5, "red")
  389.             elif n[3] == "Paused.":
  390.                 bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_OTHER, (16, 16))
  391.             imageRenderer = MyImageRenderer(bmp)
  392.             self.task_grid.SetCellRenderer(index, 0, imageRenderer)
  393.             self.task_grid.SetRowSize(index, bmp.GetHeight() + 2)
  394.            
  395.             index += 1
  396.             conn.commit()
  397.            
  398.     def remove_confirmation(self, task):
  399.        
  400.         dial = wx.MessageDialog(None, 'Want to remove the task  '+str(task)+' and its records \n',\
  401.             'Warning', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_EXCLAMATION)
  402.         return dial.ShowModal()
  403.            
  404.     def show(self, event=None):
  405.         if not self._panel:
  406.             self._create_panel()
  407.             self.add_tab(self._panel, "Scheduler")
  408.         #self.show_tab(self._panel)
  409.  
  410.     def thread(self, event):
  411.         contador = self.task_grid.GetNumberRows()
  412.         conta=0
  413.         while (conta < int(self.task_grid.GetNumberRows())):
  414.  
  415.             if (self.task_grid.GetCellValue(conta,2)!="Paused.") :
  416.                 conta=conta+1
  417.             else:
  418.                
  419.                 #print self.task_grid.GetCellValue(conta,2)
  420.                 conn = sqlite3.connect(SchedulerDB)
  421.                 #print self.task_grid.GetCellValue(conta,0)
  422.                 conn.execute("update tasks SET state = 'Running.' where id = "+self.task_grid.GetCellValue(conta,0))
  423.                 conn.commit()
  424.                 conn.close()
  425.                 self.task_grid.SetCellValue(conta,2, "Running.")
  426.                 bmp = wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, (16, 16))
  427.                 imageRenderer = MyImageRenderer(bmp)
  428.                 self.task_grid.SetCellRenderer(conta,0,imageRenderer)
  429.                 #self.task_grid.SetColSize(0,bmp.GetWidth()+2)
  430.                 self.task_grid.SetRowSize(conta,bmp.GetHeight()+2)
  431.                 commandtorun = self.task_grid.GetCellValue(conta, 1)
  432.                
  433.                 self.pr = subprocess.Popen(commandtorun, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,shell=True)
  434.                 self.color="green"
  435.                 for line in self.readlines(self.pr.stdout):
  436.                     self.debug_text.AppendText(unicode( line, "utf-8"))
  437.                     if line.count("Log:") > 0:
  438.                         print line,
  439.                         log = line[9:-2]
  440.                         self.task_grid.SetCellValue(conta,3, log)
  441.                         self.task_grid.SetCellBackgroundColour(conta, 3, self.color)
  442.                         self.db_query("UPDATE tasks SET log = '" + log + "' where id = " + self.task_grid.GetCellValue(conta,0))
  443.                         break;
  444.                     elif line.count("Report:") > 0:
  445.                         print line,
  446.                         Report = line[9:-2]
  447.                         self.task_grid.SetCellValue(conta,4, Report)
  448.                         self.task_grid.SetCellBackgroundColour(conta, 4, self.color)
  449.                         self.db_query("UPDATE tasks SET report = '" + Report + "' where id = " + self.task_grid.GetCellValue(conta,0))
  450.                     elif line.count("Debug:") > 0:
  451.                         print line,
  452.                         Debug = line[9:-2]
  453.                         self.task_grid.SetCellValue(conta,5, Debug)
  454.                         self.task_grid.SetCellBackgroundColour(conta, 5, self.color)
  455.                         self.db_query("UPDATE tasks SET debug = '" + Debug + "' where id = " + self.task_grid.GetCellValue(conta,0))
  456.                     elif line.count("FAIL") > 0:
  457.                         print line,
  458.                         self.color = "red"
  459.                     else:
  460.                         pass
  461.                        
  462.                 print "---------------"
  463.                
  464.                 bmp = None
  465.                 if self.color == "red":
  466.                     self.task_grid.SetCellValue(conta,2, "Failed.")
  467.                     self.db_query("UPDATE tasks SET state = 'Failed.' where id = " + self.task_grid.GetCellValue(conta,0))
  468.                     bmp = wx.ArtProvider.GetBitmap(wx.ART_ERROR, wx.ART_OTHER, (16, 16))
  469.                 else:
  470.                     self.task_grid.SetCellValue(conta,2, "Passed.")
  471.                     self.db_query("UPDATE tasks SET state = 'Passed.' where id = " + self.task_grid.GetCellValue(conta,0))
  472.                     bmp = wx.ArtProvider.GetBitmap(wx.ART_TICK_MARK, wx.ART_OTHER, (16, 16))
  473.                
  474.                 imageRenderer = MyImageRenderer(bmp)
  475.                 self.task_grid.SetCellRenderer(conta,0,imageRenderer)
  476.                 #self.task_grid.SetColSize(0,bmp.GetWidth()+2)
  477.                 self.task_grid.SetRowSize(conta,bmp.GetHeight()+2)
  478.                
  479.                 print "---------------"
  480.                  
  481.     def update(self,message):
  482.         """Handle publications from the main frame"""
  483.         #application = self.manager._application
  484.         #model = self.model()
  485.         suite = self.model.suite
  486.         self.li=[]
  487.         self.test_suite_tree.Clear()
  488.         self.dump_suite(suite, 0)
  489.         self.test_suite_tree.InsertItems(self.li,0)
  490.         self.test_suite_tree.Select(0)
  491.  
  492.     def _create_panel(self):
  493.         """Add a tab for this plugin to the notebook"""
  494.         self._panel = wx.Panel(self.notebook)
  495.         sizer = wx.GridBagSizer(5, 5)
  496.        
  497.         self.execution_combo = wx.ComboBox(self._panel, choices=runners.keys(), style=wx.CB_READONLY)
  498.         self.execution_combo.SetStringSelection(runners.keys()[1])
  499.         sizer.Add(self.execution_combo, (0, 0), (1, 2), wx.EXPAND)
  500.        
  501.         self.test_suite_label = wx.StaticText(self._panel, label="--test && --suite")
  502.         sizer.Add(self.test_suite_label, (1, 0))
  503.        
  504.         self.test_suite_tree = wx.ListBox(self._panel, style=wx.LB_EXTENDED|wx.LB_HSCROLL)
  505.         sizer.Add(self.test_suite_tree, (2, 0), (11, 2), wx.EXPAND)
  506.        
  507.         self.include_label = wx.StaticText(self._panel, label=" --include tag")
  508.         sizer.Add(self.include_label, (2, 2))
  509.         self.include_text = wx.TextCtrl(self._panel)
  510.         sizer.Add(self.include_text, (3, 2), flag=wx.EXPAND)
  511.        
  512.         self.exclude_label = wx.StaticText(self._panel, label=" --exclude tag")
  513.         sizer.Add(self.exclude_label, (2, 3))
  514.         self.exclude_text = wx.TextCtrl(self._panel)
  515.         sizer.Add(self.exclude_text, (3, 3), flag=wx.EXPAND)
  516.        
  517.         self.variable_label = wx.StaticText(self._panel, label=" --variable var_name:var_value")
  518.         sizer.Add(self.variable_label, (4, 2))
  519.         self.variable_text = wx.TextCtrl(self._panel)
  520.         sizer.Add(self.variable_text, (5, 2), flag=wx.EXPAND)
  521.        
  522.         self.loglevel_label = wx.StaticText(self._panel, label=" --loglevel value")
  523.         sizer.Add(self.loglevel_label, (4, 3))
  524.         self.loglevel_combo = wx.ComboBox(self._panel, choices=["NONE", "WARN", "INFO", "DEBUG", "TRACE"], style=wx.CB_READONLY)
  525.         self.loglevel_combo.SetStringSelection("INFO")
  526.         sizer.Add(self.loglevel_combo, (5, 3), flag=wx.EXPAND)
  527.        
  528.         self.output_label = wx.StaticText(self._panel, label=" --outputdir dir")
  529.         sizer.Add(self.output_label, (6, 2))
  530.         self.output_text = wx.TextCtrl(self._panel, value="logs\\%s" % today)
  531.         sizer.Add(self.output_text, (7, 2), (1, 2), wx.EXPAND)
  532.        
  533.         self.debug_cb = wx.CheckBox(self._panel, label="Debug -T")
  534.         self.debug_cb.SetValue(True)
  535.         sizer.Add(self.debug_cb, (6, 3))
  536.        
  537.         self.remote_cb = wx.CheckBox(self._panel, label="Remote Computer")
  538.         self.remote_cb.Bind(wx.EVT_CHECKBOX,self.on_remote_cb_check)
  539.         sizer.Add(self.remote_cb, (8, 2))
  540.         self.remotepc_text = wx.TextCtrl(self._panel)
  541.         sizer.Add(self.remotepc_text, (9, 2), (1, 2), wx.EXPAND)
  542.        
  543.         self.remoteuser_label = wx.StaticText(self._panel, label="User:")
  544.         sizer.Add(self.remoteuser_label, (10, 2))
  545.         self.remoteuser_text = wx.TextCtrl(self._panel)
  546.         sizer.Add(self.remoteuser_text, (11, 2), flag=wx.EXPAND)
  547.        
  548.         self.remotepassword_label = wx.StaticText(self._panel, label="Password:")
  549.         sizer.Add(self.remotepassword_label, (10, 3))
  550.         self.remotepassword_text = wx.TextCtrl(self._panel, style=wx.TE_PASSWORD)
  551.         sizer.Add(self.remotepassword_text, (11, 3), flag=wx.EXPAND)
  552.        
  553.         # Initially disable all remote PC "stuff" since checkbox is not checked by default
  554.         self.remoteuser_label.Disable()
  555.         self.remotepassword_label.Disable()
  556.         self.remotepc_text.Disable()
  557.         self.remoteuser_text.Disable()
  558.         self.remotepassword_text.Disable()
  559.        
  560.         task_notebook = wx.Notebook(self._panel)
  561.         self.task_panel = wx.Panel(task_notebook)
  562.         self.execution_label = wx.StaticText(self.task_panel, label="Executing: ")
  563.         self.task_grid = wx.grid.Grid(self.task_panel)
  564.        
  565.         self.task_grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.on_cell_selection)
  566.         self.task_grid.CreateGrid(0,6)
  567.         self.task_grid.SetRowLabelSize(0)
  568.         self.task_grid.SetColLabelValue(0, "")
  569.         self.task_grid.SetColLabelValue(1, "Command")
  570.         self.task_grid.SetColLabelValue(2, "State")
  571.         self.task_grid.SetColLabelValue(3, "Log")
  572.         self.task_grid.SetColLabelValue(4, "Report")
  573.         self.task_grid.SetColLabelValue(5, "Debug")
  574.         self.task_grid.SetColSize(0,20)
  575.         self.task_grid.SetColSize(1,300)
  576.         self.task_grid.SetColSize(2,70)
  577.         self.task_grid.SetColSize(3,100)
  578.         self.task_grid.SetColSize(4,100)
  579.         self.task_grid.SetColSize(5,100)
  580.         self.refresh_grid()
  581.        
  582.         self.log_panel = wx.Panel(task_notebook)
  583.         self.log_text = wx.TextCtrl(self.log_panel, style=wx.TE_MULTILINE)
  584.        
  585.         self.debug_panel = wx.Panel(task_notebook)
  586.         font = wx.Font(9, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
  587.         self.debug_text = wx.TextCtrl(self.debug_panel, style=wx.TE_MULTILINE)
  588.         self.debug_text.SetFont(font)
  589.         ranId1 = wx.NewId()
  590.         self.debug_panel.Bind(wx.EVT_MENU, self.on_ctrl_a, id=ranId1)
  591.         ranId2 = wx.NewId()
  592.         self.debug_panel.Bind(wx.EVT_MENU, self.on_delete, id=ranId2)
  593.         accel_tbl = wx.AcceleratorTable([ (wx.ACCEL_CTRL, ord('A'), ranId1), (wx.ACCEL_NORMAL, wx.WXK_DELETE, ranId2)])
  594.         self.debug_panel.SetAcceleratorTable(accel_tbl)
  595.  
  596.         nb_task_sizer = wx.GridBagSizer()
  597.         nb_task_sizer.Add(self.execution_label, (0,0), flag=wx.EXPAND)
  598.         nb_task_sizer.Add(self.task_grid, (1,0), flag=wx.EXPAND)
  599.         nb_task_sizer.AddGrowableCol(0)
  600.         nb_task_sizer.AddGrowableRow(1)
  601.        
  602.         nb_log_sizer = wx.GridSizer(1, 1)
  603.         nb_log_sizer.Add(self.log_text, flag=wx.EXPAND)
  604.         nb_debug_sizer = wx.GridSizer(1, 1)
  605.         nb_debug_sizer.Add(self.debug_text, flag=wx.EXPAND)
  606.        
  607.         self.task_panel.SetSizer(nb_task_sizer)
  608.         self.log_panel.SetSizer(nb_log_sizer)
  609.         self.debug_panel.SetSizer(nb_debug_sizer)
  610.        
  611.         task_notebook.AddPage(self.task_panel, "Task")
  612.         task_notebook.AddPage(self.log_panel, "Log")
  613.         task_notebook.AddPage(self.debug_panel, "Debug")
  614.  
  615.         scheduler_panel = wx.Panel(self._panel)
  616.         scheduler_sizer = wx.BoxSizer()
  617.         self.scheduler_cb = wx.CheckBox(scheduler_panel, label="Scheduler")
  618.         self.scheduler_cb.Bind(wx.EVT_CHECKBOX,self.on_scheduler_cb_check)
  619.         self.scheduler_runtasks_label = wx.StaticText(scheduler_panel, label=" Run tasks ")
  620.         self.times_to_run = wx.SpinCtrl(scheduler_panel)
  621.         self.scheduler_timesat_label = wx.StaticText(scheduler_panel, label=" times at ")
  622.         self.date_to_run = wx.DatePickerCtrl(scheduler_panel)
  623.        
  624.         # Initially disable all scheduling "stuff" since checkbox is not checked by default
  625.         self.scheduler_runtasks_label.Disable()
  626.         self.times_to_run.Disable()
  627.         self.scheduler_timesat_label.Disable()
  628.         self.date_to_run.Disable()
  629.        
  630.         scheduler_sizer.Add(self.scheduler_cb)
  631.         scheduler_sizer.Add(self.scheduler_runtasks_label)
  632.         scheduler_sizer.Add(self.times_to_run)
  633.         scheduler_sizer.Add(self.scheduler_timesat_label)
  634.         scheduler_sizer.Add(self.date_to_run)
  635.         scheduler_panel.SetSizer(scheduler_sizer)
  636.        
  637.         sizer.Add(scheduler_panel, (12, 2), (1, 2))
  638.                
  639.         button_panel = wx.Panel(self._panel)
  640.        
  641.         self.addtask_button = wx.Button(button_panel, label="Add Tasks")
  642.         self.addtask_button.Bind(wx.EVT_BUTTON, self.button_add)
  643.         self.runtasks_button = wx.Button(button_panel, label="Run Paused Tasks")
  644.         self.runtasks_button.Bind(wx.EVT_BUTTON, self.button_run)
  645.         self.emptytasks_button = wx.Button(button_panel, label="Empty Tasks")
  646.         self.emptytasks_button.Bind(wx.EVT_BUTTON, self.button_empty)
  647.        
  648.         button_sizer = wx.BoxSizer()
  649.         button_sizer.Add(self.addtask_button)
  650.         button_sizer.Add(self.runtasks_button)
  651.         button_sizer.Add(self.emptytasks_button)
  652.         button_panel.SetSizer(button_sizer)
  653.        
  654.         sizer.Add(button_panel, (14, 1))
  655.         sizer.Add(task_notebook, (15, 0), (1, 4), wx.EXPAND)
  656.        
  657.         sizer.AddGrowableCol(0)
  658.         sizer.AddGrowableCol(1)
  659.         sizer.AddGrowableCol(2)
  660.         sizer.AddGrowableCol(3)
  661.         sizer.AddGrowableRow(15)
  662.        
  663.        
  664.         self._panel.SetSizer(sizer)
  665.  
  666.  
  667.  
  668.     def _absnorm(self, path):
  669.         return os.path.normpath(os.path.abspath(path.replace('/', os.sep)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement