From: David G. <go...@us...> - 2003-06-30 15:26:18
|
Update of /cvsroot/docutils/docutils/docutils In directory sc8-pr-cvs1:/tmp/cvs-serv14536/docutils Modified Files: io.py Log Message: Catch IOErrors when opening source & destination files, report & exit without tracebacks. Index: io.py =================================================================== RCS file: /cvsroot/docutils/docutils/docutils/io.py,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- io.py 17 Jun 2003 13:26:52 -0000 1.26 +++ io.py 30 Jun 2003 15:26:15 -0000 1.27 @@ -147,7 +147,15 @@ self.autoclose = autoclose if source is None: if source_path: - self.source = open(source_path) + try: + self.source = open(source_path) + except IOError, error: + print >>sys.stderr, '%s: %s' % (error.__class__.__name__, + error) + print >>sys.stderr, ( + 'Unable to open source file for reading (%s). Exiting.' + % source_path) + sys.exit(1) else: self.source = sys.stdin self.autoclose = None @@ -203,7 +211,14 @@ pass def open(self): - self.destination = open(self.destination_path, 'w') + try: + self.destination = open(self.destination_path, 'w') + except IOError, error: + print >>sys.stderr, '%s: %s' % (error.__class__.__name__, + error) + print >>sys.stderr, ('Unable to open destination file for writing ' + '(%s). Exiting.' % source_path) + sys.exit(1) self.opened = 1 def write(self, data): |