[Liblas-commits] hg: support accounting for more than one instance of a file open...

liblas-commits at liblas.org liblas-commits at liblas.org
Tue May 11 16:22:52 EDT 2010


changeset 3d6a2a893b5c in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=3d6a2a893b5c
summary: support accounting for more than one instance of a file open for read

diffstat:

 python/liblas/file.py |  15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diffs (46 lines):

diff -r e267e798a8e5 -r 3d6a2a893b5c python/liblas/file.py
--- a/python/liblas/file.py	Tue May 11 14:21:01 2010 -0500
+++ b/python/liblas/file.py	Tue May 11 15:22:43 2010 -0500
@@ -48,7 +48,7 @@
 import os
 import types
 
-files = {'append': [], 'write': [], 'read': []}
+files = {'append': [], 'write': [], 'read': {}}
 import sys
 
 
@@ -110,7 +110,7 @@
         else:
             # we're in some kind of write mode, and if we already have the
             # file open, complain to the user.
-            for f in files['read'] + files['append'] + files['write']:
+            for f in files['read'].keys() + files['append'] + files['write']:
                 if f == self.filename:
                     raise core.LASException("File %s is already open. "
                                             "Close the file or delete the "
@@ -131,7 +131,10 @@
                                                         self._header.handle)
 
             self.mode = 0
-            files['read'].append(self.filename)
+            try:
+                files['read'][self.filename] += 1
+            except KeyError:
+                files['read'][self.filename] = 1
 
             if self.in_srs:
                 core.las.las.LASReader_SetInputSRS(self.handle,
@@ -183,6 +186,12 @@
         """
         if self.mode == 0:
             core.las.LASReader_Destroy(self.handle)
+            try:
+                files['read'][self.filename] -= 1
+                if files['read'][self.filename] == 0:
+                    files['read'].pop(self.filename)
+            except KeyError:
+                raise core.LASException("File %s was not found in accounting dictionary!" % self.filename)
             files['read'].remove(self.filename)
         else:
             try:


More information about the Liblas-commits mailing list