- Ported to polkit-1.

This commit is contained in:
Tim Waugh 2009-08-27 13:16:15 +00:00
parent 34b42fa4d8
commit 7f1ff64d34
2 changed files with 160 additions and 2 deletions

View File

@ -0,0 +1,149 @@
diff -up system-config-printer-1.1.12/authconn.py.polkit-1 system-config-printer-1.1.12/authconn.py
--- system-config-printer-1.1.12/authconn.py.polkit-1 2009-08-25 15:01:40.000000000 +0100
+++ system-config-printer-1.1.12/authconn.py 2009-08-27 14:01:24.553275754 +0100
@@ -24,6 +24,7 @@ import gobject
import gtk
import os
from errordialogs import *
+import config
from debug import *
_ = lambda x: x
@@ -156,8 +157,11 @@ class Connection:
cups.setUser (self._use_user)
self._use_pk = ((self._server[0] == '/' or self._server == 'localhost')
- and not self._lock
and os.getuid () != 0)
+
+ if not config.WITH_POLKIT_1 and self._lock:
+ self._use_pk = False
+
if self._use_pk:
create_object = cupspk.Connection
else:
@@ -208,10 +212,6 @@ class Connection:
break
except cups.IPPError, (e, m):
if self._use_pk and m == 'pkcancel':
- title = _('Unauthorized request (%s)') % fname
- text = _("You are not authorized to carry out the "
- "requested action.")
- show_error_dialog (title, text, None)
raise cups.IPPError (0, _("Operation canceled"))
if not self._cancel and (e == cups.IPP_NOT_AUTHORIZED or
e == cups.IPP_FORBIDDEN):
diff -up system-config-printer-1.1.12/config.py.in.polkit-1 system-config-printer-1.1.12/config.py.in
--- system-config-printer-1.1.12/config.py.in.polkit-1 2009-08-25 15:01:40.000000000 +0100
+++ system-config-printer-1.1.12/config.py.in 2009-08-27 14:01:24.555275419 +0100
@@ -24,3 +24,4 @@ localedir="@localedir@"
pkgdatadir="@datadir@/@PACKAGE@"
VERSION="@VERSION@"
PACKAGE="@PACKAGE@"
+WITH_POLKIT_1=@WITH_POLKIT_1@
diff -up system-config-printer-1.1.12/configure.in.polkit-1 system-config-printer-1.1.12/configure.in
--- system-config-printer-1.1.12/configure.in.polkit-1 2009-08-25 17:01:27.000000000 +0100
+++ system-config-printer-1.1.12/configure.in 2009-08-27 14:01:24.556275177 +0100
@@ -43,6 +43,17 @@ if test x$with_udev_rules != xno; then
AM_PROG_CC_C_O
fi
+AC_ARG_WITH(polkit-1,
+ [AC_HELP_STRING([--with-polkit-1],
+ [Enable support for polkit-1 @<:@default=no@:>@])],
+ [],
+ [with_polkit_1=no])
+WITH_POLKIT_1=False
+if test x$with_polkit_1 != xno; then
+ WITH_POLKIT_1=True
+fi
+AC_SUBST(WITH_POLKIT_1)
+
ALL_LINGUAS="ar as bg bn_IN bn bs ca cs cy da de el en_GB es et fa fi fr gu he hi hr hu hy id is it ja ka kn ko lo lv mai mk ml mr ms my nb nl nn or pa pl pt_BR pt ro ru si sk sl sr@latin sr sv ta te th tr uk vi zh_CN zh_TW"
AC_CONFIG_FILES([
Makefile
diff -up system-config-printer-1.1.12/cupspk.py.polkit-1 system-config-printer-1.1.12/cupspk.py
--- system-config-printer-1.1.12/cupspk.py.polkit-1 2009-08-25 15:01:40.000000000 +0100
+++ system-config-printer-1.1.12/cupspk.py 2009-08-27 14:01:24.558275639 +0100
@@ -34,6 +34,7 @@ import tempfile
import cups
import dbus
import gtk
+import config
from debug import debugprint
from dbus.mainloop.glib import DBusGMainLoop
@@ -221,8 +222,14 @@ class Connection:
return retval
break
except dbus.exceptions.DBusException, e:
- if not self._handle_exception_with_auth(e):
+ if config.WITH_POLKIT_1:
+ if e.get_dbus_name() == CUPS_PK_NEED_AUTH:
+ raise cups.IPPError(cups.IPP_NOT_AUTHORIZED, 'pkcancel')
+
break
+ else:
+ if not self._handle_exception_with_auth(e):
+ break
# The PolicyKit call did not work (either a PK-error and we got a dbus
# exception that wasn't handled, or an error in the mechanism itself)
diff -up system-config-printer-1.1.12/Makefile.am.polkit-1 system-config-printer-1.1.12/Makefile.am
--- system-config-printer-1.1.12/Makefile.am.polkit-1 2009-08-25 17:01:27.000000000 +0100
+++ system-config-printer-1.1.12/Makefile.am 2009-08-27 14:01:24.551276420 +0100
@@ -39,6 +39,7 @@ config.py: config.py.in Makefile
-e "s|\@localedir\@|$(localedir)|" \
-e "s|\@VERSION\@|$(VERSION)|" \
-e "s|\@PACKAGE\@|$(PACKAGE)|" \
+ -e "s|\@WITH_POLKIT_1\@|$(WITH_POLKIT_1)|" \
$< > $@
# Use distutils to build the module.
diff -up system-config-printer-1.1.12/system-config-printer.py.polkit-1 system-config-printer-1.1.12/system-config-printer.py
--- system-config-printer-1.1.12/system-config-printer.py.polkit-1 2009-08-27 14:01:17.554275306 +0100
+++ system-config-printer-1.1.12/system-config-printer.py 2009-08-27 14:01:24.564275576 +0100
@@ -4620,19 +4620,32 @@ class NewPrinterGUI(GtkGUI):
self.WaitWindow.set_transient_for (parent)
self.WaitWindow.show_now ()
self.busy (self.WaitWindow)
- while gtk.events_pending ():
- gtk.main_iteration ()
- debugprint ("Fetching devices")
- self.mainapp.cups._begin_operation (_("fetching device list"))
- try:
- devices = cupshelpers.getDevices(self.mainapp.cups)
- except:
- self.mainapp.cups._end_operation ()
- self.WaitWindow.hide ()
- raise
+ if self.mainapp.cups._use_pk and config.WITH_POLKIT_1:
+ def get_devices():
+ c = authconn.Connection (host=self.mainapp.connect_server,
+ parent=parent, lock=True)
+ c._begin_operation (_("fetching device list"))
+ ret = cupshelpers.getDevices (c)
+ c._end_operation ()
+ return ret
+
+ op = TimedOperation (get_devices)
+ try:
+ devices = op.run ()
+ except (OperationCanceled, RuntimeError, cups.IPPError):
+ self.WaitWindow.hide ()
+ raise
+ else:
+ self.mainapp.cups._begin_operation (_("fetching device list"))
+ try:
+ devices = cupshelpers.getDevices (self.mainapp.cups)
+ self.mainapp.cups._end_operation ()
+ except cups.IPPError:
+ self.mainapp.cups._end_operation ()
+ self.WaitWindow.hide ()
+ raise
- self.mainapp.cups._end_operation ()
self.WaitWindow.hide ()
debugprint ("Got devices")
return devices

View File

@ -7,7 +7,7 @@
Summary: A printer administration tool
Name: system-config-printer
Version: 1.1.12
Release: 3%{?dist}
Release: 4%{?dist}
License: GPLv2+
URL: http://cyberelk.net/tim/software/system-config-printer/
Group: System Environment/Base
@ -17,6 +17,7 @@ Source2: http://cyberelk.net/tim/data/pysmbc/pysmbc-%{pysmbc_version}.tar.bz2
Patch1: system-config-printer-get_cursor.patch
Patch2: system-config-printer-statereason-icons.patch
Patch3: system-config-printer-icon-load-traceback.patch
Patch4: system-config-printer-polkit-1.patch
BuildRequires: cups-devel >= 1.2
BuildRequires: python-devel >= 2.4
@ -27,6 +28,7 @@ BuildRequires: intltool
BuildRequires: libusb-devel, libudev-devel
BuildRequires: xmlto
BuildRequires: epydoc
BuildRequires: automake, autoconf
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@ -80,9 +82,13 @@ printers.
%patch1 -p1 -b .get_cursor
%patch2 -p1 -b .statereason-icons
%patch3 -p1 -b .icon-load-traceback
%patch4 -p1 -b .polkit-1
%build
%configure --with-udev-rules
aclocal
automake --copy --add-missing
autoconf
%configure --with-udev-rules --with-polkit-1
pushd pycups-%{pycups_version}
make
@ -191,6 +197,9 @@ rm -rf %buildroot
exit 0
%changelog
* Thu Aug 27 2009 Tim Waugh <twaugh@redhat.com> 1.1.12-4
- Ported to polkit-1.
* Wed Aug 26 2009 Tim Waugh <twaugh@redhat.com> 1.1.12-3
- Handle icon load failure gracefully.
- Fixed statereason icon names.