[Liblas-commits] hg: Added handling for non-existent files in the python bindings

liblas-commits at liblas.org liblas-commits at liblas.org
Thu May 12 16:46:49 EDT 2011


details:   http://hg.liblas.orghg/rev/b25d47aca584
changeset: 2939:b25d47aca584
user:      Pete Gadomski <pete.gadomski at gmail.com>
date:      Thu May 12 13:46:32 2011 -0700
description:
Added handling for non-existent files in the python bindings

diffstat:

 python/liblas/file.py |  3 +++
 python/tests/File.txt |  5 +++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diffs (26 lines):

diff -r 5ed84f7d6e69 -r b25d47aca584 python/liblas/file.py
--- a/python/liblas/file.py	Wed May 11 11:45:20 2011 -0700
+++ b/python/liblas/file.py	Thu May 12 13:46:32 2011 -0700
@@ -130,6 +130,9 @@
         """Open the file for processing, called by __init__
         """
         
+        if not os.path.exists(self.filename):
+            raise OSError("No such file or directory: '%s'" % self.filename)
+        
         if self._mode == 'r' or self._mode == 'rb':
 
             if self._header == None:
diff -r 5ed84f7d6e69 -r b25d47aca584 python/tests/File.txt
--- a/python/tests/File.txt	Wed May 11 11:45:20 2011 -0700
+++ b/python/tests/File.txt	Thu May 12 13:46:32 2011 -0700
@@ -1,4 +1,9 @@
   >>> from liblas import file
+  >>> file.File('notafile.las')
+  Traceback (most recent call last):
+  ...
+  OSError: File junk.las can not be found
+  
   >>> f = file.File('../test/data/TO_core_last_clip.las')
   
   >>> f.header # doctest: +ELLIPSIS


More information about the Liblas-commits mailing list