Commits

Moises Henriquez committed 6cb1274

Provided safe and forced exit

Comments (0)

Files changed (3)

src/vpackager/bot.py

 import urllib
 import time
 import preferences
+import psutil
 
 __author__ = 'M0E-lnx'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
 
     def PlayOutput(self, data):
         gtk.gdk.threads_enter()
-        buf = self.textview.get_buffer()
-        buf.insert(buf.get_end_iter(), data)
-        # scroll the lines if necessary
-        vad = self.scrl.get_vadjustment()
-        newpos = vad.get_upper() - vad.get_page_size()
-        vad.set_value(newpos)
-        self.scrl.set_vadjustment(vad)
+        try:
+            buf = self.textview.get_buffer()
+            buf.insert(buf.get_end_iter(), data)
+            # scroll the lines if necessary
+            vad = self.scrl.get_vadjustment()
+            newpos = vad.get_upper() - vad.get_page_size()
+            vad.set_value(newpos)
+            self.scrl.set_vadjustment(vad)
+        except:
+            pass
         gtk.gdk.threads_leave()
 
     def _get_output_display(self):
         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
         self.dbase_model = dbase_model
         self.RUN_BOT = False
-        self.CheckDatabase()
         self.body = gtk.VBox()
         datadir = os.path.dirname(os.path.abspath(__file__))
         datadir = os.path.join(datadir, 'data')
         self.body.pack_start(self.tabstrip, True, True, 2)
         self.add(self.body)
         self.show_all()
-        self.connect('destroy', gtk.main_quit)
+        #self.connect('destroy', self._exit)
+        self.connect('delete-event', self._exit)
         self.set_size_request(700,400)
 
         # Connect the start/stop buttons
         self.dispatcher = Dispatcher(model = self.dbase_model,
                                      view = self.bot_tab)
 
+        self.CheckDatabase()
+
         # Force initial display of the queue and history
         self.dbase_model.RefreshQueue()
         self.dbase_model.RefreshHistory()
 
     def CheckDatabase(self):
         """ Run a sanity check and make sure the databse tables exist"""
+        self.dbase_model._cleanup_history()
         if self.dbase_model.verify_tables() is True:
             return self.dbase_model.CreateTables()
 
 
         return dia.destroy()
 
-    def _exit(self, widget=None):
-        self.bot_tab.RUN_BOT = False
-        time.sleep(0.25)
+    def _force_exit(self):
+        """ Force close the application """
+        parent = psutil.Process(os.getpid())
+        for child in parent.get_children():
+            child.kill()
+        parent.kill()
         self.dbase_model.close()
         return gtk.main_quit()
 
+
+    def _exit(self, widget=None, event=None):
+        if self.RUN_BOT:
+            # Warn the user about running tasks
+            msg = "The build bot is currently running. Are you sure you "\
+                  "want to quit anyway?"
+            dia = guitools.message.Question(text=msg, parent=self)
+            res = dia.run()
+            dia.hide()
+            if res == gtk.RESPONSE_YES:
+                # Force quit
+                return self._force_exit()
+            else:
+                return True
+        else:
+            self.RUN_BOT = False
+            time.sleep(0.25)
+            self.dbase_model.close()
+            return gtk.main_quit()
+
     def _show_about(self, widget=None):
         """Display the about window"""
         dia = guitools.About()

src/vpackager/dbutils.py

             return False
         return True
 
+    def _cleanup_history(self):
+        """ Make sure all packages that did not finish correctly are marked
+        as failed"""
+        db, cursor = self._open()
+        cursor.execute('''UPDATE history SET result="Fail" WHERE result="Running"''')
+        db.commit()
+        self.close()
+        self.notify(self.GetHistory(), group='history')
+
     def CreateTables(self):
         """Create the essential tables for the vpackager environment. Should
         only need to be ran once"""
             result from history where result="Success"'''
         elif filter in ('failed', 'Failed'):
             sql = ''' select id, app, ver, release, buildstart, buildend,
-            result from history where result="Failed"'''
+            result from history where result="Fail"'''
         else:
             self.close()
             return self.notify(self.GetHistory(), group='history')

src/vpackager/viewcontrollers.py

         return self.model.RefreshHistory()
 
     def apply_filter(self, widget=None, filter=None):
-	return self.model.FilterHistory(filter)
+        return self.model.FilterHistory(filter)
 
     def connect_signals(self):
         # Connect buttons
         self.view.connect_item('about_task', self._about_task_event)
         self.view.connect_item('wipe_history', self._wipe_history_event)
-	self.view.connect_item('filter_all', self.apply_filter, 'all')
-	self.view.connect_item('filter_successful', self.apply_filter,
-			       'successful')
-	self.view.connect_item('filter_failed', self.apply_filter, 'failed')
+        self.view.connect_item('filter_all', self.apply_filter, 'all')
+        self.view.connect_item('filter_successful', self.apply_filter,
+                               'successful')
+        self.view.connect_item('filter_failed', self.apply_filter, 'failed')
         # Connect menu items.
         self.view.rc_menu.connect_item('about_job', self._about_task_event)
         self.view.rc_menu.connect_item('rebuild_job', self._rebuild_job_event)
     def _view_build_log_event(self, widget=None):
         """ Display the build log if it is still present"""
         details = self.model.GetTaskDetails(self.view._selectedjob)
-        if not os.path.exists(details['stdout']):
+        if not details['stdout']:
+            dia = guitools.message.Error(
+                text = 'Build log for this job is not available.',
+                parent = self._parentwindow)
+            if dia.run():
+                return dia.destroy()
+        elif not os.path.exists(details['stdout']):
             dia = guitools.message.Error(
                 parent = self._parentwindow,
                 text = \
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.