rpms/system-config-printer/devel pycups-add-getJobs-requested-attrs.patch, NONE, 1.1 system-config-printer-use-getJobs-requested-attrs.patch, NONE, 1.1 system-config-printer.spec, 1.390, 1.391

Tim Waugh twaugh at fedoraproject.org
Thu Apr 22 15:20:06 UTC 2010


Author: twaugh

Update of /cvs/pkgs/rpms/system-config-printer/devel
In directory cvs01.phx2.fedoraproject.org:/tmp/cvs-serv17119

Modified Files:
	system-config-printer.spec 
Added Files:
	pycups-add-getJobs-requested-attrs.patch 
	system-config-printer-use-getJobs-requested-attrs.patch 
Log Message:
* Thu Apr 22 2010 Tim Waugh <twaugh at redhat.com> - 1.2.1-2
- Specify requested attributes in getJobs if possible (bug #584806).
- Added optional requested_attributes argument to Connection.getJobs
  (bug #584806).


pycups-add-getJobs-requested-attrs.patch:
 NEWS             |    4 +
 cupsconnection.c |  130 +++++++++++++++++++++++++++++++++----------------------
 2 files changed, 84 insertions(+), 50 deletions(-)

--- NEW FILE pycups-add-getJobs-requested-attrs.patch ---
diff -U0 pycups-1.9.49/ChangeLog.add-getJobs-requested-attrs pycups-1.9.49/ChangeLog
diff -up pycups-1.9.49/cupsconnection.c.add-getJobs-requested-attrs pycups-1.9.49/cupsconnection.c
--- pycups-1.9.49/cupsconnection.c.add-getJobs-requested-attrs	2010-02-24 15:07:28.000000000 +0000
+++ pycups-1.9.49/cupsconnection.c	2010-04-22 16:02:33.425457367 +0100
@@ -1382,6 +1382,52 @@ Connection_getDevices (Connection *self,
   return result;
 }
 
+static int
+get_requested_attrs (PyObject *requested_attrs, size_t *n_attrs, char ***attrs)
+{
+  int i;
+  size_t n;
+  char **as;
+
+  if (!PyList_Check (requested_attrs)) {
+    PyErr_SetString (PyExc_TypeError, "List required");
+    return -1;
+  }
+
+  n = PyList_Size (requested_attrs);
+  as = malloc ((n + 1) * sizeof (char *));
+  for (i = 0; i < n; i++) {
+    PyObject *val = PyList_GetItem (requested_attrs, i); // borrowed ref
+    if (!PyString_Check (val)) {
+      PyErr_SetString (PyExc_TypeError, "String required");
+      while (--i >= 0)
+	free (as[i]);
+      free (as);
+      return -1;
+    }
+
+    as[i] = strdup (PyString_AsString (val));
+  }
+  as[n] = NULL;
+
+  debugprintf ("Requested attributes:\n");
+  for (i = 0; as[i] != NULL; i++)
+    debugprintf ("  %s\n", as[i]);
+
+  *n_attrs = n;
+  *attrs = as;
+  return 0;
+}
+
+static void
+free_requested_attrs (size_t n_attrs, char **attrs)
+{
+  int i;
+  for (i = 0; i < n_attrs; i++)
+    free (attrs[i]);
+  free (attrs);
+}
+
 static PyObject *
 Connection_getJobs (Connection *self, PyObject *args, PyObject *kwds)
 {
@@ -1392,10 +1438,14 @@ Connection_getJobs (Connection *self, Py
   int my_jobs = 0;
   int limit = -1;
   int first_job_id = -1;
+  PyObject *requested_attrs = NULL;
+  char **attrs = NULL; /* initialised to calm compiler */
+  size_t n_attrs = 0; /* initialised to calm compiler */
   static char *kwlist[] = { "which_jobs", "my_jobs", "limit", "first_job_id", 
-			    NULL };
-  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|siii", kwlist,
-				    &which, &my_jobs, &limit, &first_job_id))
+			    "requested_attributes", NULL };
+  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|siiiO", kwlist,
+				    &which, &my_jobs, &limit, &first_job_id,
+				    &requested_attrs))
 	  return NULL;
 
   debugprintf ("-> Connection_getJobs(%s,%d)\n",
@@ -1419,6 +1469,18 @@ Connection_getJobs (Connection *self, Py
     ippAddInteger (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
 		   "first-job-id", first_job_id);
 
+  if (requested_attrs) {
+    if (get_requested_attrs (requested_attrs, &n_attrs, &attrs) == -1) {
+      ippDelete (request);
+      return NULL;
+    }
+
+    ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+		   "requested-attributes", n_attrs, NULL,
+		   (const char **) attrs);
+    free_requested_attrs (n_attrs, attrs);
+  }
+
   debugprintf ("cupsDoRequest(\"/\")\n");
   Connection_begin_allow_threads (self);
   answer = cupsDoRequest (self->http, request, "/");
@@ -1474,6 +1536,18 @@ Connection_getJobs (Connection *self, Py
       else if (!strcmp (attr->name, "job-preserved") &&
 	       attr->value_tag == IPP_TAG_BOOLEAN)
 	val = PyBool_FromLong (attr->values[0].integer);
+      else {
+	if (attr->num_values > 1) {
+	  int i;
+	  val = PyList_New (0);
+	  for (i = 0; i < attr->num_values; i++) {
+	    PyObject *item = PyObject_from_attr_value (attr, i);
+	    if (item)
+	      PyList_Append (val, item);
+	  }
+	} else
+	  val = PyObject_from_attr_value (attr, 0);
+      }
 
       if (val) {
 	debugprintf ("Adding %s to job dict\n", attr->name);
@@ -1500,52 +1574,6 @@ Connection_getJobs (Connection *self, Py
   return result;
 }
 
-static int
-get_requested_attrs (PyObject *requested_attrs, size_t *n_attrs, char ***attrs)
-{
-  int i;
-  size_t n;
-  char **as;
-
-  if (!PyList_Check (requested_attrs)) {
-    PyErr_SetString (PyExc_TypeError, "List required");
-    return -1;
-  }
-
-  n = PyList_Size (requested_attrs);
-  as = malloc ((n + 1) * sizeof (char *));
-  for (i = 0; i < n; i++) {
-    PyObject *val = PyList_GetItem (requested_attrs, i); // borrowed ref
-    if (!PyString_Check (val)) {
-      PyErr_SetString (PyExc_TypeError, "String required");
-      while (--i >= 0)
-	free (as[i]);
-      free (as);
-      return -1;
-    }
-
-    as[i] = strdup (PyString_AsString (val));
-  }
-  as[n] = NULL;
-
-  debugprintf ("Requested attributes:\n");
-  for (i = 0; as[i] != NULL; i++)
-    debugprintf ("  %s\n", as[i]);
-
-  *n_attrs = n;
-  *attrs = as;
-  return 0;
-}
-
-static void
-free_requested_attrs (size_t n_attrs, char **attrs)
-{
-  int i;
-  for (i = 0; i < n_attrs; i++)
-    free (attrs[i]);
-  free (attrs);
-}
-
 static PyObject *
 Connection_getJobAttributes (Connection *self, PyObject *args, PyObject *kwds)
 {
@@ -4439,7 +4467,7 @@ PyMethodDef Connection_methods[] =
 
     { "getJobs",
       (PyCFunction) Connection_getJobs, METH_VARARGS | METH_KEYWORDS,
-      "getJobs(which_jobs='not-completed', my_jobs=False, limit=-1, first_job_id=-1) -> dict\n"
+      "getJobs(which_jobs='not-completed', my_jobs=False, limit=-1, first_job_id=-1, requested_attributes=None) -> dict\n"
       "Fetch a list of jobs.\n"
       "@type which_jobs: string\n"
       "@param which_jobs: which jobs to fetch; possible values: \n"
@@ -4453,6 +4481,8 @@ PyMethodDef Connection_methods[] =
       "@param limit: maximum number of jobs to return\n"
       "@type first_job_id: integer\n"
       "@param first_job_id: lowest job ID to return\n"
+      "@type requested_attributes: string list\n"
+      "@param requested_attributes: list of requested attribute names\n"
       "@raise IPPError: IPP problem" },
 
     { "getJobAttributes",
diff -up pycups-1.9.49/NEWS.add-getJobs-requested-attrs pycups-1.9.49/NEWS
--- pycups-1.9.49/NEWS.add-getJobs-requested-attrs	2010-01-19 12:33:26.000000000 +0000
+++ pycups-1.9.49/NEWS	2010-04-22 16:01:37.816457416 +0100
@@ -1,6 +1,10 @@
 NEWS
 ----
 
+New in 1.9.50:
+
+* cups.getJobs() now takes optional requested_attributes argument.
+
 New in 1.9.48:
 
 * cups.cancelJob()'s optional second argument is now a keyword.

system-config-printer-use-getJobs-requested-attrs.patch:
 monitor.py |   23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

--- NEW FILE system-config-printer-use-getJobs-requested-attrs.patch ---
diff -up system-config-printer-1.2.1/monitor.py.use-getJobs-requested-attrs system-config-printer-1.2.1/monitor.py
--- system-config-printer-1.2.1/monitor.py.use-getJobs-requested-attrs	2010-04-15 00:11:33.000000000 +0100
+++ system-config-printer-1.2.1/monitor.py	2010-04-22 16:05:28.493458040 +0100
@@ -608,11 +608,26 @@ class Monitor:
             return False
 
         limit = 1
+        r = ["job-id",
+             "job-printer-uri",
+             "job-state",
+             "job-originating-user-name",
+             "job-k-octets",
+             "job-name",
+             "time-at-creation"]
         try:
-            fetched = c.getJobs (which_jobs=self.which_jobs,
-                                 my_jobs=self.my_jobs,
-                                 first_job_id=self.fetch_first_job_id,
-                                 limit=limit)
+            try:
+                fetched = c.getJobs (which_jobs=self.which_jobs,
+                                     my_jobs=self.my_jobs,
+                                     first_job_id=self.fetch_first_job_id,
+                                     limit=limit,
+                                     requested_attributes=r)
+            except TypeError:
+                # requested_attributes requires pycups 1.9.50
+                fetched = c.getJobs (which_jobs=self.which_jobs,
+                                     my_jobs=self.my_jobs,
+                                     first_job_id=self.fetch_first_job_id,
+                                     limit=limit)
         except cups.IPPError, (e, m):
             self.watcher.cups_ipp_error (self, e, m)
             self.fetch_jobs_timer = None


Index: system-config-printer.spec
===================================================================
RCS file: /cvs/pkgs/rpms/system-config-printer/devel/system-config-printer.spec,v
retrieving revision 1.390
retrieving revision 1.391
diff -u -p -r1.390 -r1.391
--- system-config-printer.spec	14 Apr 2010 23:59:19 -0000	1.390
+++ system-config-printer.spec	22 Apr 2010 15:20:06 -0000	1.391
@@ -7,7 +7,7 @@
 Summary: A printer administration tool
 Name: system-config-printer
 Version: 1.2.1
-Release: 1%{?dist}
+Release: 2%{?dist}
 License: GPLv2+
 URL: http://cyberelk.net/tim/software/system-config-printer/
 Group: System Environment/Base
@@ -18,8 +18,10 @@ Source1: http://cyberelk.net/tim/data/py
 Source2: http://cyberelk.net/tim/data/pysmbc/pysmbc-%{pysmbc_version}.tar.bz2
 
 Patch1: system-config-printer-no-epydoc.patch
+Patch2: system-config-printer-use-getJobs-requested-attrs.patch
 
 Patch100: system-config-printer-pycups-build.patch
+Patch101: pycups-add-getJobs-requested-attrs.patch
 
 BuildRequires: cups-devel >= 1.2
 BuildRequires: python-devel >= 2.4
@@ -81,11 +83,18 @@ printers.
 # Don't require epydoc.
 %patch1 -p1 -b .no-epydoc
 
+# Specify requested attributes in getJobs if possible (bug #584806).
+%patch2 -p1 -b .use-getJobs-requested-attrs.patch
+
 pushd pycups-%{pycups_version}
 
 # Fixed pycups build with new distutils.
 %patch100 -p1 -b .pycups-build
 
+# Added optional requested_attributes argument to Connection.getJobs
+# (bug #584806).
+%patch101 -p1 -b .add-getJobs-requested-attrs
+
 popd
 
 %build
@@ -203,6 +212,11 @@ rm -rf %buildroot
 exit 0
 
 %changelog
+* Thu Apr 22 2010 Tim Waugh <twaugh at redhat.com> - 1.2.1-2
+- Specify requested attributes in getJobs if possible (bug #584806).
+- Added optional requested_attributes argument to Connection.getJobs
+  (bug #584806).
+
 * Thu Apr 15 2010 Tim Waugh <twaugh at redhat.com> - 1.2.1-1
 - Updated to 1.2.1:
   - Fixed missing translations (bug #580442).



More information about the scm-commits mailing list