Commits

Moises Henriquez  committed 4270c53

Small changes / added some docstrings

  • Participants
  • Parent commits 0e7c8cf

Comments (0)

Files changed (3)

 import dialogs
 
 gtk.gdk.threads_init()
-todo = dbconn.refresh_todo()
+todo = None #dbconn.refresh_todo()
 
 _busy = False
-_dbchange = False
+
 class Monitor(threading.Thread):
     def __init__(self, label):
         super(Monitor, self).__init__()
         
 
 class tbp(threading.Thread):
+    '''Threaded build process.'''
     def __init__(self, src):
         global _busy
         global w
         
 
 class dispatcher(threading.Thread):
+    '''Create threaded build objects one at a time and deploy them'''
     def __init__(self):
         global todo
         global _busy
     def update_status(self, status):
         w.info_label3.set_text(status)
 
+class guiMonitor(threading.Thread):
+    '''Monitor the gridlist in the GUI'''
+    def __init__(self, f):
+        self.f = f
+        threading.Thread.__init__(self, name = 'GuiMonitor')
+    
+    def run(self):
+        global _busy
+        while _busy is True:
+            time.sleep(5) # Refresh the GUI every 5 seconds
+            self.f()
+        
 
 class mWindow(gtk.Window):
+    '''Main top level GUI'''
     def treeview_click(self, treeview):
-        #print 'tick'
+    
         sel,itr = treeview.get_selection().get_selected()
         id = self._todo_list.get_value(itr, 0)
         src_ = self._todo_list.get_value(itr, 1)
         self.selected_job = id
         self.selected_job_src = src_
         self.selected_job_dsc = dsc_
-        #sql = "DELETE FROM todo WHERE id='%s'"% id
-        #print sql
-        #print self._todo_list.get_value(itr, 0)
         
     def delete_job(self, widget, job_id):
         '''Delete a job'''
         self._todo_list = treestore
         
         
+        # Setup a thread that monitors the database so that when a build is done
+        # the gui is automagically updated.
+        # This thread only runs when the build process is running.
+        
+        gmon = guiMonitor(self.refresh_task_list)
+        gmon.start()
+        
+        
         ## Get the todo list from the database:
         _lst = dbconn.refresh_todo()
-        for row in _lst:
-            treestore.append(None, [row[0], row[1], row[2]])
+        if _lst == 1 or _lst is None:
+            msgerr = dialogs.error(message='Unable to connect to mysql server', parent=self)
+            if msgerr.run(): msgerr.destroy()
+            import sys
+            sys.exit()
+        else:
+            
+            for row in _lst:
+                treestore.append(None, [row[0], row[1], row[2]])
 
         
         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
         banner.set_property('label', 'Welcome to the buildbot')
         banner.set_property('xalign', 0.0)
         
-        body.pack_start(banner, False, False, 4)
+        hbanner = gtk.HBox(False, 4)
+        hbanner.pack_start(banner, True, True, 4)
+        body.pack_start(hbanner, False, False, 0)
         blank = gtk.Label()
         body.pack_start(blank, False, False, 4)
         frm_todo = gtk.Frame('Scheduled Builds')
         col.add_attribute(cell, 'text', 0)
         col1.add_attribute(cell1, 'text', 1)
         col2.add_attribute(cell2, 'text', 2)
-        tv.set_search_column(0)
-        col.set_sort_column_id(0)
-        tv.set_reorderable(True)
+
         sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
         sw.add(tv)
         ### End of tree, Lets add some action buttons in the same frame
         toolbar_frame = gtk.Frame()
         task_toolbar = gtk.HBox(False, 4)
         bt_addtask = gtk.Button(label='New Job')
-        #bt_addtask.connect('clicked', self.sample_add)
         bt_addtask.connect('clicked', self._show_add_form)
         img = gtk.Image()
         img.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
 
         
 class _AddJobWindow(gtk.Dialog):
+    '''Add task dialog'''
     def __init__(self, parent):
         self.srcpath = ''
         self.descpath = ''
         dia.destroy()
         
 class JobEdit(_AddJobWindow):
+    '''Edit task dialog'''
     def __init__(self, parent, id, srcpath, descpath):
         _AddJobWindow.__init__(self, parent=parent)
         self.set_title('Edit Task')
         self._desc_entry.set_text(descpath)
         self.header.set_text('Edit existing task on to-do list')
 
-        
-        
-        
-#w = gui()
-w = mWindow()
-w.statusbar.push(0, 'Idle')
-w.show_all()
-tmon = Monitor(w.info_label1)
-tmon.start()
-gtk.gdk.threads_enter()
-gtk.main()
-gtk.gdk.threads_leave()
+if __name__ == '__main__':
+    w = mWindow()
+    w.statusbar.push(0, 'Idle')
+    w.show_all()
+    tmon = Monitor(w.info_label1)
+    tmon.start()
+    gtk.gdk.threads_enter()
+    gtk.main()
+    gtk.gdk.threads_leave()
 
-_busy = False
+    _busy = False
 #    along with vpackager.  If not, see <http://www.gnu.org/lici
 
 import MySQLdb as dbase
+from _mysql_exceptions import *
 
 db = None
 
 def open_connection():
+    """ Convenience method to open the connection to the database"""
     global db
-    db = dbase.connect(host='localhost', user='root', db='buildbot')
+    try:
+        db = dbase.connect(host='localhost', user='root', db='buildbot')
+    except OperationalError:
+        print "Unable to open connection to mysql database. is mysql running?"
+        return 1
     return 0
 
 def close_connection():
 def refresh_todo():
     '''Read the todo list from the database'''
     global db
-    open_connection()
+    if open_connection() > 0: return 1
     if db.cursor is None: return 1
     cursor = db.cursor()
     cursor.execute("""SELECT * FROM todo ORDER BY id""")
 
 def push_data(sql_data):
     global db
-    #print sql_data
+    
     open_connection()
     cursor = db.cursor()
     cursor.execute(sql_data)
         self.set_markup(question)
         self.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_ACCEPT,
             gtk.STOCK_NO, gtk.RESPONSE_CANCEL)
+        self.set_title('Question')
 
 class info(gtk.MessageDialog):
     def __init__(self, message, parent):
             parent = parent)
         self.set_markup(message)
         self.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
+        self.set_title('Info')
+        
+class error(gtk.MessageDialog):
+    def __init__(self, message, parent):
+        gtk.MessageDialog.__init__(self,
+            type = gtk.MESSAGE_ERROR,
+            parent = parent)
+        self.set_markup(message)
+        self.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
+        self.set_position(gtk.WIN_POS_CENTER)
+        self.set_title('Error')