~romaia/stoqdrivers/hudson-test

« back to all changes in this revision

Viewing changes to stoqdrivers/devices/printers/base.py

  • Committer: henrique
  • Date: 2006-01-03 21:04:00 UTC
  • Revision ID: vcs-imports@canonical.com-20060103210400-i1apdu7e8qr1ssr4


Fix for bug #700: Stoqdrivers exception messages should be internationalized
r=jdahlin


Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    Generic base class implementation for all printers
30
30
"""
31
31
import os
 
32
import gettext
32
33
 
33
34
from zope.interface import providedBy
34
35
from kiwi.python import namedAny
40
41
from stoqdrivers.devices.printers.interface import (ICouponPrinter,
41
42
                                                    IChequePrinter)
42
43
 
 
44
_ = lambda msg: gettext.dgettext("stoqdrivers", msg)
 
45
 
43
46
class BasePrinter(Logger):
44
47
    log_domain = "stoqdrivers"
45
48
    
52
55
        if not self.model or not self.brand or not self.device:
53
56
            self.config = StoqdriversConfig(config_file)
54
57
            if not self.config.has_section("Printer"):
55
 
                raise ConfigError("There is no printer configured!")
 
58
                raise ConfigError(_("There is no printer configured!"))
56
59
            self.brand = self.config.get_option("brand", "Printer")
57
60
            self.device = self.config.get_option("device", "Printer")
58
61
            self.model = self.config.get_option("model", "Printer")
61
64
        try:
62
65
            module = __import__(name, None, None, 'stoqdevices')
63
66
        except ImportError, reason:
64
 
            raise CriticalError(("Could not load driver %s %s: %s"
65
 
                                 % (self.brand.capitalize(),
66
 
                                    self.model.upper(), reason)))
 
67
            raise CriticalError("Could not load driver %s %s: %s"
 
68
                                % (self.brand.capitalize(),
 
69
                                   self.model.upper(), reason))
67
70
 
68
71
        class_name = self.model
69
72
 
70
73
        driver_class = getattr(module, class_name, None)
71
74
        if not driver_class:
72
 
            raise CriticalError(("Printer driver %s needs a class called %s"
73
 
                                 % (name, class_name)))
 
75
            raise CriticalError("Printer driver %s needs a class called %s"
 
76
                                % (name, class_name))
74
77
 
75
78
        self._driver = driver_class(device=self.device)
76
79
 
80
83
        driver_interfaces = providedBy(self._driver)
81
84
        if not (ICouponPrinter in driver_interfaces):
82
85
            raise TypeError("The driver %s doesn't implements a known "
83
 
                            "interface")
 
86
                            "interface" % self._driver)
84
87
 
85
88
def get_virtual_printer():
86
89
    from stoqdrivers.devices.printers.fiscal import FiscalPrinter
112
115
                                  % (model_name, model_name))
113
116
            if not (IChequePrinter.implementedBy(obj) or
114
117
                    ICouponPrinter.implementedBy(obj)):
115
 
                raise TypeError("The driver %s %s doesn't implements a valid "
116
 
                                "interface" % (brand, model_name))
117
 
                
 
118
                raise TypeError("The driver %s %s doesn't implements a "
 
119
                                "valid interface" % (brand, model_name))
118
120
            result[brand].append(obj)
119
121
 
120
122
    return result