From 82858a08e397dceec049c067b71bbf90973df24c Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Tue, 27 Nov 2007 12:53:03 +0000 Subject: [PATCH] - pycups: Applied patch from SVN to allow fetching printer attributes by URI. --- pycups-attributes-uri.patch | 136 ++++++++++++++++++++++++++++++ system-config-printer-0.7.x.patch | 63 ++++++++++++++ system-config-printer.spec | 4 + 3 files changed, 203 insertions(+) create mode 100644 pycups-attributes-uri.patch create mode 100644 system-config-printer-0.7.x.patch diff --git a/pycups-attributes-uri.patch b/pycups-attributes-uri.patch new file mode 100644 index 0000000..a9c401d --- /dev/null +++ b/pycups-attributes-uri.patch @@ -0,0 +1,136 @@ +diff -up pycups-1.9.31/cupsconnection.c.attributes-uri pycups-1.9.31/cupsconnection.c +--- pycups-1.9.31/cupsconnection.c.attributes-uri 2007-11-27 12:47:43.000000000 +0000 ++++ pycups-1.9.31/cupsconnection.c 2007-11-27 12:48:46.000000000 +0000 +@@ -1975,42 +1975,77 @@ PyObject_from_attr_value (ipp_attribute_ + } + + static PyObject * +-Connection_getPrinterAttributes (Connection *self, PyObject *args) ++Connection_getPrinterAttributes (Connection *self, PyObject *args, ++ PyObject *kwds) + { + PyObject *ret; +- PyObject *nameobj; ++ PyObject *nameobj = NULL; + char *name; ++ PyObject *uriobj = NULL; ++ char *uri; + ipp_t *request, *answer; + ipp_attribute_t *attr; +- char uri[HTTP_MAX_URI]; ++ char consuri[HTTP_MAX_URI]; + int i; ++ static char *kwlist[] = { "name", "uri", NULL }; ++ ++ if (!PyArg_ParseTupleAndKeywords (args, kwds, "|OO", kwlist, ++ &nameobj, &uriobj)) ++ return NULL; + +- if (!PyArg_ParseTuple (args, "O", &nameobj)) ++ if (nameobj && uriobj) { ++ PyErr_SetString (PyExc_RuntimeError, ++ "name or uri must be specified but not both"); + return NULL; ++ } + +- if (UTF8_from_PyObj (&name, nameobj) == NULL) ++ if (nameobj) { ++ if (UTF8_from_PyObj (&name, nameobj) == NULL) ++ return NULL; ++ } else if (uriobj) { ++ if (UTF8_from_PyObj (&uri, uriobj) == NULL) ++ return NULL; ++ } else { ++ PyErr_SetString (PyExc_RuntimeError, ++ "name or uri must be specified"); + return NULL; ++ } ++ ++ debugprintf ("-> Connection_getPrinterAttributes(%s)\n", ++ nameobj ? name : uri); ++ if (nameobj) { ++ snprintf (consuri, sizeof (consuri), "ipp://localhost/printers/%s", name); ++ free (name); ++ uri = consuri; ++ } + +- snprintf (uri, sizeof (uri), "ipp://localhost/printers/%s", name); + for (i = 0; i < 2; i++) { + request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES); + ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI, + "printer-uri", NULL, uri); ++ debugprintf ("trying request with uri %s\n", uri); + answer = cupsDoRequest (self->http, request, "/"); + if (answer && answer->request.status.status_code == IPP_NOT_POSSIBLE) { + ippDelete (answer); ++ if (uriobj) ++ break; ++ + // Perhaps it's a class, not a printer. + snprintf (uri, sizeof (uri), "ipp://localhost/classes/%s", name); + } else break; + } + +- free (name); ++ if (uriobj) ++ free (uri); ++ + if (!answer || answer->request.status.status_code > IPP_OK_CONFLICT) { + set_ipp_error (answer ? + answer->request.status.status_code : + cupsLastError ()); + if (answer) + ippDelete (answer); ++ ++ debugprintf ("<- Connection_getPrinterAttributes() (error)\n"); + return NULL; + } + +@@ -2027,6 +2062,7 @@ Connection_getPrinterAttributes (Connect + size_t namelen = strlen (attr->name); + int is_list = attr->num_values > 1; + ++ debugprintf ("Attribute: %s\n", attr->name); + // job-sheets-default is special, since it is always two values. + // Make it a tuple. + if (!strcmp (attr->name, "job-sheets-default") && +@@ -2102,6 +2138,7 @@ Connection_getPrinterAttributes (Connect + break; + } + ++ debugprintf ("<- Connection_getPrinterAttributes() = dict\n"); + return ret; + } + +@@ -3317,13 +3354,17 @@ PyMethodDef Connection_methods[] = + "@raise IPPError: IPP problem" }, + + { "getPrinterAttributes", +- (PyCFunction) Connection_getPrinterAttributes, METH_VARARGS, +- "getPrinterAttributes(name) -> dict\n" +- "Fetch the attributes for a printer.\n\n" ++ (PyCFunction) Connection_getPrinterAttributes, ++ METH_VARARGS | METH_KEYWORDS, ++ "getPrinterAttributes() -> dict\n" ++ "Fetch the attributes for a printer, specified either by name or by \n" ++ "uri but not both.\n\n" + "@type name: string\n" + "@param name: queue name\n" ++ "@type uri: string\n" ++ "@param uri: queue URI\n" + "@return: a dict, indexed by attribute, of printer attributes\n" +- "for the printer 'name'.\n\n" ++ "for the specified printer.\n\n" + "Attributes:\n" + " - 'job-sheets-supported': list of strings\n" + " - 'job-sheets-default': tuple of strings (start, end)\n" +@@ -3332,7 +3373,7 @@ PyMethodDef Connection_methods[] = + " - 'printer-op-policy-supported': if present, list of strings\n" + " - 'printer-op-policy': if present, string\n\n" + "There are other attributes; the exact list of attributes returned \n" +- "will depend on the CUPS server.\n" ++ "will depend on the IPP server.\n" + "@raise IPPError: IPP problem"}, + + { "addPrinterToClass", +diff -U0 pycups-1.9.31/ChangeLog.attributes-uri pycups-1.9.31/ChangeLog diff --git a/system-config-printer-0.7.x.patch b/system-config-printer-0.7.x.patch new file mode 100644 index 0000000..772b60d --- /dev/null +++ b/system-config-printer-0.7.x.patch @@ -0,0 +1,63 @@ +diff -up system-config-printer-0.7.78/print-applet.desktop.in.0.7.x system-config-printer-0.7.78/print-applet.desktop.in +--- system-config-printer-0.7.78/print-applet.desktop.in.0.7.x 2007-11-22 15:23:59.000000000 +0000 ++++ system-config-printer-0.7.78/print-applet.desktop.in 2007-11-27 12:51:17.000000000 +0000 +@@ -5,6 +5,6 @@ _Comment=System tray icon for managing p + Exec=/usr/bin/system-config-printer-applet + Terminal=false + Type=Application +-Icon=printer.png ++Icon=printer + X-KDE-autostart-after=panel + StartupNotify=false +diff -up system-config-printer-0.7.78/system-config-printer.py.0.7.x system-config-printer-0.7.78/system-config-printer.py +--- system-config-printer-0.7.78/system-config-printer.py.0.7.x 2007-11-22 15:23:59.000000000 +0000 ++++ system-config-printer-0.7.78/system-config-printer.py 2007-11-27 12:51:17.000000000 +0000 +@@ -3231,10 +3231,16 @@ class NewPrinterGUI(GtkGUI): + try: + cups.setServer (match.group (2)) + c = cups.Connection () +- attributes = c.getPrinterAttributes (match.group (4)) ++ try: ++ attributes = c.getPrinterAttributes (uri = uri) ++ except TypeError: # uri keyword introduced in pycups 1.9.32 ++ print "Fetching printer attributes by name" ++ attributes = c.getPrinterAttributes (match.group (4)) + verified = True ++ except cups.IPPError (e, msg): ++ print "Failed to get attributes:", e, msg + except: +- pass ++ nonfatalError () + else: + print uri + +@@ -3279,9 +3285,8 @@ class NewPrinterGUI(GtkGUI): + printers = c.getPrinters () + classes = c.getClasses () + del c +- except RuntimeError: +- failed = True +- except cups.IPP_Error, (e, msg): ++ except: ++ nonfatalException() + failed = True + + gtk.gdk.threads_enter() +diff -U0 system-config-printer-0.7.78/ChangeLog.0.7.x system-config-printer-0.7.78/ChangeLog +--- system-config-printer-0.7.78/ChangeLog.0.7.x 2007-11-22 15:23:59.000000000 +0000 ++++ system-config-printer-0.7.78/ChangeLog 2007-11-27 12:51:17.000000000 +0000 +@@ -0,0 +1,14 @@ ++2007-11-27 Tim Waugh ++ ++ * system-config-printer.py ++ (NewPrinterGUI.browse_ipp_queues_thread): Handle exceptions other ++ than RuntimeError and cups.IPPError (bug #252304). ++ (NewPrinterGUI.on_btnIPPVerify_clicked): Get printer attributes by ++ printer URI not name, to prevent pycups constructing a CUPS URI ++ (bug #252304). ++ ++2007-11-22 Till Kamppeter ++ ++ * print-applet.desktop.in: Removed the last printer.png (Ubuntu package ++ did not build with Icon=printer.png in the .desktop file). ++ diff --git a/system-config-printer.spec b/system-config-printer.spec index d8d4f49..95fd8df 100644 --- a/system-config-printer.spec +++ b/system-config-printer.spec @@ -13,6 +13,7 @@ Source2: system-config-printer.pam Source3: system-config-printer.console Patch0: pycups-job-sheets.patch Patch1: pycups-attributes-uri.patch +Patch100: system-config-printer-0.7.x.patch BuildRequires: cups-devel >= 1.2 BuildRequires: python-devel >= 2.4 @@ -59,6 +60,8 @@ pushd pycups-%{pycups_version} %patch1 -p1 -b .attributes-uri popd +%patch100 -p1 -b .0.7.x + %build %configure @@ -130,6 +133,7 @@ exit 0 %changelog * Tue Nov 27 2007 Tim Waugh - pycups: Applied patch from SVN to allow fetching printer attributes by URI. +- Sync to SVN 1748. * Thu Nov 22 2007 Tim Waugh 0.7.78-1 - pycups: Fix job-sheets-default attribute.