Moises Henriquez avatar Moises Henriquez committed 41bbd12

Adding install window dialog and implementing summary attribute on package objects (Thanks rbistolfi)

Comments (0)

Files changed (7)

     basepath = os.path.dirname(os.path.abspath(__file__))
     return os.path.join(basepath, 'data/PACKAGES.TXT')
 
+def generate_slapt_getrc():
+    """ Generate a slapt-getrc file dynamically taking into consideration the
+    current path and saving it to a temp dir"""
+    basepath = os.path.dirname(get_repo_path())
+    rcpath = '/tmp/slapt-getrc_vlmmbd'
+    rc = """
+    WORKINGDIR=/var/cache/slapt-get
+    EXCLUDE=kernel,kernel-ide,kernel-source,kernel-headers,kernel-modules,vl-hot
+
+    SOURCE=file://%s"""% basepath
+    foo = open(rcpath, 'w')
+    foo.write('\n'.join(([s.strip() for s in rc.split('\n')])))
+    foo.close()
+    return rcpath
+    
+
 class Window(gtk.Window):
     """ Top-level window for the vectorlinux multimedia
     add-on"""
         filem = gtk.MenuItem('_%s'% _('File'))
         filem.set_submenu(filemenu)
         exit = gtk.MenuItem('_%s'% _('Exit'))
-        exit.connect('activate', gtk.main_quit)
+        exit.connect('activate', self.exit)
         filemenu.append(exit)
 
         mb.append(filem)
 
         btInstallSelected = gtk.Button(_('Install Selected'))
         self.actionbtn = btInstallSelected
+        self.actionbtn.connect('clicked', self.install_btn_event)
         img = gtk.Image()
         img.set_from_stock(gtk.STOCK_APPLY,
                 gtk.ICON_SIZE_BUTTON)
         self._stop_monitor = True
         time.sleep(0.25)
         gtk.main_quit()
+        if os.path.exist('/tmp/slapt-getrc_vlmmbd'):
+            try:
+                os.remove('/tmp/slapt-getrc_vlmmbd')
+            except:
+                pass
         return
 
     def monitor(self):
         # Get the number of selected items
        i = 0
+       model = self.display.get_model()
        if self._stop_monitor is True:
            return
        while self._stop_monitor is False:
            time.sleep(0.25)
-           i = 0
-           model = self.display.get_model()
-           for item in model:
-               if item[0] is True:
-                   i += 1
+           try:
+               i = len(self._do_get_selected_items())
+           except:
+               model = self.display.get_model()
+               for item in model:
+                   if item[0] is True:
+                       i += 1
+
 
            if i > 0:
                if self._stop_monitor is True:
                         '%s items selected' % len(model))
         return
 
+    def install_btn_event(self, widget):
+        todo = self._do_get_selected_items()
+        print todo
+
+    def _do_get_selected_items(self):
+        ret = []
+        try:
+            model = self.display.get_model()
+        except:
+            return ret
+        for item in model:
+            if item[0] is True:
+                (app, desc) = item[1].split('\n')
+                # Remove the formatting garbage from the string
+                app = app.replace('<b>', '').replace('</b>','').strip()
+                ret.append(app.strip())
+        return ret
+
+
 
 if __name__ == '__main__':
     gtk.gdk.threads_init()

utils/message.py

-#!/usr/bin/env python
-
-#    This file is part of the vectorlinux multimedia bonus disc.
-#
-#    This file 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.
-#
-#    This file 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 this file.  If not, see <http://www.gnu.org/licenses/>.
-
-import gtk
-
-__author__ = 'Moises Henriquez'
-__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
-
-
-def _(str):
-    return str
-
-def Error(parent = None, text = None, title = 'Error'):
-    """Generic error message dialog"""
-    dia = gtk.MessageDialog(
-            parent = parent,
-            type = gtk.MESSAGE_ERROR,
-            buttons = gtk.BUTTONS_OK,
-            )
-    dia.set_markup(text)
-    dia.set_title(title)
-    return dia
-
-
-def Info(parent = None, text = None, title = 'Info'):
-    dia = gtk.MessageDialog(
-            parent = parent,
-            type = gtk.MESSAGE_INFO,
-            buttons = gtk.BUTTONS_OK,
-            )
-    dia.set_markup(text)
-    dia.set_title(title)
-    return dia
-
-

utils/repository.py

 
         self.tag = self.build.rsplit(".", 1)[0]
 
+    def get_summary(self):
+        """Returns the short description of a package if found, and an empty
+        string if not.
+
+        """
+
+        short_desc = re.search(r'\(.*\)', self.description)
+        if short_desc:
+            return short_desc.group().strip("()")
+        return str()
+
+    summary = property(get_summary)
+
 
 def repository(packages_txt):
     """Parse PACKAGES.TXT file and return a list of Package objects."""
     data = data.split("\n\n")
     return ( Package(regex.search(i).groups()) for i in data )
 
-def ShortDescribe(package):
-    """ 
-    Returns a string representing the short description of a Package object
-    Arguments:
-            package - a Package object
-            """
-    description = package.description.replace('%s:'% package.name, '').strip()
-    description = description.strip()
-    short = description.split('\n')[0].strip()
-    if short.startswith(package.name):
-            short = short.split(' ')[1:]
-    short = ' '.join(short)
-    short = short.replace('(', '')
-    short = short.replace(')', '')
-    short = short.strip()
-    if short.startswith(':'):
-            short = short.replace(':', '').strip()
-#    if description.startswith(package.name):
-#            description = description.split(' ')[:1]
-
-    return short.strip()
-
-    
-
-
             return pkg2
     return max(pkg1, pkg2)
 
-
 class PackageManager(object):
     """
     Package manager functions tied to VL"""
         the bonus disc over ANYTHING else
         """
 
-
-
 class PackageCache(object):
     """ Cache of currently installed packages """
     def __init__(self, cachedir='/var/log/packages'):
+#!/usr/bin/env python
+
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    This file 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.
+#
+#    This file 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 this file.  If not, see <http://www.gnu.org/licenses/>.
+
+import gtk
+import time
+import threading
+
+__author__ = 'Moises Henriquez'
+__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
+
+
+def _(str):
+    return str
+
+class InstallWindow(gtk.Dialog):
+    def __init__(self, parent = None, pkglist = []):
+        gtk.Dialog.__init__(self, parent = parent)
+        self.set_title(_('Installing Packages'))
+        if parent is None:
+            self.set_position(gtk.WIN_POS_CENTER)
+
+        content = self.get_content_area()
+        action = self.get_action_area()
+
+        banner = gtk.Label(
+                _('Please wait while the following tasks complete')
+                )
+        blank = gtk.Label()
+        self.progress = gtk.ProgressBar()
+        self.status = gtk.Label()
+
+        for item in (banner, blank, self.status, self.progress):
+            content.pack_start(item, False, False, 4)
+
+        btnCancel = gtk.Button(stock = gtk.STOCK_CANCEL)
+        btnCancel.connect('clicked', self.exit)
+
+        btGo = gtk.Button(stock = gtk.STOCK_OK)
+        btGo.connect('clicked', self.start_process)
+        action.pack_start(btGo, False, False, 4)
+
+        action.pack_start(btnCancel, False, False, 4)
+        self.stopbar = False
+        self.monitor = threading.Thread(target = self.move)
+        self.resize(400, 150)
+        self.current = ""
+
+        self.show_all()
+        self.pkglist = range(25)
+#        self.pkglist = ['Package 1', 'package 2', 'package 3' ]
+        self._icurrent = 0.0
+
+    def start_process(self, widget = None):
+        self.stopbar = False
+        self.monitor.start()
+        ins = threading.Thread(target = self.installation, args=(self.pkglist,))
+        ins.start()
+
+
+    def installation(self, pkgs):
+        for pkg in pkgs:
+            self.current = pkg
+            gtk.gdk.threads_enter()
+            self.status.set_property('label', pkg)
+            gtk.gdk.threads_leave()
+            # FIXME: Instead of this wait time, call the slapt-get
+            # install method to install the package and process the
+            # output.
+            time.sleep(3)
+            self._icurrent += 1
+        
+        # When done, stop the monitor thread
+        self.stopbar = True
+
+
+    def exit(self, widget=None):
+        self.stopbar = True
+        time.sleep(0.25)
+        gtk.main_quit()
+
+    def move(self):
+        while not self.stopbar:
+            val = float(float(self._icurrent) / float(len(self.pkglist)))
+            valstr = str(int(val) * 100)
+#            print float(float(self._icurrent) / float(len(self.pkglist)))
+            #            print self._icurrent / len(self.pkglist)
+            gtk.gdk.threads_enter()
+            self.progress.set_fraction(val)
+            self.progress.set_text('%i'% (val * 100) + ' %')
+            #   str(int(self._icurrent / len(self.pkglist)), '\%'))
+            gtk.gdk.threads_leave()
+            time.sleep(0.1)
+        gtk.gdk.threads_enter()
+        self.progress.set_fraction(1.0)
+        self.progress.set_text('100 %')
+        gtk.gdk.threads_leave()
+               
+
+    def process_package(self, package):
+        #        gtk.gdk.threads_enter()
+        self.status.set_property('label', package)
+#        gtk.gdk.threads_leave()
+#        time.sleep(5)
+        return 0
+
+
+
+
+if __name__ == '__main__':
+    gtk.gdk.threads_init()
+    w = InstallWindow()
+#    w.monitor.start()
+    gtk.gdk.threads_enter()
+#    w.show_all()
+
+    gtk.main()
+    gtk.gdk.threads_leave()
+
+
+
+#!/usr/bin/env python
+
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    This file 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.
+#
+#    This file 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 this file.  If not, see <http://www.gnu.org/licenses/>.
+
+import gtk
+import threading
+import time
+__author__ = 'Moises Henriquez'
+__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
+
+
+def _(str):
+    return str
+
+def Error(parent = None, text = None, title = 'Error'):
+    """Generic error message dialog"""
+    dia = gtk.MessageDialog(
+            parent = parent,
+            type = gtk.MESSAGE_ERROR,
+            buttons = gtk.BUTTONS_OK,
+            )
+    dia.set_markup(text)
+    dia.set_title(title)
+    return dia
+
+def Info(parent = None, text = None, title = 'Info'):
+    dia = gtk.MessageDialog(
+            parent = parent,
+            type = gtk.MESSAGE_INFO,
+            buttons = gtk.BUTTONS_OK,
+            )
+    dia.set_markup(text)
+    dia.set_title(title)
+    return dia
+
+
             for app in self.repo:
                 if 'deps' not in app.location:
                     _overlay = cache.is_app_installed(app.name)
-                    _sdesc = repository.ShortDescribe(app)
+                    _sdesc = app.summary
+#                    _sdesc = repository.ShortDescribe(app)
                     self.view.list_app(app_name = app.name,
                             app_short_description = _sdesc,
                             installed_indicator = _overlay)
         elif category == _('Audio'):
             for app in self.repo:
                 _overlay = cache.is_app_installed(app.name)
-                _sdesc = repository.ShortDescribe(app)
+                _sdesc = app.summary
+#                _sdesc = repository.ShortDescribe(app)
                 if 'Audio' in app.location:
                     self.view.list_app(
                             app_name = app.name,
         elif category == _('Video'):
             for app in self.repo:
                 _overlay = cache.is_app_installed(app.name)
-                _sdesc = repository.ShortDescribe(app)
+                _sdesc = app.summary
+#                _sdesc = repository.ShortDescribe(app)
                 if 'Video' in app.location:
                     self.view.list_app(
                             app_name = app.name,
         else:
             for app in self.repo:
                 _overlay = cache.is_app_installed(app.name)
-                _sdesc = repository.ShortDescribe(app)
+                _sdesc = app.summary
+#                _sdesc = repository.ShortDescribe(app)
                 if app.location not in (
                         'Audio',
                         'Video',
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.