~flamingolof/gnome-codec-install/aptdaemon

« back to all changes in this revision

Viewing changes to GnomeCodecInstall/PackageWorker.py

  • Committer: Olof Kindgren
  • Date: 2009-10-22 19:56:54 UTC
  • Revision ID: olof@calculon-20091022195654-qssylm11h392lj32
Use aptdaemon instead of synaptic (can't be configured, doesn't detect aptdaemon)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import time
10
10
import os
11
11
import tempfile
 
12
import aptdaemon.client
 
13
from aptdaemon.enums import *
 
14
from aptdaemon.gtkwidgets import AptErrorDialog, \
 
15
                                 AptProgressDialog
12
16
from gettext import gettext as _
13
17
 
14
18
class GtkOpProgress(apt.progress.OpProgress):
67
71
        return True on success 
68
72
               False if any of the actions could not be performed
69
73
        """
70
 
        window_main.set_sensitive(False)
71
 
        if window_main.window:
72
 
          window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
73
 
        lock = thread.allocate_lock()
74
 
        lock.acquire()
75
 
        t = thread.start_new_thread(self.run_synaptic,(window_main.window.xid,lock,to_add, to_rm, self.INSTALL))
76
 
        while lock.locked():
 
74
        #How do we check if aptdaemon is available? Should there be a backend
 
75
        #chooser as in update-manager?
 
76
        use_aptdaemon = True
 
77
        if use_aptdaemon == True:
 
78
          ac = aptdaemon.client.AptClient()
 
79
          t = ac.commit_packages(to_add, [], to_rm, [], [], exit_handler=self._on_exit)
 
80
          dia = AptProgressDialog(t, parent=window_main.window.xid, terminal=False)
 
81
          dia.run()
 
82
          dia.hide()
 
83
          self._show_messages(t)
 
84
        else:
 
85
          window_main.set_sensitive(False)
 
86
          if window_main.window:
 
87
            window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
 
88
          lock = thread.allocate_lock()
 
89
          lock.acquire()
 
90
          t = thread.start_new_thread(self.run_synaptic,(window_main.window.xid,lock,to_add, to_rm, self.INSTALL))
 
91
          while lock.locked():
77
92
            while gtk.events_pending():
78
 
                gtk.main_iteration()
 
93
              gtk.main_iteration()
79
94
            time.sleep(0.05)
80
95
 
81
96
        # check if the requested package really got installed
95
110
        if window_main.window:
96
111
          window_main.window.set_cursor(None)
97
112
        return result
 
113
 
 
114
    def _on_exit(self, trans, exit):
 
115
        if exit == EXIT_FAILED:
 
116
            d = AptErrorDialog(trans.get_error(), parent=self.win)
 
117
            d.run()
 
118
            d.hide()
 
119
    def _show_messages(self, trans):
 
120
        while gtk.events_pending():
 
121
            gtk.main_iteration()
 
122
        for msg in trans._messages:
 
123
            d = AptMessageDialog(msg.enum, msg.details, parent=self.win)
 
124
            d.run()
 
125
            d.hide()