import os
import simplejson
+import codecs
import logging
os.makedirs(self.path)
try:
- with open(self.books_path, "r") as settingsFile:
+ with codecs.open(self.books_path, "r", "utf-8") as settingsFile:
settings = simplejson.load(settingsFile)
except IOError, e:
_moduleLogger.info("No settings")
"selected": self.selected,
"books": self._books,
}
- with open(self.books_path, "w") as settingsFile:
+ with codecs.open(self.books_path, "w", "utf-8") as settingsFile:
simplejson.dump(settings, settingsFile)
def get_selected(self):
def select_book(self, bookName):
""" Sets the book as the currently playing, and adds it to the
database if it is not already there"""
- book_file = os.path.join(self.books_path, bookName)
if bookName not in self._books:
self._books[bookName] = {
"chapter": 0,
for book in os.listdir(books_path):
book_file = os.path.join(books_path, book)
with open(book_file, 'r') as f:
- chapter = int(f.readline())
- position = int(f.readline())
+ try:
+ chapter = int(f.readline())
+ position = int(f.readline())
+ except ValueError:
+ _moduleLogger.exception("Trouble loading old settings from %s" % book_file)
+ chapter = 0
+ position = 0
self._books[book] = {
"chapter": chapter,
"position": position,