home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import apt
- import subprocess
- import gtk
- import gtk.gdk as gtk
- import thread
- import time
- import os
- import tempfile
- from gettext import gettext as _
-
- class GtkOpProgress(apt.progress.OpProgress):
- ''' a simple helper that keeps the GUI alive '''
-
- def update(self, percent):
- while gtk.events_pending():
- gtk.main_iteration()
-
-
-
- class PackageWorker(object):
- '''
- A class which does the actual package installing/removing.
- '''
- (INSTALL, UPDATE) = range(2)
-
- def run_synaptic(self, id, lock, to_add = None, to_rm = None, action = INSTALL):
- cmd = []
- if os.getuid() != 0:
- cmd = [
- '/usr/bin/gksu',
- '--desktop',
- '/usr/share/applications/synaptic.desktop',
- '--']
-
- cmd += [
- '/usr/sbin/synaptic',
- '--hide-main-window',
- '--non-interactive',
- '-o',
- 'Synaptic::closeZvt=true',
- '--parent-window-id',
- '%s' % id]
- f = tempfile.NamedTemporaryFile()
- if action == self.INSTALL:
- for item in to_add:
- f.write('%s\tinstall\n' % item)
-
- for item in to_rm:
- f.write('%s\tuninstall\n' % item)
-
- cmd.append('--set-selections-file')
- cmd.append('%s' % f.name)
- f.flush()
- elif action == self.UPDATE:
- cmd.append('--update-at-startup')
-
- self.return_code = subprocess.call(cmd)
- lock.release()
- f.close()
-
-
- def perform_action(self, window_main, to_add = None, to_rm = None):
- '''
- install/remove the given set of packages
-
- return True on success
- False if any of the actions could not be performed
- '''
- window_main.set_sensitive(False)
- window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
- lock = thread.allocate_lock()
- lock.acquire()
- t = thread.start_new_thread(self.run_synaptic, (window_main.window.xid, lock, to_add, to_rm, self.INSTALL))
- while lock.locked():
- while gtk.events_pending():
- gtk.main_iteration()
- time.sleep(0.05)
- result = True
- cache = apt.Cache(GtkOpProgress())
- for pkgname in to_add:
- if not cache[pkgname].isInstalled:
- result = False
- break
- continue
-
- for pkgname in to_rm:
- if cache[pkgname].isInstalled:
- result = False
- break
- continue
-
- window_main.set_sensitive(True)
- window_main.window.set_cursor(None)
- return result
-
-
-