Changes in / [b77e57e:079ef11]
- Location:
- server
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/errors.py
r5e70cc2 r951ab1b 13 13 14 14 class InvalidPrinterStateException(Exception): 15 errstr = {16 3: "idle",17 4: "processing",18 5: "stopped"19 }20 21 15 def __init__(self, state): 22 self.state = int(state)16 self.state = hex(state) 23 17 def __str__(self): 24 return "Invalid printer state: %s (%s)" % \ 25 (self.errstr[self.state], hex(self.state)) 18 return "Invalid printer state: %s" % self.state 26 19 27 20 class InvalidJobStateException(Exception): -
server/lib/gutenbach/server/job.py
r0494098 rbd5bffc 415 415 raise errors.InvalidJobStateException(self.state) 416 416 417 logger.debug("restarting job %d" , self.id)417 logger.debug("restarting job %d" % (self.id, self.document)) 418 418 419 419 self._why_done = None 420 fh = self.player.fh 421 422 if not fh or fh.closed: 423 raise RuntimeError, "file handler is closed" 424 425 self.player = Player(fh) 420 self.spool(self.document) -
server/lib/gutenbach/server/printer.py
r7e29e6a r57bc2dc 85 85 86 86 self.lock = threading.RLock() 87 self. _running = False87 self.running = False 88 88 self.paused = False 89 89 … … 91 91 self._next_job_id = 1 92 92 93 @sync94 93 def __repr__(self): 95 94 return str(self) 96 95 97 @sync98 96 def __str__(self): 99 return "<Printer '%s'>" % self.name 97 return "<Printer '%s'>" % self.name 100 98 101 99 def run(self): 102 self. _running = True103 while self. _running:104 try:105 with self.lock:106 if self.current_job is None:100 self.running = True 101 while self.running: 102 with self.lock: 103 try: 104 if not self.paused and self.current_job is None: 107 105 self.start_job() 108 106 elif self.current_job.is_done: 109 107 self.complete_job() 110 except:111 logger.fatal(traceback.format_exc())112 sys.exit(1)108 except: 109 logger.fatal(traceback.format_exc()) 110 sys.exit(1) 113 111 time.sleep(0.1) 114 112 115 def stop(self):116 with self.lock:117 self._running = False118 if self.ident is not None and self.isAlive():119 self.join()120 121 113 ###################################################################### 122 114 ### Properties ### 123 115 ###################################################################### 124 125 @property126 def name(self):127 return self._name128 @name.setter129 def name(self, val):130 try:131 self._name = str(val)132 except:133 self._name = "gutenbach-printer"134 135 @property136 def config(self):137 return self._config138 @config.setter139 def config(self, val):140 try:141 _config = dict(val).copy()142 except:143 raise ValueError, "not a dictionary"144 if 'ipp-versions' not in _config:145 raise ValueError, "missing ipp-versions"146 self._config = _config147 116 148 117 @property … … 159 128 @sync 160 129 def state(self): 161 if self. is_running and self.current_job is not None:162 state =States.PROCESSING163 elif self.is_running andlen(self.pending_jobs) == 0:164 state =States.IDLE130 if self.current_job is not None: 131 return States.PROCESSING 132 elif len(self.pending_jobs) == 0: 133 return States.IDLE 165 134 else: 166 state = States.STOPPED 167 return state 135 return States.STOPPED 168 136 169 137 @property … … 175 143 return jobs 176 144 177 @property178 def is_running(self):179 running = self.ident is not None and self.isAlive() and self._running180 return running181 182 145 ###################################################################### 183 146 ### Methods ### … … 185 148 186 149 @sync 187 def assert_running(self):188 if not self.is_running:189 raise RuntimeError, "%s not started" % str(self)190 191 @sync192 150 def start_job(self): 193 self.assert_running() 194 if not self.paused and self.current_job is None: 151 if self.current_job is None: 195 152 try: 196 153 job_id = heapq.heappop(self.pending_jobs) … … 205 162 @sync 206 163 def complete_job(self): 207 self.assert_running() 208 if not self.paused and self.current_job is not None: 209 try: 210 if not self.current_job.is_done: 211 self.current_job.stop() 212 finally: 213 self.finished_jobs.append(self.current_job.id) 214 self.current_job = None 164 if self.current_job is None: 165 return 166 167 try: 168 if not self.current_job.is_done: 169 self.current_job.stop() 170 finally: 171 self.finished_jobs.append(self.current_job.id) 172 self.current_job = None 215 173 216 174 @sync 217 175 def get_job(self, job_id): 218 self.assert_running()219 176 if job_id not in self.jobs: 220 177 raise InvalidJobException(job_id) … … 227 184 @property 228 185 def printer_uri_supported(self): 229 self.assert_running()230 186 return ipp.PrinterUriSupported(self.uri) 231 187 @printer_uri_supported.setter 232 188 def printer_uri_supported(self, val): 233 self.assert_running()234 189 raise ipp.errors.AttributesNotSettable("printer-uri-supported") 235 190 236 191 @property 237 192 def uri_authentication_supported(self): 238 self.assert_running()239 193 return ipp.UriAuthenticationSupported("none") 240 194 @uri_authentication_supported.setter 241 195 def uri_authentication_supported(self, val): 242 self.assert_running()243 196 raise ipp.errors.AttributesNotSettable("uri-authentication-supported") 244 197 245 198 @property 246 199 def uri_security_supported(self): 247 self.assert_running()248 200 return ipp.UriSecuritySupported("none") 249 201 @uri_security_supported.setter 250 202 def uri_security_supported(self, val): 251 self.assert_running()252 203 raise ipp.errors.AttributesNotSettable("uri-security-supported") 253 204 254 205 @property 255 206 def printer_name(self): 256 self.assert_running()257 207 return ipp.PrinterName(self.name) 258 208 @printer_name.setter 259 209 def printer_name(self, val): 260 self.assert_running()261 210 raise ipp.errors.AttributesNotSettable("printer-name") 262 211 263 212 @property 264 213 def printer_state(self): 265 self.assert_running()266 214 return ipp.PrinterState(self.state) 267 215 @printer_state.setter 268 216 def printer_state(self, val): 269 self.assert_running()270 217 raise ipp.errors.AttributesNotSettable("printer-state") 271 218 272 219 @property 273 220 def printer_state_reasons(self): 274 self.assert_running()275 221 return ipp.PrinterStateReasons("none") 276 222 @printer_state_reasons.setter 277 223 def printer_state_reasons(self, val): 278 self.assert_running()279 224 raise ipp.errors.AttributesNotSettable("printer-state-reasons") 280 225 281 226 @property 282 227 def ipp_versions_supported(self): 283 self.assert_running()284 228 return ipp.IppVersionsSupported(*self.config['ipp-versions']) 285 229 @ipp_versions_supported.setter 286 230 def ipp_versions_supported(self, val): 287 self.assert_running()288 231 raise ipp.errors.AttributesNotSettable("ipp-versions-supported") 289 232 … … 291 234 @property 292 235 def operations_supported(self): 293 self.assert_running()294 236 return ipp.OperationsSupported(ipp.OperationCodes.GET_JOBS) 295 237 @operations_supported.setter 296 238 def operations_supported(self, val): 297 self.assert_running()298 239 raise ipp.errors.AttributesNotSettable("operations-supported") 299 240 300 241 @property 301 242 def charset_configured(self): 302 self.assert_running()303 243 return ipp.CharsetConfigured("utf-8") # XXX 304 244 @charset_configured.setter 305 245 def charset_configured(self, val): 306 self.assert_running()307 246 raise ipp.errors.AttributesNotSettable("charset-configured") 308 247 309 248 @property 310 249 def charset_supported(self): 311 self.assert_running()312 250 return ipp.CharsetSupported("utf-8") # XXX 313 251 @charset_supported.setter 314 252 def charset_supported(self, val): 315 self.assert_running()316 253 raise ipp.errors.AttributesNotSettable("charset-supported") 317 254 318 255 @property 319 256 def natural_language_configured(self): 320 self.assert_running()321 257 return ipp.NaturalLanguageConfigured("en-us") 322 258 @natural_language_configured.setter 323 259 def natural_language_configured(self, val): 324 self.assert_running()325 260 raise ipp.errors.AttributesNotSettable("natural-language-configured") 326 261 327 262 @property 328 263 def generated_natural_language_supported(self): 329 self.assert_running()330 264 return ipp.GeneratedNaturalLanguageSupported("en-us") 331 265 @generated_natural_language_supported.setter 332 266 def generated_natural_language_supported(self, val): 333 self.assert_running()334 267 raise ipp.errors.AttributesNotSettable("generated-natural-language-supported") 335 268 336 269 @property 337 270 def document_format_default(self): 338 self.assert_running()339 271 return ipp.DocumentFormatDefault("application/octet-stream") 340 272 @document_format_default.setter 341 273 def document_format_default(self, val): 342 self.assert_running()343 274 raise ipp.errors.AttributesNotSettable("document-format-default") 344 275 345 276 @property 346 277 def document_format_supported(self): 347 self.assert_running()348 278 return ipp.DocumentFormatSupported("application/octet-stream", "audio/mp3") 349 279 @document_format_supported.setter 350 280 def document_format_supported(self, val): 351 self.assert_running()352 281 raise ipp.errors.AttributesNotSettable("document-format-supported") 353 282 354 283 @property 355 284 def printer_is_accepting_jobs(self): 356 self.assert_running()357 285 return ipp.PrinterIsAcceptingJobs(True) 358 286 @printer_is_accepting_jobs.setter 359 287 def printer_is_accepting_jobs(self, val): 360 self.assert_running()361 288 raise ipp.errors.AttributesNotSettable("printer-is-accepting-jobs") 362 289 363 290 @property 364 291 def queued_job_count(self): 365 self.assert_running()366 292 return ipp.QueuedJobCount(len(self.active_jobs)) 367 293 @queued_job_count.setter 368 294 def queued_job_count(self, val): 369 self.assert_running()370 295 raise ipp.errors.AttributesNotSettable("queued-job-count") 371 296 372 297 @property 373 298 def pdl_override_supported(self): 374 self.assert_running()375 299 return ipp.PdlOverrideSupported("not-attempted") 376 300 @pdl_override_supported.setter 377 301 def pdl_override_supported(self, val): 378 self.assert_running()379 302 raise ipp.errors.AttributesNotSettable("pdl-override-supported") 380 303 381 304 @property 382 305 def printer_up_time(self): 383 self.assert_running()384 306 return ipp.PrinterUpTime(int(time.time()) - self.time_created) 385 307 @printer_up_time.setter 386 308 def printer_up_time(self, val): 387 self.assert_running()388 309 raise ipp.errors.AttributesNotSettable("printer-up-time") 389 310 390 311 @property 391 312 def compression_supported(self): 392 self.assert_running()393 313 return ipp.CompressionSupported("none") 394 314 @compression_supported.setter 395 315 def compression_supported(self, val): 396 self.assert_running()397 316 raise ipp.errors.AttributesNotSettable("compression-supported") 398 317 399 318 @property 400 319 def multiple_operation_time_out(self): 401 self.assert_running()402 320 return ipp.MultipleOperationTimeOut(240) 403 321 @multiple_operation_time_out.setter 404 322 def multiple_operation_time_out(self, val): 405 self.assert_running()406 323 raise ipp.errors.AttributesNotSettable("multiple-operation-time-out") 407 324 408 325 @property 409 326 def multiple_document_jobs_supported(self): 410 self.assert_running()411 327 return ipp.MultipleDocumentJobsSupported(False) 412 328 @multiple_document_jobs_supported.setter 413 329 def multiple_document_jobs_supported(self, val): 414 self.assert_running()415 330 raise ipp.errors.AttributesNotSettable("multiple-document-jobs-supported") 416 331 … … 420 335 421 336 def job_id(self, job_id): 422 self.assert_running()423 337 job = self.get_job(job_id) 424 338 return ipp.JobId(job.id) 425 339 426 340 def job_name(self, job_id): 427 self.assert_running()428 341 job = self.get_job(job_id) 429 342 return ipp.JobName(job.name) 430 343 431 344 def job_originating_user_name(self, job_id): 432 self.assert_running()433 345 job = self.get_job(job_id) 434 346 return ipp.JobOriginatingUserName(job.creator) 435 347 436 348 def job_k_octets(self, job_id): 437 self.assert_running()438 349 job = self.get_job(job_id) 439 350 return ipp.JobKOctets(job.size) 440 351 441 352 def job_state(self, job_id): 442 self.assert_running()443 353 job = self.get_job(job_id) 444 354 return ipp.JobState(job.state) 445 355 446 356 def job_printer_uri(self, job_id): 447 self.assert_running()448 357 job = self.get_job(job_id) 449 358 return ipp.JobPrinterUri(self.uri) … … 453 362 ###################################################################### 454 363 455 @sync456 364 def print_job(self, document, document_name=None, document_format=None, 457 365 document_natural_language=None, requesting_user_name=None, 458 366 compression=None, job_name=None, job_k_octets=None): 459 460 self.assert_running()461 367 462 368 # create the job … … 479 385 return job_id 480 386 481 @sync 482 def validate_job(self, document_name=None, document_format=None, 483 document_natural_language=None, requesting_user_name=None, 484 compression=None, job_name=None, job_k_octets=None): 485 486 self.assert_running() 387 def verify_job(self, document_name=None, document_format=None, 388 document_natural_language=None, requesting_user_name=None, 389 compression=None, job_name=None, job_k_octets=None): 487 390 488 391 job_id = self._next_job_id … … 495 398 del job 496 399 497 @sync498 400 def get_jobs(self, requesting_user_name=None, which_jobs=None, 499 401 requested_attributes=None): 500 402 501 self.assert_running()502 503 403 # Filter by the which-jobs attribute 504 404 if which_jobs is None: … … 525 425 return job_attrs 526 426 527 @sync528 427 def print_uri(self): 529 self.assert_running() 530 531 @sync 428 pass 429 532 430 def create_job(self, requesting_user_name=None, job_name=None, 533 431 job_k_octets=None): 534 535 self.assert_running()536 432 537 433 job_id = self._next_job_id … … 554 450 Does nothing if the printer is already paused. 555 451 """ 556 557 self.assert_running()558 if not self.paused: 559 560 561 self.paused = True 562 logger.info("%s paused", str(self))452 if self.paused: 453 return 454 455 if self.current_job is not None and self.current_job.is_playing: 456 self.current_job.pause() 457 458 self.paused = True 563 459 564 460 @sync … … 568 464 Does nothing if the printer is not paused. 569 465 """ 570 571 self.assert_running()572 if self.paused: 573 574 575 self.paused = False 576 logger.info("%s unpaused", str(self))466 if not self.paused: 467 return 468 469 if self.current_job is not None: 470 self.current_job.resume() 471 472 self.paused = False 577 473 578 474 @sync 579 475 def get_printer_attributes(self, requested_attributes=None): 580 self.assert_running()581 476 if requested_attributes is None: 582 477 requested = self.printer_attributes … … 590 485 591 486 @sync 592 def set_printer_attributes(self, attributes): 593 self.assert_running() 487 def set_printer_attributes(self, job_id, attributes): 594 488 for attr in attributes: 595 489 try: … … 600 494 @sync 601 495 def cancel_job(self, job_id, requesting_user_name=None): 602 self.assert_running()603 496 job = self.get_job(job_id) 604 497 try: … … 614 507 last_document=None): 615 508 616 self.assert_running()617 509 job = self.get_job(job_id) 618 510 job.spool(document) … … 623 515 requesting_user_name=None, compression=None, 624 516 last_document=None): 625 626 self.assert_running()627 517 job = self.get_job(job_id) 628 518 # XXX: need to validate URI … … 632 522 @sync 633 523 def get_job_attributes(self, job_id, requested_attributes=None): 634 635 self.assert_running()636 524 if requested_attributes is None: 637 525 requested = self.job_attributes … … 646 534 @sync 647 535 def set_job_attributes(self, job_id, attributes): 648 649 self.assert_running()650 536 job = self.get_job(job_id) 651 537 for attr in attributes: … … 659 545 @sync 660 546 def restart_job(self, job_id, requesting_user_name=None): 661 662 self.assert_running()663 547 job = self.get_job(job_id) 664 548 try: … … 677 561 # completes, this one will go next 678 562 679 self.assert_running()680 563 job = self.get_job(job_id) 681 564 job.priority = 1 # XXX we need to actually do something -
server/lib/gutenbach/server/requests.py
rb77e57e r079ef11 169 169 170 170 """ 171 172 171 operation = request.attribute_groups[0] 173 172 document = request.data … … 179 178 compression = None 180 179 last_document = None 180 181 181 182 # requested printer uri 182 183 if 'printer-uri' not in operation: -
server/test/server/job.py
r0494098 rbd5bffc 201 201 202 202 def testRestart(self): 203 self.assertRaises(errors.InvalidJobStateException, self.job.restart) 204 205 self.job.play() 206 self.assertTrue(self.job.is_playing) 207 self.assertFalse(self.job.is_done) 208 209 self.assertRaises(errors.InvalidJobStateException, self.job.restart) 210 211 self.job.cancel() 212 self.assertFalse(self.job.is_playing) 213 self.assertTrue(self.job.is_done) 214 self.assertTrue(self.job.is_cancelled) 215 self.assertFalse(self.job.is_aborted) 216 217 self.job.restart() 218 self.assertTrue(self.job.is_ready) 203 # XXX: Todo 204 pass 219 205 220 206 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.