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 / PackageWorker.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  4.2 KB  |  113 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import apt_pkg
  5. import subprocess
  6. import gtk
  7. import gtk.gdk as gtk
  8. import thread
  9. import time
  10. import os
  11. import tempfile
  12. from gettext import gettext as _
  13.  
  14. class PackageWorker:
  15.     '''
  16.     A class which does the actual package installing/removing.
  17.     '''
  18.     (INSTALL, UPDATE) = range(2)
  19.     
  20.     def __init__(self, addon_cd = None):
  21.         self.addon_cd = addon_cd
  22.  
  23.     
  24.     def run_synaptic(self, id, lock, to_add = None, to_rm = None, action = INSTALL):
  25.         cmd = []
  26.         if os.getuid() != 0:
  27.             cmd = [
  28.                 '/usr/bin/gksu',
  29.                 '--desktop',
  30.                 '/usr/share/applications/synaptic.desktop',
  31.                 '--']
  32.         
  33.         cmd += [
  34.             '/usr/sbin/synaptic',
  35.             '--hide-main-window',
  36.             '--non-interactive',
  37.             '-o',
  38.             'Synaptic::closeZvt=true',
  39.             '--parent-window-id',
  40.             '%s' % id]
  41.         f = tempfile.NamedTemporaryFile()
  42.         if action == self.INSTALL:
  43.             if self.addon_cd:
  44.                 cmd += [
  45.                     '-o',
  46.                     'Acquire::cdrom::mount=%s' % self.addon_cd]
  47.             
  48.             for item in to_add:
  49.                 f.write('%s\tinstall\n' % item)
  50.             
  51.             for item in to_rm:
  52.                 f.write('%s\tuninstall\n' % item)
  53.             
  54.             cmd.append('--set-selections-file')
  55.             cmd.append('%s' % f.name)
  56.             f.flush()
  57.         elif action == self.UPDATE:
  58.             cmd.append('--update-at-startup')
  59.         
  60.         self.return_code = subprocess.call(cmd)
  61.         lock.release()
  62.         f.close()
  63.  
  64.     
  65.     def plug_removed(self, w, .2):
  66.         (win, socket) = .2
  67.         win.hide()
  68.         return True
  69.  
  70.     
  71.     def plug_added(self, sock, win):
  72.         while gtk.events_pending():
  73.             win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
  74.             win.show()
  75.             gtk.main_iteration()
  76.  
  77.     
  78.     def get_plugged_win(self, window_main):
  79.         win = gtk.Window()
  80.         win.realize()
  81.         win.window.set_functions(gtk.gdk.FUNC_MOVE)
  82.         win.set_border_width(6)
  83.         win.set_transient_for(window_main)
  84.         win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
  85.         win.set_title('')
  86.         win.set_resizable(False)
  87.         win.set_property('skip-taskbar-hint', True)
  88.         win.set_property('skip-taskbar-hint', True)
  89.         win.connect('delete_event', (lambda e, w: True))
  90.         socket = gtk.Socket()
  91.         socket.show()
  92.         win.add(socket)
  93.         socket.connect('plug-added', self.plug_added, win)
  94.         socket.connect('plug-removed', self.plug_removed, (win, socket))
  95.         return (win, socket)
  96.  
  97.     
  98.     def perform_action(self, window_main, cache, to_add = None, to_rm = None, action = INSTALL):
  99.         window_main.set_sensitive(False)
  100.         window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
  101.         lock = thread.allocate_lock()
  102.         lock.acquire()
  103.         t = thread.start_new_thread(self.run_synaptic, (window_main.window.xid, lock, to_add, to_rm, action))
  104.         while lock.locked():
  105.             while gtk.events_pending():
  106.                 gtk.main_iteration()
  107.             time.sleep(0.05)
  108.         window_main.set_sensitive(True)
  109.         window_main.window.set_cursor(None)
  110.         return self.return_code
  111.  
  112.  
  113.