Changeset 1a63bf7


Ignore:
Timestamp:
Dec 20, 2011, 11:17:58 AM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
08a764a
Parents:
6ed9d7a
git-author:
Jessica B. Hamrick <jhamrick@…> (12/20/11 11:17:58)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/20/11 11:17:58)
Message:

Remove ipp-specific objects from server/job and server/printers (but keep ipp-specific attribute names)

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

Legend:

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

    rb2e077a r1a63bf7  
    77class Job(object):
    88
     9    # for IPP
    910    attributes = [
    1011        "job-id",
     
    1415        "job-state",
    1516        "job-printer-uri"
    16         ]
     17    ]
    1718
    1819    def __init__(self, document=None):
     
    2324        """
    2425         
    25         self._id = None
    26         self._name = document
    27         self._status = None
    28         self._document = document
    29         self._printer = None
     26        self.jid = None
     27        self.name = document
     28        self.status = None
     29        self.document = document
     30        self.printer = None
     31
     32    def __getattr__(self, attr):
     33        try:
     34            return super(Job, self).__getattr__(attr)
     35        except AttributeError:
     36            pass
     37
     38        return super(Job, self).__getattr__(
     39            attr.replace("-", "_"))
     40
     41    def __hasattr__(self, attr):
     42        has = super(Job, self).__hasattr__(attr)
     43        if not has:
     44            has = super(Job, self).__hasattr__(
     45                attr.replace("-", "_"))
     46        return has
     47
     48    #### Job attributes
    3049
    3150    @property
    3251    def job_id(self):
    33         return ipp.Attribute(
    34             'job-id',
    35             [ipp.Value(ipp.Tags.INTEGER, self._id)])
     52        return self.jid
    3653
    3754    @property
    3855    def job_name(self):
    39         return ipp.Attribute(
    40             'job-name',
    41             [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, self._name)])
     56        return self.name
    4257
    4358    # XXX: we need to actually calculate this!
    4459    @property
    4560    def job_originating_user_name(self):
    46         return ipp.Attribute(
    47             'job-originating-user-name',
    48             [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, "jhamrick")])
     61        return "jhamrick"
    4962
    5063    # XXX: we need to actually calculate this!
    5164    @property
    5265    def job_k_octets(self):
    53         return ipp.Attribute(
    54             'job-k-octets',
    55             [ipp.Value(ipp.Tags.INTEGER, 1)])
     66        return "job-k-octets"
    5667
    5768    @property
    5869    def job_state(self):
    59         return ipp.Attribute(
    60             'job-state',
    61             [ipp.Value(ipp.Tags.ENUM, self._status)])
     70        return self.status
    6271
    6372    @property
    6473    def job_printer_uri(self):
    65         return ipp.Attribute(
    66             'job-printer-uri',
    67             [ipp.Value(ipp.Tags.URI, self._printer._uri)])
     74        return self.printer.uri
    6875
    6976    def get_job_attributes(self, request):
    70         attributes = [getattr(self, attr.replace("-", "_")) for attr in self.attributes]
     77        attributes = [(attr, getattr(self, attr)) for attr in self.attributes]
    7178        return attributes
    72 
    7379   
    7480    #######
    75     @property
    76     def document(self):
    77         return self._document
    78 
    79     @document.setter
    80     def document(self, path):
    81         if not os.path.exists(path):
    82             raise IOError("Document '%s' does not exist!" % path)
    83         self._document = path
    84 
    85     @property
    86     def status(self):
    87         return self._status
    88 
    89     @property
    90     def printer(self):
    91         return self._printer
    9281
    9382    def enqueue(self, printer, job_id):
    94         if self._status != None:
     83        if self.status != None:
    9584            raise InvalidJobException(
    9685                "Cannot enqueue a job that has " + \
    9786                "already been initialized!")
    98         self._printer = printer
    99         self._job_id = job_id
    100         self._status = const.JobStates.PENDING
     87        self.printer = printer
     88        self.jid = job_id
     89        self.status = const.JobStates.PENDING
    10190
    10291    def play(self):
     
    10594                "Cannot play an inactive job!")
    10695       
    107         self._status = const.JobStates.PROCESSING
     96        self.status = const.JobStates.PROCESSING
    10897        # TODO: add external call to music player
    10998        print "Playing job %s" % str(self)
    110         self._printer.complete_job(self._id)
     99        self.printer.complete_job(self.jid)
    111100
    112101    def finish(self):
    113         self._status = const.JobStates.COMPLETE
     102        self.status = const.JobStates.COMPLETE
    114103
    115104    def __repr__(self):
     
    118107    def __str__(self):
    119108        return "<Job %d '%s'>" % \
    120                (self._id if self._id is not None else -1, \
    121                 self._document)
     109               (self.jid if self.jid is not None else -1, \
     110                self.document)
  • server/lib/gutenbach/server/printer.py

    rb2e077a r1a63bf7  
    1212class GutenbachPrinter(object):
    1313
     14    # for IPP
    1415    attributes = [
    1516        "printer-uri-supported",
     
    3132        "pdl-override-supported",
    3233        "printer-up-time",
    33         "compression-supported"]
     34        "compression-supported"
     35    ]
    3436
    3537    #def __init__(self, name, card, mixer):
    3638    def __init__(self, name):
    3739
    38         self._name = name
    39         self._uri = "ipp://localhost:8000/printers/" + self._name
    40         self._time_created = int(time.time())
     40        self.name = name
     41        self.uri = "ipp://localhost:8000/printers/" + self.name
     42        self.time_created = int(time.time())
     43        self.state = "idle"
    4144
    4245        # if card >= len(aa.cards()):
     
    5659        self._next_jobid = 0
    5760
     61    def __getattr__(self, attr):
     62        try:
     63            return super(Printer, self).__getattr__(attr)
     64        except AttributeError:
     65            pass
     66
     67        return super(Printer, self).__getattr__(
     68            attr.replace("-", "_"))
     69
     70    def __hasattr__(self, attr):
     71        has = super(Printer, self).__hasattr__(attr)
     72        if not has:
     73            has = super(Printer, self).__hasattr__(
     74                attr.replace("-", "_"))
     75        return has
     76
    5877    ## Printer attributes
     78
    5979    @property
    6080    def printer_uri_supported(self):
    61         return ipp.Attribute(
    62             "printer-uri-supported",
    63             [ipp.Value(ipp.Tags.URI, self._uri)])
    64    
     81        return self.uri
     82
    6583    @property
    6684    def uri_authentication_supported(self):
    67         return ipp.Attribute(
    68             "uri-authentication-supported",
    69             [ipp.Value(ipp.Tags.KEYWORD, "none")])
     85        return "none"
    7086
    7187    @property
    7288    def uri_security_supported(self):
    73         return ipp.Attribute(
    74             "uri-security-supported",
    75             [ipp.Value(ipp.Tags.KEYWORD, "none")])
     89        return "none"
    7690
    7791    @property
    7892    def printer_name(self):
    79         return ipp.Attribute(
    80             "printer-name",
    81             [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE, self._name)])
    82        
     93        return self.name
     94
    8395    @property
    8496    def printer_state(self):
    85         return ipp.Attribute(
    86             "printer-state",
    87             [ipp.Value(ipp.Tags.ENUM, const.PrinterStates.IDLE)])
    88        
     97        return self.state
     98
    8999    @property
    90100    def printer_state_reasons(self):
    91         return ipp.Attribute(
    92             "printer-state-reasons",
    93             [ipp.Value(ipp.Tags.KEYWORD, "none")])
     101        return "none"
    94102
    95103    @property
    96104    def ipp_versions_supported(self):
    97         return ipp.Attribute(
    98             "ipp-versions-supported",
    99             [ipp.Value(ipp.Tags.KEYWORD, "1.0"),
    100              ipp.Value(ipp.Tags.KEYWORD, "1.1")])
    101 
     105        return ("1.0", "1.1")
    102106    # XXX: We should query ourself for the supported operations
     107
    103108    @property
    104109    def operations_supported(self):
    105         return ipp.Attribute(
    106             "operations-supported",
    107             [ipp.Value(ipp.Tags.ENUM, const.Operations.GET_JOBS)])
     110        return "get-jobs"
    108111
    109112    @property
    110113    def charset_configured(self):
    111         return ipp.Attribute(
    112             "charset-configured",
    113             [ipp.Value(ipp.Tags.CHARSET, "utf-8")])
     114        return "utf-8"
    114115
    115116    @property
    116117    def charset_supported(self):
    117         return ipp.Attribute(
    118             "charset-supported",
    119             [ipp.Value(ipp.Tags.CHARSET, "utf-8")])
     118        return "utf-8"
    120119
    121120    @property
    122121    def natural_language_configured(self):
    123         return ipp.Attribute(
    124             "natural-language-configured",
    125             [ipp.Value(ipp.Tags.NATURAL_LANGUAGE, "en-us")])
     122        return "en-us"
    126123
    127124    @property
    128125    def generated_natural_language_supported(self):
    129         return ipp.Attribute(
    130             "generated-natural-language-supported",
    131             [ipp.Value(ipp.Tags.NATURAL_LANGUAGE, "en-us")])
     126        return "en-us"
    132127
    133128    @property
    134129    def document_format_default(self):
    135         return ipp.Attribute(
    136             "document-format-default",
    137             [ipp.Value(ipp.Tags.MIME_MEDIA_TYPE, "application/octet-stream")])
     130        return "application/octet-stream"
    138131
    139132    @property
    140133    def document_format_supported(self):
    141         return ipp.Attribute(
    142             "document-format-supported",
    143             [ipp.Value(ipp.Tags.MIME_MEDIA_TYPE, "application/octet-stream"),
    144              ipp.Value(ipp.Tags.MIME_MEDIA_TYPE, "audio/mp3")])
     134        return ("application/octet-stream", "audio/mp3")
    145135
    146136    @property
    147137    def printer_is_accepting_jobs(self):
    148         return ipp.Attribute(
    149             "printer-is-accepting-jobs",
    150             [ipp.Value(ipp.Tags.BOOLEAN, True)])
     138        return True
    151139
    152140    @property
    153141    def queued_job_count(self):
    154         return ipp.Attribute(
    155             "queued-job-count",
    156             [ipp.Value(ipp.Tags.INTEGER, len(self.active_jobs))])
     142        return len(self.active_jobs)
    157143
    158144    @property
    159145    def pdl_override_supported(self):
    160         return ipp.Attribute(
    161             "pdl-override-supported",
    162             [ipp.Value(ipp.Tags.KEYWORD, "not-attempted")])
     146        return "not-attempted"
    163147
    164148    @property
    165149    def printer_up_time(self):
    166         return ipp.Attribute(
    167             "printer-up-time",
    168             [ipp.Value(ipp.Tags.INTEGER, int(time.time()) - self._time_created)])
     150        return int(time.time()) - self.time_created
    169151
    170152    @property
    171153    def compression_supported(self):
    172         return ipp.Attribute(
    173             "compression-supported",
    174             [ipp.Value(ipp.Tags.KEYWORD, "none")])
     154        return "none"
    175155
    176156    def get_printer_attributes(self, request):
    177         attributes = [getattr(self, attr.replace("-", "_")) for attr in self.attributes]
     157        attributes = [(attr, getattr(self, attr)) for attr in self.attributes]
    178158        return attributes
    179159
     
    229209
    230210    def __str__(self):
    231         return "<Printer '%s'>" % self._name
     211        return "<Printer '%s'>" % self.name
Note: See TracChangeset for help on using the changeset viewer.