rpms/system-config-printer/devel pycups-attributes-uri.patch, NONE, 1.1 system-config-printer.spec, 1.147, 1.148

Tim Waugh (twaugh) fedora-extras-commits at redhat.com
Tue Nov 27 12:50:41 UTC 2007


Author: twaugh

Update of /cvs/pkgs/rpms/system-config-printer/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv17726

Modified Files:
	system-config-printer.spec 
Added Files:
	pycups-attributes-uri.patch 
Log Message:
* Tue Nov 27 2007 Tim Waugh <twaugh at redhat.com>
- pycups: Applied patch from SVN to allow fetching printer attributes by URI.


pycups-attributes-uri.patch:

--- NEW FILE pycups-attributes-uri.patch ---
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


Index: system-config-printer.spec
===================================================================
RCS file: /cvs/pkgs/rpms/system-config-printer/devel/system-config-printer.spec,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -r1.147 -r1.148
--- system-config-printer.spec	22 Nov 2007 15:32:38 -0000	1.147
+++ system-config-printer.spec	27 Nov 2007 12:50:08 -0000	1.148
@@ -12,6 +12,7 @@
 Source2: system-config-printer.pam
 Source3: system-config-printer.console
 Patch0: pycups-job-sheets.patch
+Patch1: pycups-attributes-uri.patch
 
 BuildRequires: cups-devel >= 1.2
 BuildRequires: python-devel >= 2.4
@@ -55,6 +56,7 @@
 %setup -q -a 1
 pushd pycups-%{pycups_version}
 %patch0 -p1 -b .job-sheets
+%patch1 -p1 -b .attributes-uri
 popd
 
 %build
@@ -126,6 +128,9 @@
 exit 0
 
 %changelog
+* Tue Nov 27 2007 Tim Waugh <twaugh at redhat.com>
+- pycups: Applied patch from SVN to allow fetching printer attributes by URI.
+
 * Thu Nov 22 2007 Tim Waugh <twaugh at redhat.com> 0.7.78-1
 - pycups: Fix job-sheets-default attribute.
 - Updated pycups to 1.9.31.




More information about the fedora-extras-commits mailing list