Ignore:
Timestamp:
Jan 11, 2012, 6:58:43 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
09790fe
Parents:
4126d3d
git-author:
Jessica B. Hamrick <jhamrick@…> (01/11/12 18:58:43)
git-committer:
Jessica B. Hamrick <jhamrick@…> (01/11/12 18:58:43)
Message:

Keep IPP code in GutenbachPrinter?, not in GutenbachJob?

File:
1 edited

Legend:

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

    r34a4e5d r33ea505  
    1 from . import InvalidJobException, InvalidPrinterStateException, InvalidJobStateException
    2 from . import Job
     1from .errors import InvalidJobException, InvalidPrinterStateException, InvalidJobStateException
     2from .job import GutenbachJob
    33from gutenbach.ipp import PrinterStates as States
    44import gutenbach.ipp as ipp
     
    1717
    1818    # for IPP
    19     attributes = [
     19    printer_attributes = [
    2020        "printer-uri-supported",
    2121        "uri-authentication-supported",
     
    4141    ]
    4242
     43    job_attributes = [
     44        "job-id",
     45        "job-name",
     46        "job-originating-user-name",
     47        "job-k-octets",
     48        "job-state",
     49        "job-printer-uri"
     50    ]
     51
    4352    operations = [
    4453        "print-job",
    45         "complete-job",
    46         "start-job",
    47         "get-job",
     54        "validate-job",
    4855        "get-jobs",
     56        "print-uri",
     57        "create-job",
     58        "pause-printer",
     59        "resume-printer",
     60        "get-printer-attributes",
     61        "set-printer-attributes",
     62        "cancel-job",
     63        "send-document",
     64        "send-uri",
     65        "get-job-attributes",
     66        "set-job-attributes",
     67        "restart-job",
     68        "promote-job"
    4969    ]
    5070       
     
    7393    def __str__(self):
    7494        return "<Printer '%s'>" % self.name
    75 
    76     ######################################################################
    77     ###                          Properties                            ###
    78     ######################################################################
    79 
    80     @property
    81     def uris(self):
    82         uris = ["ipp://localhost:8000/printers/" + self.name,
    83                 "ipp://localhost/printers/" + self.name]
    84         return uris
    85    
    86     @property
    87     def uri(self):
    88         return self.uris[0]
    89 
    90     @property
    91     def state(self):
    92         with self.lock:
    93             if self.current_job is not None:
    94                 val = States.PROCESSING
    95             elif len(self.pending_jobs) == 0:
    96                 val = States.IDLE
    97             else:
    98                 val = States.STOPPED
    99         return val
    100 
    101     @property
    102     def active_jobs(self):
    103         with self.lock:
    104             jobs = self.pending_jobs[:]
    105             if self.current_job is not None:
    106                 jobs.insert(0, self.current_job.id)
    107         return jobs
    108 
    109     ######################################################################
    110     ###                            Methods                             ###
    111     ######################################################################
    11295
    11396    def run(self):
     
    124107                    sys.exit(1)
    125108            time.sleep(0.1)
     109
     110    ######################################################################
     111    ###                          Properties                            ###
     112    ######################################################################
     113
     114    @property
     115    def uris(self):
     116        uris = ["ipp://localhost:8000/printers/" + self.name,
     117                "ipp://localhost/printers/" + self.name]
     118        return uris
     119   
     120    @property
     121    def uri(self):
     122        return self.uris[0]
     123
     124    @property
     125    def state(self):
     126        with self.lock:
     127            if self.current_job is not None:
     128                val = States.PROCESSING
     129            elif len(self.pending_jobs) == 0:
     130                val = States.IDLE
     131            else:
     132                val = States.STOPPED
     133        return val
     134
     135    @property
     136    def active_jobs(self):
     137        with self.lock:
     138            jobs = self.pending_jobs[:]
     139            if self.current_job is not None:
     140                jobs.insert(0, self.current_job.id)
     141        return jobs
     142
     143    ######################################################################
     144    ###                            Methods                             ###
     145    ######################################################################
    126146
    127147    def start_job(self):
     
    150170                self.current_job = None
    151171
    152     def stop(self):
    153         pass
    154 
    155172    def get_job(self, job_id):
    156173        with self.lock:
     
    249266        return ipp.MultipleDocumentJobsSupported(False)
    250267
     268    ######################################################################
     269    ###                      Job IPP Attributes                        ###
     270    ######################################################################
     271
     272    def job_id(self, job_id):
     273        job = self.get_job(job_id)
     274        return ipp.JobId(job.id)
     275
     276    def job_name(self, job_id):
     277        job = self.get_job(job_id)
     278        return ipp.JobName(job.name)
     279
     280    def job_originating_user_name(self, job_id):
     281        job = self.get_job(job_id)
     282        return ipp.JobOriginatingUserName(job.creator)
     283
     284    def job_k_octets(self, job_id):
     285        job = self.get_job(job_id)
     286        return ipp.JobKOctets(job.size)
     287
     288    def job_state(self, job_id):
     289        job = self.get_job(job_id)
     290        return ipp.JobState(job.state)
     291
     292    def job_printer_uri(self, job_id):
     293        job = self.get_job(job_id)
     294        return ipp.JobPrinterUri(self.uri)
    251295
    252296    ######################################################################
     
    260304        pass
    261305
    262     def get_jobs(self, requesting_user_name="", which_jobs=None):
     306    def get_jobs(self, requesting_user_name=None, which_jobs=None,
     307                 requested_attributes=None):
     308       
    263309        # Filter by the which-jobs attribute
    264310        if which_jobs is None:
     
    278324        else:
    279325            user_jobs = [job for job in jobs if job.creator == requesting_user_name]
    280        
    281         return user_jobs
     326
     327        # Get the attributes of each job
     328        job_attrs = [self.get_job_attributes(
     329            job.id, requested_attributes=requested_attributes) for job in user_jobs]
     330       
     331        return job_attrs
    282332
    283333    def print_uri(self):
     
    288338        self._next_job_id += 1
    289339       
    290         job = Job(job_id,
    291                   self,
    292                   creator=requesting_user_name,
    293                   name=job_name,
    294                   size=job_k_octets)
     340        job = GutenbachJob(
     341            job_id,
     342            creator=requesting_user_name,
     343            name=job_name)
    295344       
    296345        self.jobs[job_id] = job
    297346        self.pending_jobs.append(job_id)
    298347       
    299         return job
     348        return job_id
    300349
    301350    def pause_printer(self):
     
    307356    def get_printer_attributes(self, requested_attributes=None):
    308357        if requested_attributes is None:
    309             requested = self.attributes
     358            requested = self.printer_attributes
    310359        else:
    311             requested = [a for a in self.attributes if a in requested_attributes]
     360            requested = [a for a in self.printer_attributes \
     361                         if a in requested_attributes]
    312362
    313363        _attributes = [attr.replace("-", "_") for attr in requested]
     
    317367    def set_printer_attributes(self):
    318368        pass
     369
     370    def cancel_job(self, job_id, requesting_user_name=None):
     371        job = self.get_job(job_id)
     372        try:
     373            job.cancel()
     374        except InvalidJobStateException:
     375            # XXX
     376            raise
     377
     378    def send_document(self, job_id, document, document_name=None,
     379                      document_format=None, document_natural_language=None,
     380                      requesting_user_name=None, compression=None,
     381                      last_document=None):
     382
     383        job = self.get_job(job_id)
     384        job.spool(document, username=requesting_user_name)
     385
     386    def send_uri(self):
     387        pass
     388
     389    def get_job_attributes(self, job_id, requested_attributes=None):
     390        if requested_attributes is None:
     391            requested = self.job_attributes
     392        else:
     393            requested = [a for a in self.job_attributes \
     394                         if a in requested_attributes]
     395
     396        _attributes = [attr.replace("-", "_") for attr in requested]
     397        attributes = [getattr(self, attr)(job_id) for attr in _attributes]
     398        return attributes
     399
     400    def set_job_attributes(self):
     401        pass
     402
     403    def restart_job(self):
     404        pass
     405
     406    def promote_job(self):
     407        pass
Note: See TracChangeset for help on using the changeset viewer.