log_search.py
changeset 99 8719ac564b22
parent 96 d30c88e89a7e
child 118 f530c158aa07
--- a/log_search.py	Wed Feb 11 03:32:21 2009 +0200
+++ b/log_search.py	Wed Feb 11 03:46:59 2009 +0200
@@ -46,11 +46,16 @@
     def __init__ (self, channels, path, mode='r') :
         """
             Open the database at the given path, with the given mode:
-                r       - read, error if not exists
-                w       - write, create if not exists
-                a       - write, error if not exists
-                c       - write, create, error if exists
-                *       - write, create, truncate if exists
+                First char:
+                    r       - read, error if not exists
+                    w       - write, create if not exists
+                    a       - write, error if not exists
+                    c       - create, error if exists
+                
+                Additional chars:
+                    trunc   - truncate if exists
+                    +       - read as well as write
+                    ?       - non-blocking lock open, i.e. it fails if already open
             
             Channels is the ChannelList.
         """
@@ -69,13 +74,25 @@
             'r':    hype.Database.DBREADER,
             'w':    hype.Database.DBWRITER | hype.Database.DBCREAT,
             'a':    hype.Database.DBWRITER,
-            'c':    hype.Database.DBWRITER | hype.Database.DBCREAT,
-            '*':    hype.Database.DBWRITER | hype.Database.DBCREAT | hype.Database.DBTRUNC,
+            'c':    hype.Database.DBCREAT,
         }
 
-        # look up flags
-        flags = mode_to_flag[mode]
+        # flags to use, standard modes
+        flags = mode_to_flag[mode[0]]
+ 
+        # mode-flags
+        if '?' in mode :
+            # non-blocking locking
+            flags |= hype.Database.DBLCKNB
         
+        elif '+' in mode :
+            # read
+            flags |= hype.Database.DBREADER
+
+        elif 'trunc' in mode :
+            # truncate. Dangerous!
+            flags |= hype.Database.DBTRUNC
+       
         # make instance
         self.db = hype.Database()