X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Fdb.py;h=9a48caa8fdade56f6ca38f86f393ad410ef98b5d;hb=1b4e677c375c8d518574c84406428f1ccbcc6022;hp=7e5744f243e64eabebe14afadd66f768a08e2430;hpb=07794a8efe6512dd65b98c692d35a1a41ed5683e;p=m_librarian.git diff --git a/m_librarian/db.py b/m_librarian/db.py index 7e5744f..9a48caa 100755 --- a/m_librarian/db.py +++ b/m_librarian/db.py @@ -1,16 +1,16 @@ #! /usr/bin/env python -__all__ = ['Author', 'Book', 'Extension', 'Genre', 'Language', - 'AuthorBook', 'BookGenre', 'open_db', 'init_db', - 'insert_name', 'insert_author', 'update_counters', - ] - import os from sqlobject import SQLObject, StringCol, UnicodeCol, IntCol, BoolCol, \ ForeignKey, DateCol, DatabaseIndex, RelatedJoin, \ connectionForURI, sqlhub, SQLObjectNotFound, dberrors from .config import get_config +__all__ = ['Author', 'Book', 'Extension', 'Genre', 'Language', + 'AuthorBook', 'BookGenre', 'open_db', 'init_db', + 'insert_name', 'insert_author', 'update_counters', + ] + class Author(SQLObject): surname = UnicodeCol(notNull=True) @@ -142,11 +142,21 @@ 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': def lower(s): - return s.lower() + if isinstance(s, basestring): + return s.lower() + return s sqlite = connection.module