mirror of
https://github.com/apprenticeharper/DeDRM_tools
synced 2024-12-26 09:58:55 +01:00
Merge pull request #859 from HansChua/linux_handling
Allow users to specify Kobo directory and add 'ip' command for linux
This commit is contained in:
commit
ef3c7f261c
3 changed files with 50 additions and 21 deletions
|
@ -93,7 +93,7 @@ class InterfacePluginAction(InterfaceAction):
|
||||||
debug_print("Exception getting device path. Probably not an E-Ink Kobo device")
|
debug_print("Exception getting device path. Probably not an E-Ink Kobo device")
|
||||||
|
|
||||||
# Get the Kobo Library object (obok v3.01)
|
# Get the Kobo Library object (obok v3.01)
|
||||||
self.library = KoboLibrary(tmpserials, device_path)
|
self.library = KoboLibrary(tmpserials, device_path, cfg['kobo_directory'])
|
||||||
debug_print ("got kobodir %s" % self.library.kobodir)
|
debug_print ("got kobodir %s" % self.library.kobodir)
|
||||||
if (self.library.kobodir == ''):
|
if (self.library.kobodir == ''):
|
||||||
# linux and no device connected, but could be extended
|
# linux and no device connected, but could be extended
|
||||||
|
|
|
@ -3,9 +3,9 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||||
print_function)
|
print_function)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PyQt5.Qt import (Qt, QGroupBox, QListWidget, QLineEdit, QDialogButtonBox, QWidget, QLabel, QDialog, QVBoxLayout, QAbstractItemView, QIcon, QHBoxLayout, QComboBox, QListWidgetItem)
|
from PyQt5.Qt import (Qt, QGroupBox, QListWidget, QLineEdit, QDialogButtonBox, QWidget, QLabel, QDialog, QVBoxLayout, QAbstractItemView, QIcon, QHBoxLayout, QComboBox, QListWidgetItem, QFileDialog)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from PyQt4.Qt import (Qt, QGroupBox, QListWidget, QLineEdit, QDialogButtonBox, QWidget, QLabel, QDialog, QVBoxLayout, QAbstractItemView, QIcon, QHBoxLayout, QComboBox, QListWidgetItem)
|
from PyQt4.Qt import (Qt, QGroupBox, QListWidget, QLineEdit, QDialogButtonBox, QWidget, QLabel, QDialog, QVBoxLayout, QAbstractItemView, QIcon, QHBoxLayout, QComboBox, QListWidgetItem, QFileDialog)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PyQt5 import Qt as QtGui
|
from PyQt5 import Qt as QtGui
|
||||||
|
@ -18,6 +18,7 @@ from calibre.utils.config import JSONConfig, config_dir
|
||||||
plugin_prefs = JSONConfig('plugins/obok_dedrm_prefs')
|
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'] = []
|
||||||
|
plugin_prefs.defaults['kobo_directory'] = u''
|
||||||
|
|
||||||
from calibre_plugins.obok_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)
|
||||||
|
@ -37,6 +38,7 @@ class ConfigWidget(QWidget):
|
||||||
|
|
||||||
# copy of preferences
|
# copy of preferences
|
||||||
self.tmpserials = plugin_prefs['kobo_serials']
|
self.tmpserials = plugin_prefs['kobo_serials']
|
||||||
|
self.kobodirectory = plugin_prefs['kobo_directory']
|
||||||
|
|
||||||
combo_label = QLabel(_('When should Obok try to insert EPUBs into existing calibre entries?'), self)
|
combo_label = QLabel(_('When should Obok try to insert EPUBs into existing calibre entries?'), self)
|
||||||
layout.addWidget(combo_label)
|
layout.addWidget(combo_label)
|
||||||
|
@ -53,15 +55,30 @@ class ConfigWidget(QWidget):
|
||||||
self.serials_button.clicked.connect(self.edit_serials)
|
self.serials_button.clicked.connect(self.edit_serials)
|
||||||
layout.addWidget(self.serials_button)
|
layout.addWidget(self.serials_button)
|
||||||
|
|
||||||
|
self.kobo_directory_button = QtGui.QPushButton(self)
|
||||||
|
self.kobo_directory_button.setToolTip(_(u"Click to specify the Kobo directory"))
|
||||||
|
self.kobo_directory_button.setText(u"Kobo directory")
|
||||||
|
self.kobo_directory_button.clicked.connect(self.edit_kobo_directory)
|
||||||
|
layout.addWidget(self.kobo_directory_button)
|
||||||
|
|
||||||
|
|
||||||
def edit_serials(self):
|
def edit_serials(self):
|
||||||
d = ManageKeysDialog(self,u"Kobo device serial numbers",self.tmpserials, AddSerialDialog)
|
d = ManageKeysDialog(self,u"Kobo device serial number",self.tmpserials, AddSerialDialog)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
|
||||||
|
def edit_kobo_directory(self):
|
||||||
|
tmpkobodirectory = QFileDialog.getExistingDirectory(self, u"Select Kobo directory", self.kobodirectory or "/home", QFileDialog.ShowDirsOnly)
|
||||||
|
|
||||||
|
if tmpkobodirectory != u"" and tmpkobodirectory is not None:
|
||||||
|
self.kobodirectory = tmpkobodirectory
|
||||||
|
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
plugin_prefs['finding_homes_for_formats'] = unicode(self.find_homes.currentText())
|
plugin_prefs['finding_homes_for_formats'] = unicode(self.find_homes.currentText())
|
||||||
plugin_prefs['kobo_serials'] = self.tmpserials
|
plugin_prefs['kobo_serials'] = self.tmpserials
|
||||||
|
plugin_prefs['kobo_directory'] = self.kobodirectory
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,7 @@ 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 = [], device_path = None):
|
def __init__ (self, serials = [], device_path = None, desktopkobodir = u""):
|
||||||
print(__about__)
|
print(__about__)
|
||||||
self.kobodir = u""
|
self.kobodir = u""
|
||||||
kobodb = u""
|
kobodb = u""
|
||||||
|
@ -345,19 +345,23 @@ class KoboLibrary(object):
|
||||||
|
|
||||||
if (self.kobodir == u""):
|
if (self.kobodir == u""):
|
||||||
# step 4. we haven't found a device with serials, so try desktop apps
|
# step 4. we haven't found a device with serials, so try desktop apps
|
||||||
if sys.platform.startswith('win'):
|
if desktopkobodir != u'':
|
||||||
import _winreg as winreg
|
self.kobodir = desktopkobodir
|
||||||
if sys.getwindowsversion().major > 5:
|
|
||||||
if 'LOCALAPPDATA' in os.environ.keys():
|
if (self.kobodir == u""):
|
||||||
# Python 2.x does not return unicode env. Use Python 3.x
|
if sys.platform.startswith('win'):
|
||||||
self.kobodir = winreg.ExpandEnvironmentStrings(u"%LOCALAPPDATA%")
|
import _winreg as winreg
|
||||||
if (self.kobodir == u""):
|
if sys.getwindowsversion().major > 5:
|
||||||
if 'USERPROFILE' in os.environ.keys():
|
if 'LOCALAPPDATA' in os.environ.keys():
|
||||||
# Python 2.x does not return unicode env. Use Python 3.x
|
# Python 2.x does not return unicode env. Use Python 3.x
|
||||||
self.kobodir = os.path.join(winreg.ExpandEnvironmentStrings(u"%USERPROFILE%"), u"Local Settings", u"Application Data")
|
self.kobodir = winreg.ExpandEnvironmentStrings(u"%LOCALAPPDATA%")
|
||||||
self.kobodir = os.path.join(self.kobodir, u"Kobo", u"Kobo Desktop Edition")
|
if (self.kobodir == u""):
|
||||||
elif sys.platform.startswith('darwin'):
|
if 'USERPROFILE' in os.environ.keys():
|
||||||
self.kobodir = os.path.join(os.environ['HOME'], u"Library", u"Application Support", u"Kobo", u"Kobo Desktop Edition")
|
# Python 2.x does not return unicode env. Use Python 3.x
|
||||||
|
self.kobodir = os.path.join(winreg.ExpandEnvironmentStrings(u"%USERPROFILE%"), u"Local Settings", u"Application Data")
|
||||||
|
self.kobodir = os.path.join(self.kobodir, u"Kobo", u"Kobo Desktop Edition")
|
||||||
|
elif sys.platform.startswith('darwin'):
|
||||||
|
self.kobodir = os.path.join(os.environ['HOME'], u"Library", u"Application Support", u"Kobo", u"Kobo Desktop Edition")
|
||||||
#elif linux_path != None:
|
#elif linux_path != None:
|
||||||
# Probably Linux, let's get the wine prefix and path to Kobo.
|
# Probably Linux, let's get the wine prefix and path to Kobo.
|
||||||
# self.kobodir = os.path.join(linux_path, u"Local Settings", u"Application Data", u"Kobo", u"Kobo Desktop Edition")
|
# self.kobodir = os.path.join(linux_path, u"Local Settings", u"Application Data", u"Kobo", u"Kobo Desktop Edition")
|
||||||
|
@ -369,7 +373,6 @@ class KoboLibrary(object):
|
||||||
self.kobodir = u""
|
self.kobodir = u""
|
||||||
kobodb = u""
|
kobodb = u""
|
||||||
|
|
||||||
|
|
||||||
if (self.kobodir != u""):
|
if (self.kobodir != u""):
|
||||||
self.bookdir = os.path.join(self.kobodir, u"kepub")
|
self.bookdir = os.path.join(self.kobodir, u"kepub")
|
||||||
# make a copy of the database in a temporary file
|
# make a copy of the database in a temporary file
|
||||||
|
@ -451,7 +454,16 @@ class KoboLibrary(object):
|
||||||
# print u"m:{0}".format(m[0])
|
# print u"m:{0}".format(m[0])
|
||||||
macaddrs.append(m[0].upper())
|
macaddrs.append(m[0].upper())
|
||||||
else:
|
else:
|
||||||
# probably linux, let's try ipconfig under wine
|
# probably linux
|
||||||
|
|
||||||
|
# let's try ip
|
||||||
|
c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
||||||
|
for line in os.popen('ip -br link'):
|
||||||
|
m = c.search(line)
|
||||||
|
if m:
|
||||||
|
macaddrs.append(m.group(1).upper())
|
||||||
|
|
||||||
|
# let's try ipconfig under wine
|
||||||
c = re.compile('\s(' + '[0-9a-f]{2}-' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
c = re.compile('\s(' + '[0-9a-f]{2}-' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
||||||
for line in os.popen('ipconfig /all'):
|
for line in os.popen('ipconfig /all'):
|
||||||
m = c.search(line)
|
m = c.search(line)
|
||||||
|
|
Loading…
Reference in a new issue