Changeset 34a4e5d
- Timestamp:
- Jan 11, 2012, 4:51:13 PM (12 years ago)
- Branches:
- no-cups
- Children:
- 4126d3d
- Parents:
- d21198f
- git-author:
- Jessica B. Hamrick <jhamrick@…> (01/11/12 16:51:13)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (01/11/12 16:51:13)
- Location:
- server/lib/gutenbach/server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/job.py
rd21198f r34a4e5d 69 69 70 70 @property 71 def uri(self): 72 return self.uris[0] 73 74 @property 75 def uris(self): 76 return ["ipp://localhost/jobs/%d" % self.id, 77 "ipp://localhost:8000/jobs/%d" % self.id] 78 79 @property 71 80 def creator(self): 72 81 """The user who created the job; analogous to the IPP … … 118 127 @property 119 128 def is_finished(self): 120 return self.state != States.PENDING and self.state != States.PROCESSING 129 return self.state != States.PENDING and \ 130 self.state != States.PROCESSING and \ 131 self.state != States.HELD 121 132 122 133 ###################################################################### … … 141 152 142 153 def pause(self): 143 if self. player:154 if self.is_playing: 144 155 self.player.mplayer_pause() 145 146 def stop(self): 147 if self.player: 148 self.player.callback = self._stopped 156 self.state = States.STOPPED 157 158 def cancel(self): 159 if self.is_playing: 160 self.player.callback = self._canceled 149 161 self.player.mplayer_stop() 162 self.state = States.CANCELLED 163 164 def abort(self): 165 if self.is_playing: 166 self.player.callback = self._aborted 167 self.player.mplayer_stop() 168 self.state = states.ABORTED 150 169 151 170 def _completed(self): 152 if self.state != States.PROCESSING:153 raise InvalidJobStateException(self.state)154 171 logger.info("completed job %s" % str(self)) 155 172 self.state = States.COMPLETE … … 157 174 158 175 def _canceled(self): 159 if self.state != States.PROCESSING:160 raise InvalidJobStateException(self.state)161 176 logger.info("canceled job %s" % str(self)) 162 177 self.state = States.CANCELLED 163 178 self.player = None 164 179 165 def _stopped(self):166 if self.state != States.PROCESSING:167 raise InvalidJobStateException(self.state)168 logger.info("stopped job %s" % str(self))169 self.state = States.STOPPED170 self.player = None171 172 180 def _aborted(self): 173 if self.state != States.PROCESSING:174 raise InvalidJobStateException(self.state)175 181 logger.info("aborted job %s" % str(self)) 176 182 self.state = States.ABORTED -
server/lib/gutenbach/server/printer.py
rd21198f r34a4e5d 131 131 job_id = heapq.heappop(self.pending_jobs) 132 132 self.current_job = self.get_job(job_id) 133 print "before play"134 133 self.current_job.play() 135 print "after play"136 134 except IndexError: 137 135 self.current_job = None … … 265 263 # Filter by the which-jobs attribute 266 264 if which_jobs is None: 267 jobs = self.jobs.values() 268 elif which_jobs == "completed": 265 which_jobs = "not-completed" 266 267 if which_jobs == "completed": 269 268 jobs = [self.jobs[job_id] for job_id in self.finished_jobs] 270 269 elif which_jobs == "not-completed": -
server/lib/gutenbach/server/requests.py
reee389a r34a4e5d 1 from . import InvalidJobException, InvalidPrinterStateException, InvalidJobStateException 1 2 import gutenbach.ipp as ipp 2 3 import logging … … 446 447 @handler_for(ipp.OperationCodes.CANCEL_JOB) 447 448 def cancel_job(self, request, response): 448 raise ipp.errors.ServerErrorOperationNotSupported 449 """3.3.3 Cancel-Job Operation 450 451 This REQUIRED operation allows a client to cancel a Print Job from 452 the time the job is created up to the time it is completed, canceled, 453 or aborted. Since a Job might already be printing by the time a 454 Cancel-Job is received, some media sheet pages might be printed 455 before the job is actually terminated. 456 457 The IPP object MUST accept or reject the request based on the job's 458 current state and transition the job to the indicated new state as 459 follows: 460 461 Current State New State Response 462 ----------------------------------------------------------------- 463 pending canceled successful-ok 464 pending-held canceled successful-ok 465 processing canceled successful-ok 466 processing processing successful-ok See Rule 1 467 processing processing client-error-not-possible See Rule 2 468 processing-stopped canceled successful-ok 469 processing-stopped processing-stopped successful-ok See Rule 1 470 processing-stopped processing-stopped client-error-not-possible See Rule 2 471 completed completed client-error-not-possible 472 canceled canceled client-error-not-possible 473 aborted aborted client-error-not-possible 474 475 Rule 1: If the implementation requires some measurable time to 476 cancel the job in the 'processing' or 'processing-stopped' job 477 states, the IPP object MUST add the 'processing-to-stop-point' 478 value to the job's 'job-state-reasons' attribute and then 479 transition the job to the 'canceled' state when the processing 480 ceases (see section 4.3.8). 481 482 Rule 2: If the Job object already has the 483 'processing-to-stop-point' value in its 'job-state-reasons' 484 attribute, then the Printer object MUST reject a Cancel-Job 485 operation. 486 487 Access Rights: The authenticated user (see section 8.3) 488 performing this operation must either be the job owner or an 489 operator or administrator of the Printer object (see Sections 490 1 and 8.5). Otherwise, the IPP object MUST reject the 491 operation and return: 'client-error-forbidden', 492 'client-error-not-authenticated', or 493 'client-error-not-authorized' as appropriate. 494 495 Request 496 ------- 497 498 Group 1: Operation Attributes 499 REQUIRED 'attributes-charset' 500 REQUIRED 'attributes-natural-language' 501 REQUIRED 'job-id' (integer(1:MAX)) and 'printer-uri' (uri) 502 -or- 'job-uri' (uri) 503 OPTIONAL 'requesting-user-name' (name(MAX)) 504 OPTIONAL 'message' (text(127)) 505 506 Response 507 -------- 508 509 Group 1: Operation Attributes 510 OPTIONAL 'status-message' (text(255)) 511 OPTIONAL 'detailed-status-message' (text(MAX)) 512 REQUIRED 'attributes-charset' 513 REQUIRED 'attributes-natural-language' 514 Group 2: Unsupported Attributes 515 516 """ 517 518 operation = request.attribute_groups[0] 519 520 job_id = None 521 printer_uri = None 522 requesting_user_name = None 523 message = None 524 525 # required attributes 526 if 'job-id' in operation and 'printer-uri' in operation: 527 job_id = verify_attribute(operation['job-id'], ipp.JobId)[0] 528 printer_uri = verify_attribute(operation['printer-uri'], ipp.PrinterUri)[0] 529 if printer_uri not in self.printer.uris: 530 raise ipp.errors.ClientErrorAttributes( 531 str(operation['printer-uri']), operation['printer-uri']) 532 533 elif 'job-uri' in operation: 534 job_uri = verify_attribute(operation['job-uri'], ipp.JobUri)[0] 535 job_id = int(job_uri.split("/")[-1]) 536 537 if 'requesting-user-name' in operation: 538 user_name = verify_attribute( 539 operation['requesting-user-name'], ipp.RequestingUserName)[0] 540 541 try: 542 job = self.printer.get_job(job_id) 543 job.cancel() 544 except InvalidJobException: 545 raise ipp.errors.ClientErrorNotFound("bad job: %d" % job_id) 449 546 450 547 @handler_for(ipp.OperationCodes.SEND_DOCUMENT) … … 504 601 REQUIRED 'attributes-charset' 505 602 REQUIRED 'attributes-natural-language' 506 REQUIRED 'job-id' ( uri)507 OPTIONAL 'printer-uri' (uri)603 REQUIRED 'job-id' (integer(1:MAX)) and 'printer-uri' (uri) 604 -or- 'job-uri' (uri) 508 605 OPTIONAL 'requesting-user-name' (name(MAX)) 509 606 OPTIONAL 'document-name' (name(MAX)) … … 583 680 ipp.DocumentNaturalLanguage)[0] 584 681 585 job = self.printer.get_job(job_id) 586 job.send_document( 587 request.data, 588 requesting_user_name=user_name, 589 document_name=document_name, 590 compression=compression, 591 document_format=document_format, 592 document_natural_language=document_natural_language, 593 last_document=last_document) 682 try: 683 job = self.printer.get_job(job_id) 684 job.send_document( 685 request.data, 686 requesting_user_name=user_name, 687 document_name=document_name, 688 compression=compression, 689 document_format=document_format, 690 document_natural_language=document_natural_language, 691 last_document=last_document) 692 attrs = job.get_job_attributes() 693 except InvalidJobException: 694 raise ipp.errors.ClientErrorNotFound("bad job: %d" % job_id) 594 695 595 696 response.attribute_groups.append(ipp.AttributeGroup( 596 ipp.AttributeTags.JOB, job.get_job_attributes()))697 ipp.AttributeTags.JOB, attrs)) 597 698 598 699 @handler_for(ipp.OperationCodes.SEND_URI) … … 647 748 REQUIRED 'attributes-charset' 648 749 REQUIRED 'attributes-natural-language' 649 REQUIRED 'job-id' ( uri)650 OPTIONAL 'printer-uri' (uri)750 REQUIRED 'job-id' (integer(1:MAX)) and 'printer-uri' (uri) 751 -or- 'job-uri' (uri) 651 752 OPTIONAL 'requesting-user-name' (name(MAX)) 652 753 OPTIONAL 'requested-attributes' (1setOf keyword) … … 694 795 695 796 # get the job attributes and add them to the response 696 job = self.printer.get_job(job_id) 697 attrs = job.get_job_attributes(requested_attributes=requested_attributes) 797 try: 798 job = self.printer.get_job(job_id) 799 attrs = job.get_job_attributes(requested_attributes=requested_attributes) 800 except InvalidJobException: 801 raise ipp.errors.ClientErrorNotFound("bad job: %d" % job_id) 802 698 803 response.attribute_groups.append(ipp.AttributeGroup( 699 804 ipp.AttributeTags.JOB, attrs))
Note: See TracChangeset
for help on using the changeset viewer.