mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix regressions in PRS500 handling.
This commit is contained in:
parent
d39c1a2130
commit
0ed6ddf783
@ -78,7 +78,7 @@ class Device(object):
|
||||
|
||||
def card_prefix(self, end_session=True):
|
||||
'''
|
||||
Return prefix to paths on the card or None if no cards present.
|
||||
Return prefix to paths on the card or '' if no cards present.
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -218,7 +218,7 @@ class PRS500(Device):
|
||||
self.handle = None
|
||||
|
||||
@classmethod
|
||||
def is_connected(cls):
|
||||
def is_connected(cls, helper=None):
|
||||
"""
|
||||
This method checks to see whether the device is physically connected.
|
||||
It does not return any information about the validity of the
|
||||
@ -463,7 +463,8 @@ class PRS500(Device):
|
||||
"""
|
||||
if path.endswith("/"):
|
||||
path = path[:-1] # We only copy files
|
||||
path = path.replace('card:/', self.card_prefix(False))
|
||||
cp = self.card_prefix(False)
|
||||
path = path.replace('card:/', cp if cp else '')
|
||||
_file = self.path_properties(path, end_session=False)
|
||||
if _file.is_dir:
|
||||
raise PathError("Cannot read as " + path + " is a directory")
|
||||
@ -525,7 +526,8 @@ class PRS500(Device):
|
||||
""" Do a non recursive listsing of path """
|
||||
if not path.endswith("/"):
|
||||
path += "/" # Initially assume path is a directory
|
||||
path = path.replace('card:/', self.card_prefix(False))
|
||||
cp = self.card_prefix(False)
|
||||
path = path.replace('card:/', cp if cp else '')
|
||||
files = []
|
||||
candidate = self.path_properties(path, end_session=False)
|
||||
if not candidate.is_dir:
|
||||
@ -597,7 +599,6 @@ class PRS500(Device):
|
||||
|
||||
@safe
|
||||
def card_prefix(self, end_session=True):
|
||||
'''Return prefix of path to card or None if no cards present'''
|
||||
try:
|
||||
path = 'a:/'
|
||||
self.path_properties(path, end_session=False)
|
||||
@ -649,7 +650,8 @@ class PRS500(Device):
|
||||
@todo: Update file modification time if it exists.
|
||||
Opening the file in write mode and then closing it doesn't work.
|
||||
"""
|
||||
path = path.replace('card:/', self.card_prefix(False))
|
||||
cp = self.card_prefix(False)
|
||||
path = path.replace('card:/', cp if cp else '')
|
||||
if path.endswith("/") and len(path) > 1:
|
||||
path = path[:-1]
|
||||
exists, _file = self._exists(path)
|
||||
@ -676,7 +678,8 @@ class PRS500(Device):
|
||||
bytes = infile.tell() - pos
|
||||
start_pos = pos
|
||||
infile.seek(pos)
|
||||
path = path.replace('card:/', self.card_prefix(False))
|
||||
cp = self.card_prefix(False)
|
||||
path = path.replace('card:/', cp if cp else '')
|
||||
exists, dest = self._exists(path)
|
||||
if exists:
|
||||
if dest.is_dir:
|
||||
@ -746,7 +749,8 @@ class PRS500(Device):
|
||||
def mkdir(self, path, end_session=True):
|
||||
""" Make directory """
|
||||
if path.startswith('card:/'):
|
||||
path = path.replace('card:/', self.card_prefix(False))
|
||||
cp = self.card_prefix(False)
|
||||
path = path.replace('card:/', cp if cp else '')
|
||||
if not path.endswith("/"):
|
||||
path += "/"
|
||||
error_prefix = "Cannot create directory " + path
|
||||
@ -764,7 +768,8 @@ class PRS500(Device):
|
||||
@safe
|
||||
def rm(self, path, end_session=True):
|
||||
""" Delete path from device if it is a file or an empty directory """
|
||||
path = path.replace('card:/', self.card_prefix(False))
|
||||
cp = self.card_prefix(False)
|
||||
path = path.replace('card:/', cp if cp else '')
|
||||
dir = self.path_properties(path, end_session=False)
|
||||
if not dir.is_dir:
|
||||
self.del_file(path, end_session=False)
|
||||
|
@ -335,7 +335,6 @@ class PRS505(Device):
|
||||
|
||||
def delete_books(self, paths, end_session=True):
|
||||
for path in paths:
|
||||
print path
|
||||
os.unlink(path)
|
||||
|
||||
@classmethod
|
||||
|
@ -12,17 +12,12 @@
|
||||
## You should have received a copy of the GNU General Public License along
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.Warning
|
||||
from libprs500 import iswindows
|
||||
import sys, os
|
||||
import os
|
||||
|
||||
from PyQt4.QtCore import QThread, SIGNAL, QObject
|
||||
|
||||
_libusb_available = False
|
||||
try:
|
||||
from libprs500.devices.prs500.driver import PRS500
|
||||
_libusb_available = True
|
||||
except OSError, err: #libusb not availabe
|
||||
print >>sys.stderr, err
|
||||
from libprs500 import iswindows
|
||||
from libprs500.devices import devices
|
||||
|
||||
class DeviceDetector(QThread):
|
||||
'''
|
||||
@ -35,10 +30,7 @@ class DeviceDetector(QThread):
|
||||
@param sleep_time: Time to sleep between device probes in millisecs
|
||||
@type sleep_time: integer
|
||||
'''
|
||||
self.devices = []
|
||||
if _libusb_available:
|
||||
for dclass in (PRS500,):
|
||||
self.devices.append([dclass, False])
|
||||
self.devices = [[d, False] for d in devices()]
|
||||
self.sleep_time = sleep_time
|
||||
QThread.__init__(self)
|
||||
|
||||
@ -53,6 +45,7 @@ class DeviceDetector(QThread):
|
||||
try:
|
||||
connected = device[0].is_connected(helper=helper)
|
||||
except:
|
||||
raise
|
||||
connected = False
|
||||
if connected and not device[1]:
|
||||
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], True)
|
||||
@ -69,6 +62,7 @@ class DeviceManager(QObject):
|
||||
QObject.__init__(self)
|
||||
self.device_class = device_class
|
||||
self.device = device_class()
|
||||
self.device.open()
|
||||
|
||||
def device_removed(self):
|
||||
self.device = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user