home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / AppInstall / DialogComplete.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  9.2 KB  |  260 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from SimpleGladeApp import SimpleGladeApp
  5. import gtk
  6. import gobject
  7. import os
  8. from gettext import ngettext
  9. from gettext import gettext as _
  10. from Util import *
  11. from widgets.AppListView import AppListView
  12.  
  13. class AppListViewComplete(AppListView):
  14.     
  15.     def __init__(self, cache = None, menu = None, icons = None, executable = False):
  16.         AppListView.__init__(self, style = 1)
  17.         self.executable = executable
  18.         self.connect('row-activated', self.on_row_activated)
  19.  
  20.     
  21.     def set_executable(self, value):
  22.         self.executable = value
  23.  
  24.     
  25.     def on_row_activated(self, treeview_packages, path, column):
  26.         if self.executable != True:
  27.             return False
  28.         if os.getuid() == 0:
  29.             return False
  30.         store = self.get_model()
  31.         treeiter = store.get_iter(path)
  32.         (name, item, popcon) = store[treeiter]
  33.         cmd_parts = []
  34.         command = item.execCmd
  35.         terminal = item.needsTerminal
  36.         if command == '':
  37.             return None
  38.         for part in command.split():
  39.             while True:
  40.                 if part[0] == '%':
  41.                     break
  42.                 
  43.                 if cmd_parts[-1:] == '%':
  44.                     part = '%' + part
  45.                     cmd_parts[-1:] = part
  46.                     break
  47.                 
  48.                 cmd_parts.append(part)
  49.                 break
  50.         
  51.         if terminal:
  52.             command = ' '.join(cmd_parts)
  53.             command = 'gnome-terminal --command="' + command + '"'
  54.             cmd_parts = command.split()
  55.         
  56.         os.spawnvp(os.P_NOWAIT, cmd_parts[0], cmd_parts)
  57.  
  58.  
  59.  
  60. class DialogComplete(SimpleGladeApp):
  61.     
  62.     def __init__(self, datadir, parent, to_add, to_rm, cache, auto_close = False):
  63.         
  64.         def add_apps_to_store(apps, store):
  65.             for app in apps:
  66.                 store.append([
  67.                     app.name,
  68.                     app,
  69.                     0])
  70.             
  71.  
  72.         SimpleGladeApp.__init__(self, path = '/usr/share/gnome-app-install/gnome-app-install.glade', root = 'window_complete', domain = 'gnome-app-install')
  73.         self.cache = cache
  74.         self.auto_close = auto_close
  75.         self.store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_INT)
  76.         if parent:
  77.             self.window_complete.set_transient_for(parent)
  78.         
  79.         self.treeview = AppListViewComplete()
  80.         self.scrolledwindow_complete.add(self.treeview)
  81.         self.treeview.set_headers_visible(False)
  82.         self.treeview.set_model(self.store)
  83.         self.treeview.show()
  84.         failed_apps = []
  85.         failed_extras = []
  86.         installed_apps = []
  87.         installed_extras = []
  88.         self.install_failures = False
  89.         for app in to_add:
  90.             pkg = app.pkgname
  91.             available = cache.has_key(pkg)
  92.             if available:
  93.                 pass
  94.             installed = cache[pkg].isInstalled
  95.             if not available:
  96.                 if app.execCmd != '':
  97.                     failed_apps.append(app)
  98.                 else:
  99.                     failed_extras.append(app)
  100.             app.execCmd != ''
  101.             if not installed:
  102.                 if app.execCmd != '':
  103.                     failed_apps.append(app)
  104.                 else:
  105.                     failed_extras.append(app)
  106.             app.execCmd != ''
  107.             if installed and app.execCmd != '':
  108.                 installed_apps.append(app)
  109.                 continue
  110.             if installed and app.execCmd == '':
  111.                 installed_extras.append(app)
  112.                 continue
  113.         
  114.         for app in to_rm:
  115.             pkg = app.pkgname
  116.             if self.cache.has_key(pkg) and self.cache[pkg].isInstalled:
  117.                 if app.execCmd != '':
  118.                     failed_apps.append(app)
  119.                 else:
  120.                     failed_extras.append(app)
  121.             app.execCmd != ''
  122.         
  123.         if failed_extras or failed_apps:
  124.             self.install_failures = True
  125.         
  126.         self.button_complete_retry.connect('clicked', self.on_button_retry_clicked)
  127.         self.button_complete_more.connect('clicked', self.on_button_more_clicked)
  128.         self.button_complete_close.connect('clicked', self.on_button_close_clicked)
  129.         self.window_complete.connect('delete-event', self.on_delete)
  130.         if (len(failed_apps) > 0 or len(failed_extras) > 0) and len(to_rm) == 0:
  131.             if len(failed_extras) > 0:
  132.                 header = _('Software installation failed')
  133.                 body = _('There has been a problem during the installation of the following pieces of software.')
  134.                 self.button_complete_more.set_label(_('Add/Remove More Software'))
  135.             else:
  136.                 header = _('Application installation failed')
  137.                 body = _('There has been a problem during the installation of the following applications.')
  138.             add_apps_to_store(failed_apps, self.store)
  139.             add_apps_to_store(failed_extras, self.store)
  140.             self.image_complete_icon.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
  141.             self.button_complete_retry.show()
  142.         elif (len(failed_apps) > 0 or len(failed_extras) > 0) and len(to_add) == 0:
  143.             if len(failed_extras) > 0:
  144.                 header = _('Software could not be removed')
  145.                 body = _('There has been a problem during the removal of the following pieces of software.')
  146.                 self.button_complete_more.set_label(_('Add/Remove More Software'))
  147.             else:
  148.                 header = _('Not all applications could be removed')
  149.                 body = _('There has been a problem during the removal of the following applications.')
  150.             add_apps_to_store(failed_apps, self.store)
  151.             add_apps_to_store(failed_extras, self.store)
  152.             self.image_complete_icon.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
  153.             self.button_complete_retry.show()
  154.         elif len(failed_extras) > 0 or len(failed_apps) > 0:
  155.             if len(failed_extras) > 0:
  156.                 header = _('Installation and removal of software failed')
  157.                 body = _('There has been a problem during the installation or removal of the following pieces of software.')
  158.                 self.button_complete_more.set_label(_('Add/Remove More Software'))
  159.             else:
  160.                 header = _('Installation and removal of applications failed')
  161.                 body = _('There has been a problem during the installation or removal of the following applications.')
  162.             add_apps_to_store(failed_apps, self.store)
  163.             add_apps_to_store(failed_extras, self.store)
  164.             self.button_complete_retry.show()
  165.             self.image_complete_icon.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
  166.         elif len(installed_apps) > 0:
  167.             header = ngettext(_('New application has been installed'), _('New applications have been installed'), len(installed_apps))
  168.             add_apps_to_store(installed_apps, self.store)
  169.             if os.getuid() == 0:
  170.                 body = _('To start a newly installed application, choose it from the applications menu.')
  171.             else:
  172.                 body = _('To start a newly installed application double click on it.')
  173.                 self.treeview.set_executable(True)
  174.         elif len(installed_extras) > 0:
  175.             header = _('Software has been installed successfully')
  176.             body = _('Do you want to install or remove further software?')
  177.             self.scrolledwindow_complete.hide()
  178.             self.button_complete_more.set_label(_('Add/Remove More Software'))
  179.         else:
  180.             header = _('Applications have been removed successfully')
  181.             body = _('Do you want to install or remove further applications?')
  182.             self.scrolledwindow_complete.hide()
  183.         self.label_complete.set_markup('<b><big>%s</big></b>\n\n%s' % (header, body))
  184.  
  185.     
  186.     def run(self):
  187.         if self.auto_close and self.install_failures == False:
  188.             return gtk.RESPONSE_CLOSE
  189.         self.window_complete.show()
  190.         gtk.main()
  191.         return self._response
  192.  
  193.     
  194.     def _finish(self):
  195.         self.window_complete.hide()
  196.         gtk.main_quit()
  197.  
  198.     
  199.     def on_button_close_clicked(self, button):
  200.         self._response = gtk.RESPONSE_CLOSE
  201.         self._finish()
  202.  
  203.     
  204.     def on_button_retry_clicked(self, button):
  205.         self._response = 1
  206.         self._finish()
  207.  
  208.     
  209.     def on_button_more_clicked(self, button):
  210.         self._response = 2
  211.         self._finish()
  212.  
  213.     
  214.     def on_delete(self, widget, event):
  215.         self._response = gtk.RESPONSE_CLOSE
  216.         self._finish()
  217.         return gtk.TRUE
  218.  
  219.  
  220. if __name__ == '__main__':
  221.     from AppInstall.CoreMenu import CoreApplicationMenu
  222.     from AppInstall.DialogComplete import DialogComplete
  223.     import gtk
  224.     import apt
  225.     import cPickle
  226.     import pdb
  227.     cache = apt.Cache()
  228.     progress = apt.progress.OpTextProgress()
  229.     to_add = []
  230.     datadir = '/usr/share/app-install'
  231.     desktopdir = '/usr/share/app-install'
  232.     cachedir = '/var/cache/app-install'
  233.     treeview_categories = gtk.TreeView()
  234.     treeview_packages = gtk.TreeView()
  235.     menu = CoreApplicationMenu(datadir)
  236.     menu.pickle = cPickle.load(open('/var/cache/app-install/menu.p'))
  237.     available = []
  238.     available_extras = []
  239.     installed = []
  240.     installed_extras = []
  241.     print menu.pickle.keys()
  242.     for app in menu.pickle[menu.pickle.keys()[0]]:
  243.         if cache.has_key(app.pkgname) and cache[app.pkgname].isInstalled:
  244.             if app.execCmd:
  245.                 installed.append(app)
  246.             else:
  247.                 installed_extras.append(app)
  248.         app.execCmd
  249.         if app.execCmd:
  250.             available.append(app)
  251.             continue
  252.         available_extras.append(app)
  253.     
  254.     to_rm = []
  255.     while True:
  256.         pdb.set_trace()
  257.         dia = DialogComplete(datadir, None, to_add, to_rm, cache)
  258.         dia.run()
  259.  
  260.