Commits

Moises Henriquez committed 6e886d6

Added functionality to add/remove build jobs

  • Participants
  • Parent commits e24c4dd

Comments (0)

Files changed (3)

 import gtk
 import bbot
 import dbconn
+import dialogs
 
 gtk.gdk.threads_init()
 todo = dbconn.refresh_todo()
             '<b>Source Type: </b>%s'% self.src.type)
 
 class mWindow(gtk.Window):
+    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)
+        dsc_ = self._todo_list.get_value(itr, 2)
+        
+        
+        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'''
+        if not self.selected_job: 
+            dia = dialogs.info(message='Please select a job first', parent=self)
+            if dia.run(): dia.destroy()
+            return
+        ### Present some kind of dialog to verify before you do this
+        conf = dialogs.question(parent=self,
+        question = 'Are you sure you want to delete job %s?' %self.selected_job )
+        
+        res = conf.run()
+        conf.destroy()
+        if res == gtk.RESPONSE_CANCEL:
+            return
+        
+        ### Only continue if the action has been verified by the dialog.
+        sql = "DELETE FROM todo WHERE id='%s'"% self.selected_job
+        dbconn.push_data(sql)
+        self._todo_list.clear()
+        self.refresh_task_list()
     def __init__(self):
+        self.selected_job = None
         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+        self.set_default_size(600,400)
+        self.set_position(gtk.WIN_POS_CENTER)
         self.set_property('title', 'buildbot')
         body = gtk.VBox(False, 4)
         banner = gtk.Label()
             treestore.append(None, [row[0], row[1], row[2]])
 
         tv = gtk.TreeView(treestore)
+        tv.connect('cursor-changed', self.treeview_click)
         col = gtk.TreeViewColumn('Task ID')
         col1 = gtk.TreeViewColumn('Source URI')
         col2 = gtk.TreeViewColumn('Description URI')
         bt_remove = gtk.Button('Delete Job')
         img1.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_BUTTON)
         bt_remove.set_image(img1)
+        bt_remove.connect('clicked', self.delete_job, self.selected_job)
         
         bt_edit = gtk.Button('Edit Job')
         img2 = gtk.Image()
         self.add(body)
         self.connect('destroy', gtk.main_quit)
     def _show_add_form(self, widget):
-        aw = JobWindow()
-        aw.show_all()
+        ###aw = JobWindow()
+        ###aw.show_all()
+        ##print aw.tarball
+        aj = _AddJobWindow(parent=self)
+        res = aj.run()
+        if res == gtk.RESPONSE_ACCEPT:
+            self.add_job(aj.srcpath, aj.descpath)
+        
+        aj.destroy()
     
-    def add_job(self, widget):
-        pass
+    def add_job(self, srcpath, descpath):
+        sql = 'INSERT INTO todo (srcpath, descpath) VALUES ("%s","%s")'% \
+        (srcpath, descpath)
+        ## Push the sql data into the database
+        dbconn.push_data(sql)
+        ## Refresh the GUI
+        self.refresh_task_list()
+        
         
     
     def refresh_task_list(self):
         _lst = dbconn.refresh_todo()
+        self._todo_list.clear()
         for row in _lst:
             self._todo_list.append(None, [row[0], row[1], row[2]])
+
+class _AddJobWindow(gtk.Dialog):
+    def __init__(self, parent):
+        self.srcpath = ''
+        self.descpath = ''
+        gtk.Dialog.__init__(self, parent=parent, buttons=(gtk.STOCK_OK, 
+            gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, 
+            gtk.RESPONSE_CANCEL), title='Add new Job')
+        self.set_default_size(600,200)
+        self.resize(600,200)
+        self.set_position(gtk.WIN_POS_CENTER)
+        dbody = self.vbox
+        
+        hdr = gtk.Label()
+        hdr.set_property('use-markup', True)
+        hdr.set_property('label', 'Add new job')
+        hdr.set_property('xalign', 0.0)
+        dbody.pack_start(hdr, True, True, 2)
+        
+        blnk = gtk.Label()
+        dbody.pack_start(blnk)
+        srcline = gtk.HBox(False, 4)
+        dbody.pack_start(srcline, False, False, 2)
+        src_line_lbl = gtk.Label()
+        src_line_lbl.set_property('xalign', 0.0)
+        src_line_lbl.set_property('label', 'URI to Source')
+        srcline.pack_start(src_line_lbl, False, False, 0)
+        src_line_txt = gtk.Entry()
+        srcline.pack_start(src_line_txt, True, True, 2)
+        src_line_btn = gtk.Button(stock=gtk.STOCK_OPEN)
+        src_line_btn.connect('clicked', self.load_src)
+        srcline.pack_start(src_line_btn, False, False, 2)
+        self._src_entry = src_line_txt
+        
+        descline = gtk.HBox(False, 4)
+        dsc_line_lbl = gtk.Label()
+        dsc_line_lbl.set_property('xalign', 0.0)
+        dsc_line_lbl.set_property('label', 'URI to Description')
+        descline.pack_start(dsc_line_lbl, False, False, 0)
+        dsc_line_txt = gtk.Entry()
+        descline.pack_start(dsc_line_txt, True, True, 2)
+        dsc_line_btn = gtk.Button(stock=gtk.STOCK_OPEN)
+        dsc_line_btn.connect('clicked', self.load_desc)
+        descline.pack_start(dsc_line_btn, False, False, 2)
+        self._desc_entry = dsc_line_txt
+        
+        dbody.pack_start(descline, False, False, 2)
         
 
-class JobWindow(gtk.Window):
-    def __init__(self):
-        gtk.Window.__init__(self)
-        body = gtk.VBox(False, 4)
-        self.set_title('Add New Job')
-        top_label = gtk.Label('Add new job to queue')
-        top_label.set_property('xalign', 0.0)
-        blnk = gtk.Label()
-        body.pack_start(blnk, False, False, 0)
-        body.pack_start(top_label, False, False, 0)
-        blnk = gtk.Label()
-        body.pack_start(blnk, False, False, 0)
-        
-        srcline = gtk.HBox(False, 4)
-        srclbl = gtk.Label('URI to Source')
-        srcline.pack_start(srclbl, False, False, 2)
-        src_entry = gtk.Entry()
-        self.srcentry = src_entry
-        srcline.pack_start(src_entry, True, True, 2)
-        src_loader = gtk.Button(stock=gtk.STOCK_OPEN)
-        src_loader.connect('clicked', self.load_source)
-        srcline.pack_start(src_loader, False, False, 2)
-        
-        body.pack_start(srcline, False, False, 2)
-        
-        descline = gtk.HBox(False, 4)
-        desclbl = gtk.Label('URI to Description')
-        desc_entry = gtk.Entry()
-        self.desc_entry = desc_entry
-        desc_loader = gtk.Button(stock=gtk.STOCK_OPEN)
-        desc_loader.connect('clicked', self.load_description)
-        
-        descline.pack_start(desclbl, False, False, 2)
-        descline.pack_start(desc_entry, True, True, 2)
-        descline.pack_start(desc_loader, False, False, 2)
-        
-        blnk = gtk.Label()
-        
-        body.pack_start(descline, False, False, 2)
-        body.pack_start(blnk, True, True, 0)
-        
-        self.path_to_source = None
-        self.path_to_desc = None
-        
-        toolbar = gtk.HBox(False, 2)
-        bt_OK = gtk.Button(stock=gtk.STOCK_OK)
-        bt_Cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
-        bt_Cancel.connect('clicked', lambda _: self.destroy())
-        
-        toolbar.pack_end(bt_OK, False, False, 2)
-        toolbar.pack_end(bt_Cancel, False, False, 2)
-        
-        body.pack_start(toolbar, False, False, 4)
-        self.add(body)
-
-    def load_source(self, widget):
+        self.show_all()
+    
+    def load_src(self, widget):
         dia = gtk.FileChooserDialog(buttons = (gtk.STOCK_OPEN,
         gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
         dia.set_title('Select source file')
-
-        if dia.run():
-            self.path_to_source = dia.get_filename()
-            self.srcentry.set_text(self.path_to_source)
+        filt = gtk.FileFilter()
+        filt.set_name('Compressed Archives')
+        filt.add_pattern('*.tar.*')
+        dia.add_filter(filt)
+        
+        ans = dia.run()
+        if ans == gtk.RESPONSE_ACCEPT:
+            self.srcpath = dia.get_filename()
         else:
-            self.path_to_source = ""
-            self.srcentry.set_text("")
-            
+            self.srcpath= ''
+        
+        self._src_entry.set_text(self.srcpath)
         dia.destroy()
-    def load_description(self, widget):
+    
+    def load_desc(self, widget):
         dia = gtk.FileChooserDialog(buttons = (gtk.STOCK_OPEN,
         gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
-        if dia.run():
-            self.path_to_desc = dia.get_filename()
-            self.desc_entry.set_text(self.path_to_desc)
+        dia.set_title('Select Description File')
+        
+        ans = dia.run()
+        if ans == gtk.RESPONSE_ACCEPT:
+            self.descpath = dia.get_filename()
         else:
-            self.path_to_desc = ""
-            self.desc_entry.set_text(self.path_to_desc)
+            self.descpath = ''
         
+        self._desc_entry.set_text(self.descpath)
         dia.destroy()
         
-        
+
         
         
         
 #    GNU General Public License for more details.
 #
 #    You should have received a copy of the GNU General Public License
-#    along with vpackager.  If not, see <http://www.gnu.org/licenses/>.
+#    along with vpackager.  If not, see <http://www.gnu.org/lici
 
 import MySQLdb as dbase
 
+#!/usr/bin/env python
+
+#    This file is part of vpackager.
+#
+#    vpackager is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v2 as published by
+#    the Free Software Foundation.
+#
+#    vpackager is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with vpackager.  If not, see <http://www.gnu.org/licenses/>.
+
+import gtk
+
+class question(gtk.MessageDialog):
+    def __init__(self, question, parent):
+        gtk.MessageDialog.__init__(self,
+            type = gtk.MESSAGE_QUESTION,
+            parent = parent)
+        self.set_markup(question)
+        self.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_ACCEPT,
+            gtk.STOCK_NO, gtk.RESPONSE_CANCEL)
+
+class info(gtk.MessageDialog):
+    def __init__(self, message, parent):
+        gtk.MessageDialog.__init__(self,
+            type = gtk.MESSAGE_INFO,
+            parent = parent)
+        self.set_markup(message)
+        self.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
+