Ignore:
Timestamp:
Dec 18, 2011, 11:18:16 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
9eeab06
Parents:
d04a689
git-author:
Jessica B. Hamrick <jhamrick@…> (12/18/11 23:18:16)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/18/11 23:18:16)
Message:

Refactor code to handle the operations a little bit more logically

File:
1 edited

Legend:

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

    rd04a689 rb2e077a  
    77class Job(object):
    88
     9    attributes = [
     10        "job-id",
     11        "job-name",
     12        "job-originating-user-name",
     13        "job-k-octets",
     14        "job-state",
     15        "job-printer-uri"
     16        ]
     17
    918    def __init__(self, document=None):
    1019        """Initialize a Gutenbach job.
     
    1423        """
    1524         
    16         self._jobid = None
    17         self._status = 'initializing'
     25        self._id = None
     26        self._name = document
     27        self._status = None
    1828        self._document = document
    1929        self._printer = None
    2030
    2131    @property
    22     def jobid(self):
    23         return self._jobid
     32    def job_id(self):
     33        return ipp.Attribute(
     34            'job-id',
     35            [ipp.Value(ipp.Tags.INTEGER, self._id)])
    2436
    25     @jobid.setter
    26     def jobid(self, val):
    27         raise AttributeError("Setting jobid is illegal!")
     37    @property
     38    def job_name(self):
     39        return ipp.Attribute(
     40            'job-name',
     41            [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, self._name)])
    2842
     43    # XXX: we need to actually calculate this!
     44    @property
     45    def job_originating_user_name(self):
     46        return ipp.Attribute(
     47            'job-originating-user-name',
     48            [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, "jhamrick")])
     49
     50    # XXX: we need to actually calculate this!
     51    @property
     52    def job_k_octets(self):
     53        return ipp.Attribute(
     54            'job-k-octets',
     55            [ipp.Value(ipp.Tags.INTEGER, 1)])
     56
     57    @property
     58    def job_state(self):
     59        return ipp.Attribute(
     60            'job-state',
     61            [ipp.Value(ipp.Tags.ENUM, self._status)])
     62
     63    @property
     64    def job_printer_uri(self):
     65        return ipp.Attribute(
     66            'job-printer-uri',
     67            [ipp.Value(ipp.Tags.URI, self._printer._uri)])
     68
     69    def get_job_attributes(self, request):
     70        attributes = [getattr(self, attr.replace("-", "_")) for attr in self.attributes]
     71        return attributes
     72
     73   
     74    #######
    2975    @property
    3076    def document(self):
     
    4187        return self._status
    4288
    43     @status.setter
    44     def status(self, val):
    45         raise AttributeError(
    46             "Setting status directly is illegal!  " + \
    47             "Please use enqueue(), play(), or finish().")
    48 
    4989    @property
    5090    def printer(self):
    5191        return self._printer
    5292
    53     @printer.setter
    54     def printer(self, val):
    55         raise AttributeError(
    56             "Setting printer directly is illegal!  " + \
    57             "Please use enqueue().")
    58 
    59     def enqueue(self, printer, jobid):
    60         if self.status != 'initializing':
     93    def enqueue(self, printer, job_id):
     94        if self._status != None:
    6195            raise InvalidJobException(
    6296                "Cannot enqueue a job that has " + \
    6397                "already been initialized!")
    6498        self._printer = printer
    65         self._jobid = jobid
    66         self._status = 'active'
     99        self._job_id = job_id
     100        self._status = const.JobStates.PENDING
    67101
    68102    def play(self):
     
    71105                "Cannot play an inactive job!")
    72106       
    73         self._status = 'playing'
     107        self._status = const.JobStates.PROCESSING
    74108        # TODO: add external call to music player
    75109        print "Playing job %s" % str(self)
    76         self.printer.complete_job(self.jobid)
     110        self._printer.complete_job(self._id)
    77111
    78112    def finish(self):
    79         self._status = 'finished'
     113        self._status = const.JobStates.COMPLETE
    80114
    81115    def __repr__(self):
     
    84118    def __str__(self):
    85119        return "<Job %d '%s'>" % \
    86                (self.jobid if self.jobid is not None else -1, \
    87                                   self.document)
     120               (self._id if self._id is not None else -1, \
     121                self._document)
Note: See TracChangeset for help on using the changeset viewer.