~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/hardwaredb/scripts/hwdbsubmissions.py

  • Committer: j.c.sackett
  • Date: 2011-04-05 21:07:50 UTC
  • mto: This revision was merged to the branch mainline in revision 12787.
  • Revision ID: jonathan.sackett@canonical.com-20110405210750-o2vbguaovqhyy7jx
Added a context manager to allow the disabling of oops handling when needed in cronscripts, and updated tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    ErrorReportingUtility,
57
57
    ScriptRequest,
58
58
    )
 
59
from lp.services.scripts.base import disable_oops_handler
59
60
 
60
61
_relax_ng_files = {
61
62
    '1.0': 'hardware-1_0.rng', }
135
136
        self._setHardwareSectionParsers()
136
137
        self._setSoftwareSectionParsers()
137
138
 
138
 
    def _logError(self, message, submission_key):
 
139
    def _logError(self, message, submission_key, create_oops=True):
139
140
        """Log `message` for an error in submission submission_key`."""
140
 
        self.logger.error(
141
 
            'Parsing submission %s: %s' % (submission_key, message))
 
141
        msg = 'Parsing submission %s: %s' % (submission_key, message)
 
142
        if not create_oops:
 
143
            with disable_oops_handler(self.logger):
 
144
                self.logger.error(msg)
 
145
        else:
 
146
            self.logger.error(msg)
142
147
 
143
148
    def _logWarning(self, message, warning_id=None):
144
149
        """Log `message` for a warning in submission submission_key`."""
181
186
        if not validator.validate(submission):
182
187
            self._logError(
183
188
                'Relax NG validation failed.\n%s' % validator.error_log,
184
 
                submission_key)
 
189
                submission_key,
 
190
                create_oops=False)
185
191
            return None
186
192
        return submission_doc
187
193