Changeset ef387cf


Ignore:
Timestamp:
Jan 12, 2012, 1:49:56 AM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
20f7360
Parents:
609a9b0
git-author:
Jessica B. Hamrick <jhamrick@…> (01/12/12 01:49:56)
git-committer:
Jessica B. Hamrick <jhamrick@…> (01/12/12 01:49:56)
Message:

Add more documentation to job.py

File:
1 edited

Legend:

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

    r609a9b0 ref387cf  
    1515        """Create an empty Gutenbach job.
    1616
     17        Parameters
     18        ----------
     19        job_id : integer
     20            A unique id for this job.
     21        creator : string
     22            The user creating the job.
     23        name : string
     24            The human-readable name of the job.
     25        priority : integer
     26            The priority of the job, used for ordering.
     27        document : file object
     28            A file object containing the job data.
     29
    1730        """
    1831
     
    2437        self.name = name
    2538        self.priority = priority
     39       
    2640        self._why_done = None
    2741
     
    3650
    3751    def __cmp__(self, other):
     52        """Compares two GutenbachJobs based on their priorities.
     53
     54        """
    3855        return cmp(self.priority, other.priority)
    3956
     
    4461    @property
    4562    def id(self):
    46         """Unique job identifier.  Should be a positive integer,
    47         except when unassigned, when it defaults to -1.
     63        """Unique job identifier (integer).  Should be a positive
     64        integer, except when unassigned, when it defaults to -1.
    4865       
    4966        """
     
    5875    @property
    5976    def priority(self):
     77        """Job priority (integer).  Should be a nonzero positive
     78        integer; defaults to 1 when unassigned.
     79
     80        """
    6081        return self._priority
    6182    @priority.setter
     
    6889    @property
    6990    def creator(self):
    70         """The user who created the job; analogous to the IPP
    71         requesting-user-name.
     91        """The user who created the job (string).  Defaults to an
     92        empty string.
    7293
    7394        """
     
    82103    @property
    83104    def name(self):
    84         """The job's name.
     105        """The job's human-readable name (string).  Defaults to an
     106        empty string.
    85107
    86108        """
     
    95117    @property
    96118    def size(self):
    97         """The size of the job in bytes.
     119        """The size of the job in octets/bytes (integer).  Defaults to
     120        0 if no document is specified or if there is an error reading
     121        the document.
    98122
    99123        """
     
    115139
    116140        """
     141
    117142        return self.id > 0 and \
    118143               self.priority > 0
     
    120145    @property
    121146    def is_ready(self):
    122         """Whether the job is ready to be played.
    123 
    124         """
     147        """Whether the job is ready to be played; i.e., it has all the
     148        necessary data to actually play the audio data.
     149
     150        """
     151
    125152        return self.is_valid and \
    126153               self.player is not None and \
     
    135162
    136163        """
     164
    137165        return self.is_valid and \
    138166               self.player is not None and \
     
    144172
    145173        """
     174
    146175        return self.is_valid and \
    147176               self.player is not None and \
     
    154183
    155184        """
     185
    156186        return (self.is_valid and \
    157187                self.player is not None and \
     
    165195
    166196        """
     197
    167198        return self.is_done and self._why_done == "completed"
    168199
     
    172203
    173204        """
     205
    174206        return self.is_done and self._why_done == "cancelled"
    175207
     
    179211
    180212        """
     213
    181214        return self.is_done and self._why_done == "aborted"
    182215
    183216    @property
    184217    def state(self):
    185         """State status codes; equivalent to the IPP job-state status
    186         codes.
    187        
    188         State transitions are as follows:
    189         HELD ---> PENDING ---> PROCESSING <--> STOPPED (aka paused)
    190                      ^              |---> CANCELLED
    191                      |              |---> ABORTED
    192                      |              |---> COMPLETE ---|
    193                      |--------------------------------|
     218        """State status codes (these are equivalent to the IPP
     219        job-state status codes).  State transitions are as follows:
     220       
     221            HELD ---> PENDING ---> PROCESSING <--> STOPPED (aka paused)
     222                         ^              |---> CANCELLED
     223                         |              |---> ABORTED
     224                         |              |---> COMPLETE ---|
     225                         |--------------------------------|
    194226                     
    195227        """
     228
    196229        if self.is_ready:
    197230            state = States.PENDING
     
    216249    @staticmethod
    217250    def verify_document(document):
     251        """Verifies that a document has the 'name', 'read', and
     252        'close' attributes (i.e., it should be like a file object).
     253
     254        """
     255       
    218256        if not hasattr(document, "name"):
    219257            raise errors.InvalidDocument, "no name attribute"
     
    224262
    225263    def spool(self, document=None):
    226         """Non-blocking spool.  Job must be valid, and the document
    227         must be an open file handler.
     264        """Non-blocking spool.  Job must be valid (see
     265        'GutenbachJob.is_valid'), and the document must be an open
     266        file handler.
    228267
    229268        Raises
     
    245284
    246285    def play(self):
    247         """Non-blocking play.  Job must be ready.
     286        """Non-blocking play.  Job must be ready (see
     287        'GutenbachJob.is_ready').
    248288
    249289        Raises
     
    269309
    270310    def pause(self):
    271         """Non-blocking pause.  Job must be playing.
     311        """Non-blocking pause.  Job must be playing (see
     312        'GutenbachJob.is_playing').
    272313
    273314        Raises
     
    283324
    284325    def cancel(self):
    285         """Non-blocking cancel. The job must not have previously
    286         finished (i.e., cannot be aborted, cancelled, or completed).
    287         This should be used to stop the job following an external
    288         request.
     326        """Non-blocking cancel. The job must not have been previously
     327        aborted or completed (though this method will succeed if it
     328        was previously cancelled).  This should be used to stop the
     329        job following an external request.
    289330
    290331        Raises
     
    308349
    309350    def abort(self):
    310         """Non-blocking abort. The job must not have previously
    311         finished (i.e., cannot be aborted, cancelled, or completed).
    312         This should be used to stop the job following internal errors.
     351        """Non-blocking abort. The job must not have been previously
     352        cancelled or completed (though this method will succeed if it
     353        was previously aborted).  This should be used to stop the job
     354        following internal errors.
    313355
    314356        Raises
Note: See TracChangeset for help on using the changeset viewer.