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() self.current_idx = self.gui.library_view.currentIndex()
print ('Running {}'.format(PLUGIN_NAME + ' v' + PLUGIN_VERSION)) 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) # 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 # Get a list of Kobo titles
books = self.build_book_list() 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['finding_homes_for_formats'] = 'Ask'
plugin_prefs.defaults['kobo_serials'] = [] 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) from calibre_plugins.obok_dedrm.utilities import (debug_print)
try: try:
debug_print("obok::config.py - loading translations") 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 written by the Kobo Desktop Edition application, including the list
of books, their titles, and the user's encryption key(s).""" 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__) print u"Obok v{0}\nCopyright © 2012-2015 Physisticated et al.".format(__version__)
self.kobodir = ''
kobodb = ''
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
if sys.getwindowsversion().major > 5: if sys.getwindowsversion().major > 5:
self.kobodir = os.environ['LOCALAPPDATA'] self.kobodir = os.environ['LOCALAPPDATA']
@ -254,20 +256,30 @@ class KoboLibrary(object):
self.kobodir = os.path.join(self.kobodir, 'Kobo', 'Kobo Desktop Edition') self.kobodir = os.path.join(self.kobodir, 'Kobo', 'Kobo Desktop Edition')
elif sys.platform.startswith('darwin'): elif sys.platform.startswith('darwin'):
self.kobodir = os.path.join(os.environ['HOME'], 'Library', 'Application Support', 'Kobo', 'Kobo Desktop Edition') self.kobodir = os.path.join(os.environ['HOME'], 'Library', 'Application Support', 'Kobo', 'Kobo Desktop Edition')
elif sys.platform.startswith('linux'): # desktop versions use Kobo.sqlite
# TODO TODO TODO needs change - fixed path to mount point kobodb = os.path.join(self.kobodir, 'Kobo.sqlite')
self.kobodir = '/media/norbert/KOBOeReader/.kobo' if (self.kobodir == '' or not(os.path.exists(kobodb))):
self.bookdir = os.path.join(self.kobodir, 'kepub') # kobodb is either not set or not an existing file, that means that either:
if sys.platform.startswith('linux'): # . windows or mac: desktop app is not installed
kobodb = os.path.join(self.kobodir, 'KoboReader.sqlite') # . linux
else: # we check for a connected device and try to set up kobodir and kobodb from there
kobodb = os.path.join(self.kobodir, 'Kobo.sqlite') if (device_path):
self.__sqlite = sqlite3.connect(kobodb) self.kobodir = os.path.join(device_path, '.kobo')
self.__cursor = self.__sqlite.cursor() # devices use KoboReader.sqlite
self._userkeys = [] kobodb = os.path.join(self.kobodir, 'KoboReader.sqlite')
self._books = [] if (not(os.path.exists(kobodb))):
self._volumeID = [] # give up here, we haven't found anything useful
self._serials = serials 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): def close (self):
"""Closes the database used by the library.""" """Closes the database used by the library."""
@ -326,8 +338,10 @@ class KoboLibrary(object):
for m in matches: for m in matches:
# print "m:",m[0] # print "m:",m[0]
macaddrs.append(m[0].upper()) 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 return macaddrs