]> git.phdru.name Git - m_librarian.git/blobdiff - m_librarian/db.py
Multidatabase - every script can open a database by pathname or DB URI
[m_librarian.git] / m_librarian / db.py
index b3ddd5211961196f282c411cfffe79acf9edada7..0da18a4676ab8679bcc99664705a252ea50c043b 100755 (executable)
@@ -142,11 +142,21 @@ def open_db(db_uri=None):
         except:
             db_uri = find_sqlite_dburi()
 
+    if db_uri.startswith(os.sep) or os.altsep and db_uri.startswith(os.altsep) \
+            or db_uri.startswith(os.pardir + os.sep) \
+            or os.altsep and db_uri.startswith(os.pardir + os.altsep):
+        if db_uri.startswith(os.pardir + os.sep) \
+        or os.altsep and db_uri.startswith(os.pardir + os.altsep):
+            db_uri = os.path.abspath(db_uri)
+        db_uri = 'sqlite://' + db_uri.replace(os.sep, '/')
+
     sqlhub.processConnection = connection = connectionForURI(db_uri)
 
     if connection.dbName == 'sqlite':
         def lower(s):
-            return s.lower()
+            if isinstance(s, basestring):
+                return s.lower()
+            return s
 
         sqlite = connection.module