Changeset ef387cf for server/lib/gutenbach/server/job.py
- Timestamp:
- Jan 12, 2012, 1:49:56 AM (12 years ago)
- Branches:
- no-cups
- Children:
- 20f7360
- Parents:
- 609a9b0
- git-author:
- Jessica B. Hamrick <jhamrick@…> (01/12/12 01:49:56)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (01/12/12 01:49:56)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/job.py
r609a9b0 ref387cf 15 15 """Create an empty Gutenbach job. 16 16 17 Parameters 18 ---------- 19 job_id : integer 20 A unique id for this job. 21 creator : string 22 The user creating the job. 23 name : string 24 The human-readable name of the job. 25 priority : integer 26 The priority of the job, used for ordering. 27 document : file object 28 A file object containing the job data. 29 17 30 """ 18 31 … … 24 37 self.name = name 25 38 self.priority = priority 39 26 40 self._why_done = None 27 41 … … 36 50 37 51 def __cmp__(self, other): 52 """Compares two GutenbachJobs based on their priorities. 53 54 """ 38 55 return cmp(self.priority, other.priority) 39 56 … … 44 61 @property 45 62 def id(self): 46 """Unique job identifier . Should be a positive integer,47 except when unassigned, when it defaults to -1.63 """Unique job identifier (integer). Should be a positive 64 integer, except when unassigned, when it defaults to -1. 48 65 49 66 """ … … 58 75 @property 59 76 def priority(self): 77 """Job priority (integer). Should be a nonzero positive 78 integer; defaults to 1 when unassigned. 79 80 """ 60 81 return self._priority 61 82 @priority.setter … … 68 89 @property 69 90 def creator(self): 70 """The user who created the job ; analogous to the IPP71 requesting-user-name.91 """The user who created the job (string). Defaults to an 92 empty string. 72 93 73 94 """ … … 82 103 @property 83 104 def name(self): 84 """The job's name. 105 """The job's human-readable name (string). Defaults to an 106 empty string. 85 107 86 108 """ … … 95 117 @property 96 118 def size(self): 97 """The size of the job in bytes. 119 """The size of the job in octets/bytes (integer). Defaults to 120 0 if no document is specified or if there is an error reading 121 the document. 98 122 99 123 """ … … 115 139 116 140 """ 141 117 142 return self.id > 0 and \ 118 143 self.priority > 0 … … 120 145 @property 121 146 def is_ready(self): 122 """Whether the job is ready to be played. 123 124 """ 147 """Whether the job is ready to be played; i.e., it has all the 148 necessary data to actually play the audio data. 149 150 """ 151 125 152 return self.is_valid and \ 126 153 self.player is not None and \ … … 135 162 136 163 """ 164 137 165 return self.is_valid and \ 138 166 self.player is not None and \ … … 144 172 145 173 """ 174 146 175 return self.is_valid and \ 147 176 self.player is not None and \ … … 154 183 155 184 """ 185 156 186 return (self.is_valid and \ 157 187 self.player is not None and \ … … 165 195 166 196 """ 197 167 198 return self.is_done and self._why_done == "completed" 168 199 … … 172 203 173 204 """ 205 174 206 return self.is_done and self._why_done == "cancelled" 175 207 … … 179 211 180 212 """ 213 181 214 return self.is_done and self._why_done == "aborted" 182 215 183 216 @property 184 217 def state(self): 185 """State status codes; equivalent to the IPP job-state status 186 codes. 187 188 State transitions are as follows: 189 HELD ---> PENDING ---> PROCESSING <--> STOPPED (aka paused) 190 ^ |---> CANCELLED 191 | |---> ABORTED 192 | |---> COMPLETE ---| 193 |--------------------------------| 218 """State status codes (these are equivalent to the IPP 219 job-state status codes). State transitions are as follows: 220 221 HELD ---> PENDING ---> PROCESSING <--> STOPPED (aka paused) 222 ^ |---> CANCELLED 223 | |---> ABORTED 224 | |---> COMPLETE ---| 225 |--------------------------------| 194 226 195 227 """ 228 196 229 if self.is_ready: 197 230 state = States.PENDING … … 216 249 @staticmethod 217 250 def verify_document(document): 251 """Verifies that a document has the 'name', 'read', and 252 'close' attributes (i.e., it should be like a file object). 253 254 """ 255 218 256 if not hasattr(document, "name"): 219 257 raise errors.InvalidDocument, "no name attribute" … … 224 262 225 263 def spool(self, document=None): 226 """Non-blocking spool. Job must be valid, and the document 227 must be an open file handler. 264 """Non-blocking spool. Job must be valid (see 265 'GutenbachJob.is_valid'), and the document must be an open 266 file handler. 228 267 229 268 Raises … … 245 284 246 285 def play(self): 247 """Non-blocking play. Job must be ready. 286 """Non-blocking play. Job must be ready (see 287 'GutenbachJob.is_ready'). 248 288 249 289 Raises … … 269 309 270 310 def pause(self): 271 """Non-blocking pause. Job must be playing. 311 """Non-blocking pause. Job must be playing (see 312 'GutenbachJob.is_playing'). 272 313 273 314 Raises … … 283 324 284 325 def cancel(self): 285 """Non-blocking cancel. The job must not have previously286 finished (i.e., cannot be aborted, cancelled, or completed).287 This should be used to stop the job following an external288 request.326 """Non-blocking cancel. The job must not have been previously 327 aborted or completed (though this method will succeed if it 328 was previously cancelled). This should be used to stop the 329 job following an external request. 289 330 290 331 Raises … … 308 349 309 350 def abort(self): 310 """Non-blocking abort. The job must not have previously 311 finished (i.e., cannot be aborted, cancelled, or completed). 312 This should be used to stop the job following internal errors. 351 """Non-blocking abort. The job must not have been previously 352 cancelled or completed (though this method will succeed if it 353 was previously aborted). This should be used to stop the job 354 following internal errors. 313 355 314 356 Raises
Note: See TracChangeset
for help on using the changeset viewer.