Changeset b2e077a for server/lib/gutenbach/server/job.py
- Timestamp:
- Dec 18, 2011, 11:18:16 PM (12 years ago)
- Branches:
- no-cups
- Children:
- 9eeab06
- Parents:
- d04a689
- git-author:
- Jessica B. Hamrick <jhamrick@…> (12/18/11 23:18:16)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (12/18/11 23:18:16)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/job.py
rd04a689 rb2e077a 7 7 class Job(object): 8 8 9 attributes = [ 10 "job-id", 11 "job-name", 12 "job-originating-user-name", 13 "job-k-octets", 14 "job-state", 15 "job-printer-uri" 16 ] 17 9 18 def __init__(self, document=None): 10 19 """Initialize a Gutenbach job. … … 14 23 """ 15 24 16 self._jobid = None 17 self._status = 'initializing' 25 self._id = None 26 self._name = document 27 self._status = None 18 28 self._document = document 19 29 self._printer = None 20 30 21 31 @property 22 def jobid(self): 23 return self._jobid 32 def job_id(self): 33 return ipp.Attribute( 34 'job-id', 35 [ipp.Value(ipp.Tags.INTEGER, self._id)]) 24 36 25 @jobid.setter 26 def jobid(self, val): 27 raise AttributeError("Setting jobid is illegal!") 37 @property 38 def job_name(self): 39 return ipp.Attribute( 40 'job-name', 41 [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, self._name)]) 28 42 43 # XXX: we need to actually calculate this! 44 @property 45 def job_originating_user_name(self): 46 return ipp.Attribute( 47 'job-originating-user-name', 48 [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, "jhamrick")]) 49 50 # XXX: we need to actually calculate this! 51 @property 52 def job_k_octets(self): 53 return ipp.Attribute( 54 'job-k-octets', 55 [ipp.Value(ipp.Tags.INTEGER, 1)]) 56 57 @property 58 def job_state(self): 59 return ipp.Attribute( 60 'job-state', 61 [ipp.Value(ipp.Tags.ENUM, self._status)]) 62 63 @property 64 def job_printer_uri(self): 65 return ipp.Attribute( 66 'job-printer-uri', 67 [ipp.Value(ipp.Tags.URI, self._printer._uri)]) 68 69 def get_job_attributes(self, request): 70 attributes = [getattr(self, attr.replace("-", "_")) for attr in self.attributes] 71 return attributes 72 73 74 ####### 29 75 @property 30 76 def document(self): … … 41 87 return self._status 42 88 43 @status.setter44 def status(self, val):45 raise AttributeError(46 "Setting status directly is illegal! " + \47 "Please use enqueue(), play(), or finish().")48 49 89 @property 50 90 def printer(self): 51 91 return self._printer 52 92 53 @printer.setter 54 def printer(self, val): 55 raise AttributeError( 56 "Setting printer directly is illegal! " + \ 57 "Please use enqueue().") 58 59 def enqueue(self, printer, jobid): 60 if self.status != 'initializing': 93 def enqueue(self, printer, job_id): 94 if self._status != None: 61 95 raise InvalidJobException( 62 96 "Cannot enqueue a job that has " + \ 63 97 "already been initialized!") 64 98 self._printer = printer 65 self._job id = jobid66 self._status = 'active'99 self._job_id = job_id 100 self._status = const.JobStates.PENDING 67 101 68 102 def play(self): … … 71 105 "Cannot play an inactive job!") 72 106 73 self._status = 'playing'107 self._status = const.JobStates.PROCESSING 74 108 # TODO: add external call to music player 75 109 print "Playing job %s" % str(self) 76 self. printer.complete_job(self.jobid)110 self._printer.complete_job(self._id) 77 111 78 112 def finish(self): 79 self._status = 'finished'113 self._status = const.JobStates.COMPLETE 80 114 81 115 def __repr__(self): … … 84 118 def __str__(self): 85 119 return "<Job %d '%s'>" % \ 86 (self. jobid if self.jobid is not None else -1, \87 self.document)120 (self._id if self._id is not None else -1, \ 121 self._document)
Note: See TracChangeset
for help on using the changeset viewer.