Changeset 1a63bf7 for server/lib/gutenbach/server/job.py
- Timestamp:
- Dec 20, 2011, 11:17:58 AM (12 years ago)
- Branches:
- no-cups
- Children:
- 08a764a
- Parents:
- 6ed9d7a
- git-author:
- Jessica B. Hamrick <jhamrick@…> (12/20/11 11:17:58)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (12/20/11 11:17:58)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/job.py
rb2e077a r1a63bf7 7 7 class Job(object): 8 8 9 # for IPP 9 10 attributes = [ 10 11 "job-id", … … 14 15 "job-state", 15 16 "job-printer-uri" 16 17 ] 17 18 18 19 def __init__(self, document=None): … … 23 24 """ 24 25 25 self._id = None 26 self._name = document 27 self._status = None 28 self._document = document 29 self._printer = None 26 self.jid = None 27 self.name = document 28 self.status = None 29 self.document = document 30 self.printer = None 31 32 def __getattr__(self, attr): 33 try: 34 return super(Job, self).__getattr__(attr) 35 except AttributeError: 36 pass 37 38 return super(Job, self).__getattr__( 39 attr.replace("-", "_")) 40 41 def __hasattr__(self, attr): 42 has = super(Job, self).__hasattr__(attr) 43 if not has: 44 has = super(Job, self).__hasattr__( 45 attr.replace("-", "_")) 46 return has 47 48 #### Job attributes 30 49 31 50 @property 32 51 def job_id(self): 33 return ipp.Attribute( 34 'job-id', 35 [ipp.Value(ipp.Tags.INTEGER, self._id)]) 52 return self.jid 36 53 37 54 @property 38 55 def job_name(self): 39 return ipp.Attribute( 40 'job-name', 41 [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, self._name)]) 56 return self.name 42 57 43 58 # XXX: we need to actually calculate this! 44 59 @property 45 60 def job_originating_user_name(self): 46 return ipp.Attribute( 47 'job-originating-user-name', 48 [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, "jhamrick")]) 61 return "jhamrick" 49 62 50 63 # XXX: we need to actually calculate this! 51 64 @property 52 65 def job_k_octets(self): 53 return ipp.Attribute( 54 'job-k-octets', 55 [ipp.Value(ipp.Tags.INTEGER, 1)]) 66 return "job-k-octets" 56 67 57 68 @property 58 69 def job_state(self): 59 return ipp.Attribute( 60 'job-state', 61 [ipp.Value(ipp.Tags.ENUM, self._status)]) 70 return self.status 62 71 63 72 @property 64 73 def job_printer_uri(self): 65 return ipp.Attribute( 66 'job-printer-uri', 67 [ipp.Value(ipp.Tags.URI, self._printer._uri)]) 74 return self.printer.uri 68 75 69 76 def get_job_attributes(self, request): 70 attributes = [ getattr(self, attr.replace("-", "_")) for attr in self.attributes]77 attributes = [(attr, getattr(self, attr)) for attr in self.attributes] 71 78 return attributes 72 73 79 74 80 ####### 75 @property76 def document(self):77 return self._document78 79 @document.setter80 def document(self, path):81 if not os.path.exists(path):82 raise IOError("Document '%s' does not exist!" % path)83 self._document = path84 85 @property86 def status(self):87 return self._status88 89 @property90 def printer(self):91 return self._printer92 81 93 82 def enqueue(self, printer, job_id): 94 if self. _status != None:83 if self.status != None: 95 84 raise InvalidJobException( 96 85 "Cannot enqueue a job that has " + \ 97 86 "already been initialized!") 98 self. _printer = printer99 self. _job_id = job_id100 self. _status = const.JobStates.PENDING87 self.printer = printer 88 self.jid = job_id 89 self.status = const.JobStates.PENDING 101 90 102 91 def play(self): … … 105 94 "Cannot play an inactive job!") 106 95 107 self. _status = const.JobStates.PROCESSING96 self.status = const.JobStates.PROCESSING 108 97 # TODO: add external call to music player 109 98 print "Playing job %s" % str(self) 110 self. _printer.complete_job(self._id)99 self.printer.complete_job(self.jid) 111 100 112 101 def finish(self): 113 self. _status = const.JobStates.COMPLETE102 self.status = const.JobStates.COMPLETE 114 103 115 104 def __repr__(self): … … 118 107 def __str__(self): 119 108 return "<Job %d '%s'>" % \ 120 (self. _id if self._id is not None else -1, \121 self. _document)109 (self.jid if self.jid is not None else -1, \ 110 self.document)
Note: See TracChangeset
for help on using the changeset viewer.