Commits

Moises Henriquez committed 4af88ba

Added support to install a previously built package

Comments (0)

Files changed (1)

src/vpackager/guitools.py

 import message
 import dbutils
 import preferences
+import glob
+import bottools
+import threading
+import time
+
 
 __author__ = 'M0E-lnx'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
 
         return sw
 
+class ProgressDialog(gtk.Dialog):
+    """small dialog showing a progresssbar while the package is being installed """
+    def __init__(self, banner, command):
+        gtk.Dialog.__init__(self)
+        self.set_title('Installing package')
+        lb = gtk.Label(banner)
+        self.bannerlabel = lb
+        self.job = bottools.Execute(command)
+        #self.job.observer.add_callback(self.pulse)
+        self.body = self.get_content_area()
+        self.body.pack_start(lb, False, True, 2)
+        self.pbar = gtk.ProgressBar()
+        self.body.pack_start(self.pbar, False, True, 2)
+        self.set_has_separator(True)
+        self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
+        self.actuator = threading.Thread(target=self.pulse, args=())
+        self.show_all()
+        self.PULSE=False
+        #self.actuator.start()
+        #self.job.run()
+        #self.PULSE = False
+    def __clear_status(self, data):
+        if self.job._popen_running:
+            pass
+        else:
+            self.PULSE=False
+
+    def run(self):
+        self.PULSE=True
+        #self.actuator.start()
+        t = threading.Thread(target=self.job.run)
+        t.start()
+        self.actuator.start()
+        return super(ProgressDialog, self).run()
+
+    def pulse(self, widget=None, data=None):
+        while self.job._popen_running:
+            gtk.gdk.threads_enter()
+            self.pbar.pulse()
+            self.get_action_area().set_sensitive(False)
+            gtk.gdk.threads_leave()
+            time.sleep(0.10)
+        return self._enable_action_area()
+
+    def _enable_action_area(self):
+        self.get_action_area().set_sensitive(True)
+        self.pbar.set_fraction(1.0)
+        if self.job.popen.returncode > 0 :
+            err = message.Error("Package failed to install... ")
+            if err.run():
+                err.destroy()
+        self.bannerlabel.set_property('label', 'Package installed')
+
 class AboutTask(gtk.Dialog):
     """ Informational dialog used to display details about a performed task.
     Similar to AboutJob, but the information for this one comes from the
         self.jobid = jobid
         self.dbase = dbase
         self.set_title(title)
-        self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
         self.body = self.get_content_area()
         topbox = gtk.HBox()
         img = gtk.Image()
         img.set_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
         lbl = BoldLabel("Build Task Details".strip())
         lbl.set_property('xalign', 0.0)
-        info = self.dbase.GetTaskDetails(self.jobid)
+        self.jobinfo = self.dbase.GetTaskDetails(self.jobid)
         topbox.pack_start(img, False, False, 2)
         topbox.pack_start(lbl, True, True, 2)
         self.body.pack_start(topbox, False, True, 4)
         self.set_has_separator(True)
         self.set_size_request(500, 400)
         self.body.pack_start(self._get_tree(), True, True, 2)
+        actions = self.get_action_area()
+        actions.pack_end(self._get_install_button(), False, False, 2)
+        self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
         self.show_all()
 
+    def __check_package_exists(self, widget=None):
+        """ Returns true if the package exists, False otherwise"""
+        if self.jobinfo['result'] == 'Fail' or not self.jobinfo['stdout']:
+            return []
+        ret = glob.glob(os.path.join(os.path.dirname(self.jobinfo['stdout']),
+                                                     "%s-%s-*-%s*.t?z"%(
+            self.jobinfo['app'],
+            self.jobinfo['ver'],
+            self.jobinfo['release'])))
+        return ret
+
+    def __do_install_package(self, widget=None):
+        """ install the package after it has been built"""
+        pkg = self.__check_package_exists()[0]
+        dia = ProgressDialog(banner = 'Installing %s'% os.path.basename(pkg),
+                             command = 'installpkg %s'% pkg)
+        if dia.run():
+            dia.destroy()
+
+
+    def _get_install_button(self):
+        """ Add an install button to the dialog's action area
+        but only enable it if the build is successful and the package is there."""
+        bt = vButton(stock=gtk.STOCK_EXECUTE,
+                     label='Install Package')
+        bt.connect('clicked', self.__do_install_package)
+        bt.set_sensitive(len(self.__check_package_exists()) > 0)
+        return bt
+
     def _get_tree(self):
         scroll = gtk.ScrolledWindow()
         scroll.set_policy(gtk.POLICY_AUTOMATIC,
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.