Ignore:
Timestamp:
Dec 27, 2011, 7:03:46 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
7c143c9
Parents:
1037115
git-author:
Jessica B. Hamrick <jhamrick@…> (12/27/11 19:03:46)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/27/11 19:03:46)
Message:

Fix error with HTTP server recreating printer objects

File:
1 edited

Legend:

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

    r793432f ree8e6d0  
    11#import alsaaudio as aa
    22from .exceptions import InvalidJobException, InvalidPrinterStateException
     3from .job import Job
    34import gutenbach.ipp as ipp
    45import logging
     
    169170        return ipp.MultipleDocumentJobsSupported(False)
    170171
    171     def get_printer_attributes(self, request):
    172         attributes = [getattr(self, attr) for attr in self.attributes]
     172    ## Printer operations
     173
     174    def get_printer_attributes(self, request=None):
     175        if request and 'requested-attributes' in request:
     176            requested = []
     177            for value in request['requested-attributes'].values:
     178                if value.value in self.attributes:
     179                    requested.append(value.value)
     180        else:
     181            requested = self.attributes
     182           
     183        attributes = [getattr(self, attr) for attr in requested]
    173184        return attributes
    174185
    175     ## Printer operations
     186    def create_job(self, request):
     187        operation = request.attribute_groups[0]
     188        kwargs = {}
     189       
     190        # requesting username
     191        if 'requesting-user-name' in operation:
     192            username_attr = operation['requesting-user-name']
     193            username = username_attr.values[0].value
     194            if username_attr != ipp.RequestingUserName(username):
     195                raise ipp.errors.ClientErrorBadRequest(str(username_attr))
     196            kwargs['creator'] = username
     197
     198        # job name
     199        if 'job-name' in operation:
     200            job_name_attr = operation['job-name']
     201            job_name = job_name_attr.values[0].value
     202            if job_name_attr != ipp.JobName(job_name):
     203                raise ipp.errors.ClientErrorBadRequest(str(job_name_attr))
     204            kwargs['name'] = job_name
     205
     206        # job size
     207        if 'job-k-octets' in operation:
     208            job_k_octets_attr = operation['job-k-octets']
     209            job_k_octets = job_k_octets_attr.values[0].value
     210            if job_k_octets_attr != ipp.JobKOctets(job_k_octets):
     211                raise ipp.errors.ClientErrorBadRequest(str(job_k_octets_attr))
     212            kwargs['size'] = job_k_octets
     213
     214        job_id = self._next_jobid
     215        self._next_jobid += 1
     216       
     217        job = Job(job_id, self, **kwargs)
     218        self.jobs[job_id] = job
     219        self.active_jobs.append(job_id)
     220        print self.active_jobs
     221        return job
    176222
    177223    def print_job(self, job):
    178         jobid = self._next_jobid
    179         self._next_jobid += 1
    180         self.active_jobs.append(jobid)
    181         self.jobs[jobid] = job
    182         job.enqueue(self, jobid)
    183         return jobid
     224        pass
    184225
    185226    def complete_job(self, jobid):
     
    214255
    215256    def get_jobs(self):
     257        print self.active_jobs
    216258        jobs = [self.jobs[job_id] for job_id in self.active_jobs]
    217         return jobs           
    218 
    219     def __repr__(self):
    220         return str(self)
    221 
    222     def __str__(self):
    223         return "<Printer '%s'>" % self.name
     259        return jobs
     260
     261    # def __repr__(self):
     262    #     return str(self)
     263
     264    # def __str__(self):
     265    #     return "<Printer '%s'>" % self.name
Note: See TracChangeset for help on using the changeset viewer.