From 1b26791b0f4e7330e6c1debc2c98783a794ba2c9 Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Apr 22 2010 15:15:08 +0000 Subject: - Specify requested attributes in getJobs if possible (bug #584806). - Added optional requested_attributes argument to Connection.getJobs (bug #584806). --- diff --git a/pycups-add-getJobs-requested-attrs.patch b/pycups-add-getJobs-requested-attrs.patch new file mode 100644 index 0000000..6867f54 --- /dev/null +++ b/pycups-add-getJobs-requested-attrs.patch @@ -0,0 +1,198 @@ +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. diff --git a/system-config-printer-use-getJobs-requested-attrs.patch b/system-config-printer-use-getJobs-requested-attrs.patch new file mode 100644 index 0000000..f9ec21d --- /dev/null +++ b/system-config-printer-use-getJobs-requested-attrs.patch @@ -0,0 +1,34 @@ +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 diff --git a/system-config-printer.spec b/system-config-printer.spec index dbc6b67..a9a3924 100644 --- a/system-config-printer.spec +++ b/system-config-printer.spec @@ -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/pycups/pycups-%{pycups_version}.tar.bz2 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 - 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 - 1.2.1-1 - Updated to 1.2.1: - Fixed missing translations (bug #580442).