Convert the stderr spam into a gtk.MessageDialog. Format and localise the error.

Handle unterminated quoted string errors better
This commit is contained in:
Thomas Hurst 2008-08-26 17:04:53 +01:00
parent a89f18e095
commit 9baf905cab
2 changed files with 19 additions and 4 deletions

View File

@ -210,7 +210,21 @@ class TerminatorConfValuestoreRC (TerminatorConfValuestore):
try:
ini.parse()
except ParsedWithErrors, e:
sys.stderr.write(str(e))
import gtk
from cgi import escape
msg = _("""Errors were encountered while parsing terminator_config(5) file:
<b>%s</b>
Some lines have been ignored.""") % escape(repr(self.rcfilename))
errs = "\n\n".join(map(lambda error:
_(" * %(message)s, line %(lnum)d:\n <tt>%(line)s</tt>\n <tt>%(pad)s^</tt>") % {
'message': error.message, 'file': escape(error.file), 'lnum': error.lnum,
'line': escape(error.line.rstrip()), 'pad': '-' * error.pos}, e.errors))
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK)
dialog.set_markup(msg + "\n\n" + errs)
dialog.run()
dialog.destroy()
for key in ini.settings:
try:

View File

@ -89,7 +89,8 @@ class ConfigFile:
while True:
mo = QuotedStrings[chr].match(self._line, self._pos)
if mo is None:
raise ConfigSyntaxError("Unterminated quoted string", self)
self.parse_error(_("Unterminated quoted string"))
return False
self._pos = mo.end()
if self._line[self._pos - 2] == '\\':
string += mo.group(1)[0:-1] + chr
@ -142,13 +143,13 @@ class ConfigFile:
if not self._call_if_match(Colourvalue, self._value, 1):
# bare value
if not self._call_if_match(Barevalue, self._value, 1):
self.parse_error("Setting without a value")
self.parse_error(_("Setting without a value"))
continue
self._call_if_match(Ignore, lambda junk: dbg("Ignoring: %s" % junk))
if self._line[self._pos:] != '':
self.parse_error("Unexpected token")
self.parse_error(_("Unexpected token"))
if self.errors:
raise ParsedWithErrors(self.filename, self.errors)