Changeset 3413 for pykota/trunk/pykota/cups.py
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/cups.py
r3411 r3413 8 8 # the Free Software Foundation, either version 3 of the License, or 9 9 # (at your option) any later version. 10 # 10 # 11 11 # This program is distributed in the hope that it will be useful, 12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 # GNU General Public License for more details. 15 # 15 # 16 16 # You should have received a copy of the GNU General Public License 17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 25 25 try : 26 26 from pkipplib import pkipplib 27 except ImportError : 27 except ImportError : 28 28 raise RuntimeError, "The python-pkipplib module is now mandatory. You can download pkipplib from http://www.pykota.com/" 29 29 30 class JobTicket : 30 class JobTicket : 31 31 """A class to hold CUPS print job informations.""" 32 32 def __init__(self, jobid=None, printername=None, copies=1, filename=None, \ … … 50 50 if self.JobId is not None : 51 51 self.retrieveAttributesFromCUPS() 52 53 def getAttributeTypeAndValue(self, ippanswer, attribute, category="job") : 52 53 def getAttributeTypeAndValue(self, ippanswer, attribute, category="job") : 54 54 """Retrieves a particular attribute's type and value from an IPP answer. 55 55 56 56 Returns a tuple of the form (type, value). 57 57 """ 58 58 try : 59 59 return getattr(ippanswer, category)[attribute][0] 60 except KeyError : 60 except KeyError : 61 61 return (None, None) 62 62 63 63 def retrieveAttributesFromCUPS(self) : 64 64 """Retrieve attribute's values from CUPS.""" … … 77 77 (dummy, self.TimeAtProcessing) = self.getAttributeTypeAndValue(answer, "time-at-processing") 78 78 (dummy, self.MimeType) = self.getAttributeTypeAndValue(answer, "document-format") 79 80 for attrib in ("OriginatingUserName", 79 80 for attrib in ("OriginatingUserName", 81 81 "OriginatingHostName", 82 "Title", 82 "Title", 83 83 "BillingCode", 84 84 "PrinterName", … … 87 87 "UUID", 88 88 "MimeType") : 89 try : 90 setattr(self, attrib, 89 try : 90 setattr(self, attrib, 91 91 getattr(self, attrib).decode("UTF-8", "replace")) 92 except AttributeError : 92 except AttributeError : 93 93 pass 94 94 95 95 self.OriginalUserName = self.OriginatingUserName[:] 96 97 if __name__ == "__main__" : 96 97 if __name__ == "__main__" : 98 98 import sys 99 99 if len(sys.argv) != 2 : 100 100 sys.stderr.write("usage : python cups.py jobid\n") 101 else : 101 else : 102 102 job = JobTicket(int(sys.argv[1]), "FakePrinter") 103 for attribute in ("PrinterName", "Charset", "JobId", "Copies", 104 "FileName", "OriginatingUserName", 105 "Title", "BillingCode", "OriginatingHostName", 106 "TimeAtCreation", "TimeAtProcessing", "UUID", 103 for attribute in ("PrinterName", "Charset", "JobId", "Copies", 104 "FileName", "OriginatingUserName", 105 "Title", "BillingCode", "OriginatingHostName", 106 "TimeAtCreation", "TimeAtProcessing", "UUID", 107 107 "MimeType") : 108 108 sys.stdout.write("%s : %s\n" % (attribute, repr(getattr(job, attribute))))