Fix regressions in PRS500 handling.

This commit is contained in:
Kovid Goyal 2007-10-23 02:53:26 +00:00
parent d39c1a2130
commit 0ed6ddf783
4 changed files with 20 additions and 22 deletions

View File

@ -78,7 +78,7 @@ class Device(object):
def card_prefix(self, end_session=True): 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() raise NotImplementedError()

View File

@ -218,7 +218,7 @@ class PRS500(Device):
self.handle = None self.handle = None
@classmethod @classmethod
def is_connected(cls): def is_connected(cls, helper=None):
""" """
This method checks to see whether the device is physically connected. This method checks to see whether the device is physically connected.
It does not return any information about the validity of the It does not return any information about the validity of the
@ -463,7 +463,8 @@ class PRS500(Device):
""" """
if path.endswith("/"): if path.endswith("/"):
path = path[:-1] # We only copy files 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) _file = self.path_properties(path, end_session=False)
if _file.is_dir: if _file.is_dir:
raise PathError("Cannot read as " + path + " is a directory") raise PathError("Cannot read as " + path + " is a directory")
@ -525,7 +526,8 @@ class PRS500(Device):
""" Do a non recursive listsing of path """ """ Do a non recursive listsing of path """
if not path.endswith("/"): if not path.endswith("/"):
path += "/" # Initially assume path is a directory 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 = [] files = []
candidate = self.path_properties(path, end_session=False) candidate = self.path_properties(path, end_session=False)
if not candidate.is_dir: if not candidate.is_dir:
@ -597,7 +599,6 @@ class PRS500(Device):
@safe @safe
def card_prefix(self, end_session=True): def card_prefix(self, end_session=True):
'''Return prefix of path to card or None if no cards present'''
try: try:
path = 'a:/' path = 'a:/'
self.path_properties(path, end_session=False) self.path_properties(path, end_session=False)
@ -649,7 +650,8 @@ class PRS500(Device):
@todo: Update file modification time if it exists. @todo: Update file modification time if it exists.
Opening the file in write mode and then closing it doesn't work. 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: if path.endswith("/") and len(path) > 1:
path = path[:-1] path = path[:-1]
exists, _file = self._exists(path) exists, _file = self._exists(path)
@ -676,7 +678,8 @@ class PRS500(Device):
bytes = infile.tell() - pos bytes = infile.tell() - pos
start_pos = pos start_pos = pos
infile.seek(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) exists, dest = self._exists(path)
if exists: if exists:
if dest.is_dir: if dest.is_dir:
@ -746,7 +749,8 @@ class PRS500(Device):
def mkdir(self, path, end_session=True): def mkdir(self, path, end_session=True):
""" Make directory """ """ Make directory """
if path.startswith('card:/'): 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("/"): if not path.endswith("/"):
path += "/" path += "/"
error_prefix = "Cannot create directory " + path error_prefix = "Cannot create directory " + path
@ -764,7 +768,8 @@ class PRS500(Device):
@safe @safe
def rm(self, path, end_session=True): def rm(self, path, end_session=True):
""" Delete path from device if it is a file or an empty directory """ """ 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) dir = self.path_properties(path, end_session=False)
if not dir.is_dir: if not dir.is_dir:
self.del_file(path, end_session=False) self.del_file(path, end_session=False)

View File

@ -335,7 +335,6 @@ class PRS505(Device):
def delete_books(self, paths, end_session=True): def delete_books(self, paths, end_session=True):
for path in paths: for path in paths:
print path
os.unlink(path) os.unlink(path)
@classmethod @classmethod

View File

@ -12,17 +12,12 @@
## You should have received a copy of the GNU General Public License along ## 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., ## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.Warning ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.Warning
from libprs500 import iswindows import os
import sys, os
from PyQt4.QtCore import QThread, SIGNAL, QObject from PyQt4.QtCore import QThread, SIGNAL, QObject
_libusb_available = False from libprs500 import iswindows
try: from libprs500.devices import devices
from libprs500.devices.prs500.driver import PRS500
_libusb_available = True
except OSError, err: #libusb not availabe
print >>sys.stderr, err
class DeviceDetector(QThread): class DeviceDetector(QThread):
''' '''
@ -35,10 +30,7 @@ class DeviceDetector(QThread):
@param sleep_time: Time to sleep between device probes in millisecs @param sleep_time: Time to sleep between device probes in millisecs
@type sleep_time: integer @type sleep_time: integer
''' '''
self.devices = [] self.devices = [[d, False] for d in devices()]
if _libusb_available:
for dclass in (PRS500,):
self.devices.append([dclass, False])
self.sleep_time = sleep_time self.sleep_time = sleep_time
QThread.__init__(self) QThread.__init__(self)
@ -53,6 +45,7 @@ class DeviceDetector(QThread):
try: try:
connected = device[0].is_connected(helper=helper) connected = device[0].is_connected(helper=helper)
except: except:
raise
connected = False connected = False
if connected and not device[1]: if connected and not device[1]:
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], True) self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], True)
@ -69,6 +62,7 @@ class DeviceManager(QObject):
QObject.__init__(self) QObject.__init__(self)
self.device_class = device_class self.device_class = device_class
self.device = device_class() self.device = device_class()
self.device.open()
def device_removed(self): def device_removed(self):
self.device = None self.device = None