Changeset 951ab1b for server/lib
- Timestamp:
- Jan 11, 2012, 10:32:20 PM (12 years ago)
- Branches:
- no-cups
- Children:
- 190bfb4
- Parents:
- d518298
- git-author:
- Jessica B. Hamrick <jhamrick@…> (01/11/12 22:32:15)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (01/11/12 22:32:20)
- Location:
- server/lib/gutenbach/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/errors.py
reee389a r951ab1b 35 35 (self.errstr[self.state], hex(self.state)) 36 36 37 class InvalidDocument(Exception): 38 pass 37 39 class MissingDataException(Exception): 38 40 pass -
server/lib/gutenbach/server/job.py
ra2b0582 r951ab1b 1 from . errors import InvalidJobStateException, MissingDataException1 from . import errors 2 2 from .player import Player 3 3 from gutenbach.ipp import JobStates as States … … 23 23 self.name = name 24 24 self.priority = priority 25 self._why_done = None26 25 27 26 if document is not None: 28 27 self.spool(document) 28 29 self._why_done = None 29 30 30 31 def __repr__(self): … … 52 53 try: 53 54 self._id = max(int(val), -1) 54 except TypeError:55 except: 55 56 self._id = -1 56 57 … … 62 63 try: 63 64 self._priority = max(int(val), 1) 64 except TypeError:65 except: 65 66 self._priority = 1 66 67 … … 103 104 return size 104 105 106 ###################################################################### 107 ### State ### 108 ###################################################################### 109 105 110 @property 106 111 def is_valid(self): … … 145 150 @property 146 151 def is_done(self): 152 """Whether the job is done playing, regardless of whether it 153 completed successfully or not. 154 155 """ 147 156 return (self.is_valid and \ 148 157 self.player is not None and \ … … 150 159 (self._why_done == "cancelled" or \ 151 160 self._why_done == "aborted") 161 162 @property 163 def is_completed(self): 164 """Whether the job completed successfully. 165 166 """ 167 return self.is_done and self._why_done == "completed" 168 169 @property 170 def is_cancelled(self): 171 """Whether the job was cancelled. 172 173 """ 174 return self.is_done and self._why_done == "cancelled" 175 176 @property 177 def is_aborted(self): 178 """Whether the job was aborted. 179 180 """ 181 return self.is_done and self._why_done == "aborted" 152 182 153 183 @property … … 167 197 elif self.is_playing and self.is_paused: 168 198 state = States.STOPPED 169 elif self.is_ done and self._why_done == "completed":199 elif self.is_completed: 170 200 state = States.COMPLETE 171 elif self.is_ done and self._why_done == "cancelled":201 elif self.is_cancelled: 172 202 state = States.CANCELLED 173 elif self.is_ done and self._why_done == "aborted":203 elif self.is_aborted: 174 204 state = States.ABORTED 175 205 else: … … 181 211 ###################################################################### 182 212 183 def spool(self, document): 184 if not self.is_valid: 185 raise InvalidJobStateException(self.state) 213 @staticmethod 214 def verify_document(document): 215 if not hasattr(document, "name"): 216 raise errors.InvalidDocument, "no name attribute" 217 if not hasattr(document, "read"): 218 raise errors.InvalidDocument, "no read attribute" 219 if not hasattr(document, "close"): 220 raise errors.InvalidDocument, "no close attribute" 221 222 def spool(self, document=None): 223 """Non-blocking spool. Job must be valid, and the document 224 must be an open file handler. 225 226 Raises 227 ------ 228 InvalidDocument 229 If the document is not valid. 230 InvalidJobStateException 231 If the job is not valid or it is already 232 spooled/ready/finished. 233 234 """ 235 236 if not self.is_valid or self.state != States.HELD: 237 raise errors.InvalidJobStateException(self.state) 238 self.verify_document(document) 186 239 self.document = document.name 187 240 self.player = Player(document) … … 189 242 190 243 def play(self): 191 """Non-blocking play function. Sets the job state to 192 PROCESSING. 244 """Non-blocking play. Job must be ready. 193 245 194 246 Raises … … 202 254 # valid 203 255 if not self.is_ready: 204 raise InvalidJobStateException(self.state)256 raise errors.InvalidJobStateException(self.state) 205 257 206 258 # and set the state to processing if we're good to go … … 214 266 215 267 def pause(self): 216 """Non-blocking pause function. Sets the job state to 217 STOPPED. 268 """Non-blocking pause. Job must be playing. 269 270 Raises 271 ------ 272 InvalidJobStateException 273 If the job is not playing. 218 274 219 275 """ 220 276 221 277 if not self.is_playing: 222 raise InvalidJobStateException(self.state)278 raise errors.InvalidJobStateException(self.state) 223 279 self.player.mplayer_pause() 224 280 225 281 def cancel(self): 282 """Non-blocking cancel. The job must not have previously 283 finished (i.e., cannot be aborted, cancelled, or completed). 284 This should be used to stop the job following an external 285 request. 286 287 Raises 288 ------ 289 InvalidJobStateException 290 If the job has already finished. 291 292 """ 293 226 294 def _cancelled(): 227 295 logger.info("cancelled job %s" % str(self)) … … 232 300 self.player.mplayer_stop() 233 301 elif self.is_done and not self._why_done == "cancelled": 234 raise InvalidJobStateException(self.state)302 raise errors.InvalidJobStateException(self.state) 235 303 else: 236 304 _cancelled() 237 305 238 306 def abort(self): 307 """Non-blocking abort. The job must not have previously 308 finished (i.e., cannot be aborted, cancelled, or completed). 309 This should be used to stop the job following internal errors. 310 311 Raises 312 ------ 313 InvalidJobStateException 314 If the job has already finished. 315 316 """ 317 239 318 def _aborted(): 240 319 logger.info("aborted job %s" % str(self)) … … 245 324 self.player.mplayer_stop() 246 325 elif self.is_done and not self._why_done == "aborted": 247 raise InvalidJobStateException(self.state)326 raise errors.InvalidJobStateException(self.state) 248 327 else: 249 328 _aborted()
Note: See TracChangeset
for help on using the changeset viewer.