Changeset 34a4e5d


Ignore:
Timestamp:
Jan 11, 2012, 4:51:13 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
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)
Message:

Cancelling jobs work

Location:
server/lib/gutenbach/server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/server/job.py

    rd21198f r34a4e5d  
    6969
    7070    @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
    7180    def creator(self):
    7281        """The user who created the job; analogous to the IPP
     
    118127    @property
    119128    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
    121132       
    122133    ######################################################################
     
    141152
    142153    def pause(self):
    143         if self.player:
     154        if self.is_playing:
    144155            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
    149161            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
    150169
    151170    def _completed(self):
    152         if self.state != States.PROCESSING:
    153             raise InvalidJobStateException(self.state)
    154171        logger.info("completed job %s" % str(self))
    155172        self.state = States.COMPLETE
     
    157174
    158175    def _canceled(self):
    159         if self.state != States.PROCESSING:
    160             raise InvalidJobStateException(self.state)
    161176        logger.info("canceled job %s" % str(self))
    162177        self.state = States.CANCELLED
    163178        self.player = None
    164179
    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.STOPPED
    170         self.player = None
    171 
    172180    def _aborted(self):
    173         if self.state != States.PROCESSING:
    174             raise InvalidJobStateException(self.state)
    175181        logger.info("aborted job %s" % str(self))
    176182        self.state = States.ABORTED
  • server/lib/gutenbach/server/printer.py

    rd21198f r34a4e5d  
    131131                    job_id = heapq.heappop(self.pending_jobs)
    132132                    self.current_job = self.get_job(job_id)
    133                     print "before play"
    134133                    self.current_job.play()
    135                     print "after play"
    136134                except IndexError:
    137135                    self.current_job = None
     
    265263        # Filter by the which-jobs attribute
    266264        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":
    269268            jobs = [self.jobs[job_id] for job_id in self.finished_jobs]
    270269        elif which_jobs == "not-completed":
  • server/lib/gutenbach/server/requests.py

    reee389a r34a4e5d  
     1from . import InvalidJobException, InvalidPrinterStateException, InvalidJobStateException
    12import gutenbach.ipp as ipp
    23import logging
     
    446447    @handler_for(ipp.OperationCodes.CANCEL_JOB)
    447448    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)
    449546
    450547    @handler_for(ipp.OperationCodes.SEND_DOCUMENT)
     
    504601            REQUIRED 'attributes-charset'
    505602            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)
    508605            OPTIONAL 'requesting-user-name' (name(MAX))
    509606            OPTIONAL 'document-name' (name(MAX))
     
    583680                ipp.DocumentNaturalLanguage)[0]
    584681
    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)
    594695
    595696        response.attribute_groups.append(ipp.AttributeGroup(
    596             ipp.AttributeTags.JOB, job.get_job_attributes()))
     697            ipp.AttributeTags.JOB, attrs))
    597698
    598699    @handler_for(ipp.OperationCodes.SEND_URI)
     
    647748            REQUIRED 'attributes-charset'
    648749            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)
    651752            OPTIONAL 'requesting-user-name' (name(MAX))
    652753            OPTIONAL 'requested-attributes' (1setOf keyword)
     
    694795
    695796        # 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
    698803        response.attribute_groups.append(ipp.AttributeGroup(
    699804            ipp.AttributeTags.JOB, attrs))
Note: See TracChangeset for help on using the changeset viewer.