get device path from calibre, and allow device usage on all platforms

This commit is contained in:
Norbert Preining 2015-09-16 23:01:29 +09:00
parent f97bc078db
commit 93d8758462
3 changed files with 51 additions and 19 deletions

View File

@ -78,8 +78,26 @@ class InterfacePluginAction(InterfaceAction):
self.current_idx = self.gui.library_view.currentIndex()
print ('Running {}'.format(PLUGIN_NAME + ' v' + PLUGIN_VERSION))
#
# search for connected device in case serials are saved
device = self.parent().device_manager.connected_device
device_path = None
if (device):
device_path = self.parent().device_manager.connected_device._main_prefix
debug_print("get_device_settings - device_path=", device_path)
else:
debug_print("didn't find device")
# Get the Kobo Library object (obok v3.01)
self.library = KoboLibrary(cfg['kobo_serials'])
self.library = KoboLibrary(cfg['kobo_serials'], device_path)
debug_print ("got kobodir %s" % self.library.kobodir)
if (self.library.kobodir == ''):
# linux and no device connected, but could be extended
# to the case where on Windows/Mac the prog is not installed
msg = _('<p>Could not find Kobo Library\n<p>Windows/Mac: do you have Kobo Desktop installed?\n<p>Windows/Mac/Linux: In case you have an Kobo eInk device, configure the serial number and connect the device.')
showErrorDlg(msg, None)
return
# Get a list of Kobo titles
books = self.build_book_list()

View File

@ -19,7 +19,7 @@ plugin_prefs = JSONConfig('plugins/obok_dedrm_prefs')
plugin_prefs.defaults['finding_homes_for_formats'] = 'Ask'
plugin_prefs.defaults['kobo_serials'] = []
from calibre_plugins.dedrm.__init__ import PLUGIN_NAME, PLUGIN_VERSION
from calibre_plugins.obok_dedrm.__init__ import PLUGIN_NAME, PLUGIN_VERSION
from calibre_plugins.obok_dedrm.utilities import (debug_print)
try:
debug_print("obok::config.py - loading translations")

View File

@ -244,8 +244,10 @@ class KoboLibrary(object):
written by the Kobo Desktop Edition application, including the list
of books, their titles, and the user's encryption key(s)."""
def __init__ (self, serials = []):
def __init__ (self, serials = [], device_path = None):
print u"Obok v{0}\nCopyright © 2012-2015 Physisticated et al.".format(__version__)
self.kobodir = ''
kobodb = ''
if sys.platform.startswith('win'):
if sys.getwindowsversion().major > 5:
self.kobodir = os.environ['LOCALAPPDATA']
@ -254,20 +256,30 @@ class KoboLibrary(object):
self.kobodir = os.path.join(self.kobodir, 'Kobo', 'Kobo Desktop Edition')
elif sys.platform.startswith('darwin'):
self.kobodir = os.path.join(os.environ['HOME'], 'Library', 'Application Support', 'Kobo', 'Kobo Desktop Edition')
elif sys.platform.startswith('linux'):
# TODO TODO TODO needs change - fixed path to mount point
self.kobodir = '/media/norbert/KOBOeReader/.kobo'
self.bookdir = os.path.join(self.kobodir, 'kepub')
if sys.platform.startswith('linux'):
kobodb = os.path.join(self.kobodir, 'KoboReader.sqlite')
else:
kobodb = os.path.join(self.kobodir, 'Kobo.sqlite')
self.__sqlite = sqlite3.connect(kobodb)
self.__cursor = self.__sqlite.cursor()
self._userkeys = []
self._books = []
self._volumeID = []
self._serials = serials
# desktop versions use Kobo.sqlite
kobodb = os.path.join(self.kobodir, 'Kobo.sqlite')
if (self.kobodir == '' or not(os.path.exists(kobodb))):
# kobodb is either not set or not an existing file, that means that either:
# . windows or mac: desktop app is not installed
# . linux
# we check for a connected device and try to set up kobodir and kobodb from there
if (device_path):
self.kobodir = os.path.join(device_path, '.kobo')
# devices use KoboReader.sqlite
kobodb = os.path.join(self.kobodir, 'KoboReader.sqlite')
if (not(os.path.exists(kobodb))):
# give up here, we haven't found anything useful
self.kobodir = ''
kobodb = ''
if (self.kobodir != ''):
self.bookdir = os.path.join(self.kobodir, 'kepub')
self.__sqlite = sqlite3.connect(kobodb)
self.__cursor = self.__sqlite.cursor()
self._userkeys = []
self._books = []
self._volumeID = []
self._serials = serials
def close (self):
"""Closes the database used by the library."""
@ -326,8 +338,10 @@ class KoboLibrary(object):
for m in matches:
# print "m:",m[0]
macaddrs.append(m[0].upper())
elif sys.platform.startswith('linux'):
macaddrs.extend(self._serials)
# extend the list of macaddrs in any case with the serials
# cannot hurt ;-)
macaddrs.extend(self._serials)
return macaddrs