]> git.phdru.name Git - m_librarian.git/commitdiff
Open file as an SQLite DB
authorOleg Broytman <phd@phdru.name>
Mon, 30 May 2016 21:32:11 +0000 (00:32 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 30 May 2016 21:32:11 +0000 (00:32 +0300)
Convert a relative path to an absolute, and an absolute to
an SQLite DB URI.

m_librarian/db.py

index f65569cb6e37183922b4dc6ae4e88a51e5bfec00..9a48caa8fdade56f6ca38f86f393ad410ef98b5d 100755 (executable)
@@ -142,6 +142,14 @@ def open_db(db_uri=None):
         except:
             db_uri = find_sqlite_dburi()
 
+    if db_uri.startswith(os.sep) or db_uri.startswith(os.altsep) \
+            or db_uri.startswith(os.pardir + os.sep) \
+            or db_uri.startswith(os.pardir + os.altsep):
+        if db_uri.startswith(os.pardir + os.sep) \
+        or 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':