Feature resquest extend lpstat job info

EmanuelSan at gmail.com EmanuelSan at gmail.com
Wed Feb 1 10:56:06 PST 2012


I need more information about jobs from the command "lpstat". I implemented a patch to address this request.

The output has its fields separated by tabs, to facilitate use by scripts. I implemented an option "-I" that uses the variable long_status to provide the new output.

The output contains information on copies (attr "copies"), priority ("job-priority"), status ("job-state") and page count ("page-count-informed," I need some help will implement this attribute).

Example of use:

Ex.:  ./lpstat -I Printer01
Date                    Pri     Cop     Size    #Pages  User    State           Job             Title
2012-01-26 22:55:19     30      5       620     0       ems     held            Printer01-84    Services 1
2012-01-26 22:56:03     30      5       627     0       henry   held            Printer01-85    Services 2
2012-01-26 22:56:45     33      9       633     0       henry   held            Printer01-86    Services 3
2012-01-26 22:57:35     60      9       645     0       henry   pending         Printer01-87    Services 4
2012-01-26 23:06:15     56      11      1       0       ems     held            Printer01-88    resolv
2012-01-27 00:32:04     55      2       1       0       carli   held            Printer01-94    (stdin)
2012-01-27 11:24:17     50      1       128     0       ems     held            Printer01-95    smbprn.00000015 Test Page
2012-01-31 19:35:10     50      3       1       0       henry   held            Printer01-99    resolv
2012-01-31 20:17:20     50      10      2       0       henry   completed       Printer01-100   resolv 2
2012-01-31 20:17:59     50      10      3       0       henry   held            Printer01-101   resolv 3
2012-01-31 20:19:41     50      2       25      0       henry   completed       Printer01-102   test.ps


I have patches for CUPS 1.4.2 (in use by RedHat Enterprise 6.2), 1.4.8, 1.5.0 and 1.6svn-r10201 (see below).

--- lpstat.c-ORIG       2011-10-07 18:05:19.000000000 -0300
+++ lpstat.c    2012-02-01 15:11:49.312872177 -0300
@@ -313,6 +313,8 @@ main(int  argc,                             /* I - Number of comm
              long_status = 2;
            break;

+        case 'I' : /* Show many jobs info by destination with tab separated fields */
+           long_status = 5;
         case 'o' : /* Show jobs by destination */
            op = 'o';

@@ -1257,6 +1259,45 @@ show_devices(const char  *printers,      /* I


 /*
+ * 'job_state_string()' - return string with job state
+ */
+
+static char *                                  /* O - static string with job state */
+job_state_string(const ipp_jstate_t jobstate)  /* I - job state enum */
+{
+    char *state;
+
+    switch (jobstate)
+    {
+      case IPP_JOB_PENDING :
+          state = _("pending");
+          break;
+      case IPP_JOB_HELD :
+          state = _("held");
+          break;
+      case IPP_JOB_PROCESSING :
+          state = _("processing");
+          break;
+      case IPP_JOB_STOPPED :
+          state = _("stopped");
+          break;
+      case IPP_JOB_CANCELED :
+          state = _("canceled");
+          break;
+      case IPP_JOB_ABORTED :
+          state = _("aborted");
+          break;
+      case IPP_JOB_COMPLETED :
+          state = _("completed");
+          break;
+      default :
+          state = _("unknown");
+          break;
+    }
+    return state;
+}
+
+/*
  * 'show_jobs()' - Show active print jobs.
  */

@@ -1275,10 +1316,16 @@ show_jobs(const char *dests,            /* I - Des
   const char   *dest,                  /* Pointer into job-printer-uri */
                *username,              /* Pointer to job-originating-user-name */
                *title,                 /* Pointer to job-name */
+                *state_string,          /* Pointer to job-state */
                *message;               /* Pointer to job-printer-state-message */
   int          rank,                   /* Rank in queue */
                jobid,                  /* job-id */
+                jobpriority,            /* job-priority */
+                jobcopies,              /* copies */
+                pagecountinf,           /* page count informed */
                size;                   /* job-k-octets */
+  ipp_jstate_t  jobstate;               /* job-state */
+
   time_t       jobtime;                /* time-at-creation */
   struct tm    *jobdate;               /* Date & time */
   char         temp[255],              /* Temporary buffer */
@@ -1292,6 +1339,10 @@ show_jobs(const char *dests,             /* I - Des
                  "job-printer-state-message",
                  "job-printer-uri",
                  "job-state-reasons",
+                 "job-state",
+                 "job-priority",
+                 "copies",
+                 "page-count-informed",
                  "time-at-creation"
                };

@@ -1347,6 +1398,9 @@ show_jobs(const char *dests,              /* I - Des
       return (1);
     }

+    if (long_status == 5)
+      _cupsLangPrintf(stdout, "Date              \tPri\tCop\tSize\t#Pages\tUser\tState     \tJob       \tTitle\n");
+
     rank = -1;

     for (attr = response->attrs; attr != NULL; attr = attr->next)
@@ -1373,6 +1427,11 @@ show_jobs(const char *dests,             /* I - Des
       title    = "no title";
       message  = NULL;
       reasons  = NULL;
+      state_string = "";
+      jobstate = IPP_JOB_PENDING;
+      jobpriority = 0;
+      jobcopies   = 1;
+      pagecountinf = 0;

       while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
       {
@@ -1404,9 +1463,27 @@ show_jobs(const char *dests,             /* I - Des
                 attr->value_tag == IPP_TAG_KEYWORD)
          reasons = attr;

+        if (!strcmp(attr->name, "job-state") &&
+           attr->value_tag == IPP_TAG_ENUM)
+         jobstate = attr->values[0].integer;
+
+        if (!strcmp(attr->name, "job-priority") &&
+           attr->value_tag == IPP_TAG_INTEGER)
+         jobpriority = attr->values[0].integer;
+
+        if (!strcmp(attr->name, "copies") &&
+           attr->value_tag == IPP_TAG_INTEGER)
+         jobcopies = attr->values[0].integer;
+
+        if (!strcmp(attr->name, "page-count-informed") &&
+           attr->value_tag == IPP_TAG_INTEGER)
+         pagecountinf = attr->values[0].integer;
+
         attr = attr->next;
       }

+      state_string = job_state_string (jobstate);
+
      /*
       * See if we have everything needed...
       */
@@ -1443,6 +1520,20 @@ show_jobs(const char *dests,             /* I - Des
                          temp, username ? username : "unknown",
                          size, title ? title : "unknown", date);
        }
+       else if (long_status == 5)
+       {
+        /*
+         * Show the output format for EMS long version
+         */
+
+         if (!strftime(date, sizeof(date), "%F %T", jobdate))
+           strcpy(date, "Unknown");
+
+          _cupsLangPrintf(stdout, "%s\t%d\t%d\t%d\t%d\t%s\t%-10s\t%s\t%s\n",
+                          date, jobpriority, jobcopies, size,
+                          pagecountinf, username ? username : "unknown",
+                          state_string, temp, title);
+       }
        else
        {
          if (!strftime(date, sizeof(date), "%c", jobdate))
@@ -1456,7 +1547,8 @@ show_jobs(const char *dests,              /* I - Des
            _cupsLangPrintf(stdout, "%-23s %-13s %8.0f   %s",
                            temp, username ? username : "unknown",
                            1024.0 * size, date);
-          if (long_status)
+
+          if (long_status && long_status != 5)
           {
            if (message)
              _cupsLangPrintf(stdout, _("\tStatus: %s"), message);






More information about the cups mailing list