~fougner/ubuntu/oneiric/sessioninstaller/fix-for-793396

« back to all changes in this revision

Viewing changes to .pc/02_backends_defer.patch/sessioninstaller/backends/synaptic.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2011-01-14 22:39:37 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110114223937-8eo62an1jg240hm6
Tags: 0.20+bzr117-0ubuntu1
* New bzr version:
 - Migrate from aptdaemon.defer to defer. (LP: #703330)
* debian/patches/02_backends_defer.patch:
 - Migrate also backends to defer.
* debian/control:
 - Depends on python-defer.
 - Depends on python-xapian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
"""Make use of synaptic as backend."""
 
4
# Copyright (C) 2008-2010 Sebastian Heinlein <devel@glatzor.de>
 
5
# Copyright (C) 2005-2007 Canonical
 
6
#
 
7
# Licensed under the GNU General Public License Version 2
 
8
#
 
9
# This program is free software; you can redistribute it and/or modify
 
10
# it under the terms of the GNU General Public License as published by
 
11
# the Free Software Foundation; either version 2 of the License, or
 
12
# (at your option) any later version.
 
13
#
 
14
# This program is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
# GNU General Public License for more details.
 
18
#
 
19
# You should have received a copy of the GNU General Public License
 
20
# along with this program; if not, write to the Free Software
 
21
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
22
 
 
23
__author__ = "Sebastian Heinlein <devel@glatzor.de>, " \
 
24
             "Michael Vogt <mvo@canonical.com"
 
25
 
 
26
import tempfile
 
27
from gettext import gettext as _
 
28
 
 
29
import gobject
 
30
 
 
31
from aptdaemon.defer import Deferred
 
32
 
 
33
import sessioninstaller.errors
 
34
 
 
35
 
 
36
class SynapticBackend(object):
 
37
 
 
38
    """Make use of Synaptic to install and remove packages."""
 
39
 
 
40
    def _run_synaptic(self, xid, opt, tempf, interaction):
 
41
        deferred = Deferred()
 
42
        if tempf:
 
43
            opt.extend(["--set-selections-file", "%s" % tempf.name])
 
44
        #FIXME: Take interaction into account
 
45
        opt.extend(["-o", "Synaptic::closeZvt=true"])
 
46
        if xid:
 
47
            opt.extend(["--parent-window-id", "%s" % (xid)])
 
48
        cmd = ["/usr/bin/gksu", 
 
49
               "--desktop", "/usr/share/applications/update-manager.desktop",
 
50
               "--", "/usr/sbin/synaptic", "--hide-main-window",
 
51
               "--non-interactive"]
 
52
        cmd.extend(opt)
 
53
        flags = gobject.SPAWN_DO_NOT_REAP_CHILD
 
54
        (pid, stdin, stdout, stderr) = gobject.spawn_async(cmd, flags=flags)
 
55
        gobject.child_watch_add(pid, self._on_synaptic_exit, (tempf, deferred))
 
56
        return deferred
 
57
 
 
58
    def _on_synaptic_exit(self, pid, condition, (tempf, deferred)):
 
59
        if tempf:
 
60
            tempf.close()
 
61
        if condition == 0:
 
62
            deferred.callback()
 
63
        else:
 
64
            deferred.errback(sessioninstaller.errors.ModifyFailed())
 
65
 
 
66
    def remove_packages(self, xid, package_names, interaction):
 
67
        opt = []
 
68
        # custom progress strings
 
69
        #opt.append("--progress-str")
 
70
        #opt.append("%s" % _("Please wait, this can take some time."))
 
71
        #opt.append("--finish-str")
 
72
        #opt.append("%s" %  _("Update is complete"))
 
73
        tempf = tempfile.NamedTemporaryFile()
 
74
        for pkg_name in package_names:
 
75
            tempf.write("%s\tuninstall\n" % pkg_name)
 
76
        tempf.flush()
 
77
        return self._run_synaptic(xid, opt, tempf, interaction)
 
78
 
 
79
    def install_packages(self, xid, package_names, interaction):
 
80
        opt = []
 
81
        # custom progress strings
 
82
        #opt.append("--progress-str")
 
83
        #opt.append("%s" % _("Please wait, this can take some time."))
 
84
        #opt.append("--finish-str")
 
85
        #opt.append("%s" %  _("Update is complete"))
 
86
        tempf = tempfile.NamedTemporaryFile()
 
87
        for pkg_name in package_names:
 
88
            tempf.write("%s\tinstall\n" % pkg_name)
 
89
        tempf.flush()
 
90
        return self._run_synaptic(xid, opt, tempf, interaction)
 
91
 
 
92
    def install_package_files(self, xid, package_names, interaction):
 
93
        raise NotImplemented
 
94
 
 
95
 
 
96
# vim:ts=4:sw=4:et