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
7
# Licensed under the GNU General Public License Version 2
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.
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.
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.
23
__author__ = "Sebastian Heinlein <devel@glatzor.de>, " \
24
"Michael Vogt <mvo@canonical.com"
27
from gettext import gettext as _
31
from aptdaemon.defer import Deferred
33
import sessioninstaller.errors
36
class SynapticBackend(object):
38
"""Make use of Synaptic to install and remove packages."""
40
def _run_synaptic(self, xid, opt, tempf, interaction):
43
opt.extend(["--set-selections-file", "%s" % tempf.name])
44
#FIXME: Take interaction into account
45
opt.extend(["-o", "Synaptic::closeZvt=true"])
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",
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))
58
def _on_synaptic_exit(self, pid, condition, (tempf, deferred)):
64
deferred.errback(sessioninstaller.errors.ModifyFailed())
66
def remove_packages(self, xid, package_names, interaction):
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)
77
return self._run_synaptic(xid, opt, tempf, interaction)
79
def install_packages(self, xid, package_names, interaction):
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)
90
return self._run_synaptic(xid, opt, tempf, interaction)
92
def install_package_files(self, xid, package_names, interaction):