4 from sqlobject import SQLObject, StringCol, UnicodeCol, IntCol, BoolCol, \
5 ForeignKey, DateCol, connectionForURI, sqlhub
6 from .config import ml_conf
9 db_uri = ml_conf.get('database', 'URI')
15 if 'XDG_CACHE_HOME' in os.environ:
16 db_dirs.append(os.environ['XDG_CACHE_HOME'])
17 home_cache = os.path.expanduser('~/.cache')
18 if home_cache not in db_dirs:
19 db_dirs.append(home_cache)
22 db_file = os.path.join(d, 'm_librarian.sqlite')
23 if os.path.exists(db_file):
27 # make the database file/directory readable/writeable only by the user
32 except OSError: # Perhaps already exists
34 db_file = os.path.join(db_dir, 'm_librarian.sqlite')
35 db_uri = 'sqlite://%s' % db_file.replace(os.sep, '/')
37 sqlhub.processConnection = connectionForURI(db_uri)
40 class Author(SQLObject):
45 class Genre(SQLObject):
51 class Book(SQLObject):
52 author = ForeignKey('Author')
53 genre = ForeignKey('Genre')
61 ext = ForeignKey('Extension')
63 language = ForeignKey('Language')
66 class Extension(SQLObject):
71 class Language(SQLObject):
76 if __name__ == '__main__':
77 print "DB dirs:", db_dirs
79 print "DB URI:", db_uri