]> xmof Git - DeDRM.git/commitdiff
get device path from calibre, and allow device usage on all platforms
authorNorbert Preining <norbert@preining.info>
Wed, 16 Sep 2015 14:01:29 +0000 (23:01 +0900)
committerNorbert Preining <norbert@preining.info>
Wed, 16 Sep 2015 14:01:29 +0000 (23:01 +0900)
Obok_calibre_plugin/obok_plugin/action.py
Obok_calibre_plugin/obok_plugin/config.py
Obok_calibre_plugin/obok_plugin/obok/obok.py

index e951e8afbf1ea61226ed60f7ddd4e0f734ce3d54..e82e29b36551efaf5a099a490ff598380647961a 100644 (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()
index 8f8fa3d13801c45b086b6a3a70b2186b406dad84..ae4edc01da27d54e832ecf3793289a594cdac9fd 100644 (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")
index 577312e855bc125323b96e55e69bca420fe1bc70..f8451856d998fc41f6026993fb4e72d11f669330 100644 (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