Made cp command more usable and isolated problem in OSX to bulk reads

This commit is contained in:
Kovid Goyal 2006-11-14 22:59:31 +00:00
parent 6f1767a717
commit e456f6e828
3 changed files with 8 additions and 11 deletions

View File

@ -20,6 +20,6 @@ the following rule in C{/etc/udev/rules.d/90-local.rules} ::
BUS=="usb", SYSFS{idProduct}=="029b", SYSFS{idVendor}=="054c", MODE="660", GROUP="plugdev" BUS=="usb", SYSFS{idProduct}=="029b", SYSFS{idVendor}=="054c", MODE="660", GROUP="plugdev"
You may have to adjust the GROUP and the location of the rules file to suit your distribution. You may have to adjust the GROUP and the location of the rules file to suit your distribution.
""" """
VERSION = "0.2" VERSION = "0.2.1"
__docformat__ = "epytext" __docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>" __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"

View File

@ -185,10 +185,6 @@ class PRS500Device(object):
print >> sys.stderr, "Unable to find Sony Reader. Is it connected?" print >> sys.stderr, "Unable to find Sony Reader. Is it connected?"
sys.exit(1) sys.exit(1)
self.handle = self.device.open() self.handle = self.device.open()
if sys.platform == 'darwin' :
# For some reason, Mac OS X doesn't set the
# configuration automatically like Linux does.
self.handle.setConfiguration(1)
self.handle.claimInterface(self.device_descriptor.interface_id) self.handle.claimInterface(self.device_descriptor.interface_id)
self.handle.reset() self.handle.reset()
res = self._send_validated_command(GetUSBProtocolVersion()) res = self._send_validated_command(GetUSBProtocolVersion())
@ -276,6 +272,7 @@ class PRS500Device(object):
Read in C{bytes} bytes via a bulk transfer in packets of size S{<=} C{packet_size} Read in C{bytes} bytes via a bulk transfer in packets of size S{<=} C{packet_size}
@param data_type: an object of type type. The data packet is returned as an object of type C{data_type}. @param data_type: an object of type type. The data packet is returned as an object of type C{data_type}.
@return: A list of packets read from the device. Each packet is of type data_type @return: A list of packets read from the device. Each packet is of type data_type
@todo: Figure out how to make bulk reads work in OSX
""" """
def bulk_read_packet(data_type=Answer, size=0x1000): def bulk_read_packet(data_type=Answer, size=0x1000):
data = data_type(self.handle.bulkRead(PRS500Device.PRS500_BULK_IN_EP, size)) data = data_type(self.handle.bulkRead(PRS500Device.PRS500_BULK_IN_EP, size))
@ -445,7 +442,7 @@ class PRS500Device(object):
""" """
Create a file at path Create a file at path
@todo: Update file modification time if it exists @todo: Update file modification time if file already exists
""" """
if path.endswith("/") and len(path) > 1: path = path[:-1] if path.endswith("/") and len(path) > 1: path = path[:-1]
exists, file = self._exists(path) exists, file = self._exists(path)

View File

@ -212,9 +212,9 @@ def main():
info(dev) info(dev)
elif command == "cp": elif command == "cp":
usage="usage: %prog cp [options] source destination\n\n"+\ usage="usage: %prog cp [options] source destination\n\n"+\
"One of source or destination must be a path on the device. Device paths have the form:\n"+\ "One of source or destination must be a path on the device. \n\nDevice paths have the form\n"+\
"device:mountpoint/my/path\n"+\ "prs500:mountpoint/my/path\n"+\
"where mountpoint is one of /, a: or b:\n"+\ "where mountpoint is one of /, a: or b:\n\n"+\
"source must point to a file for which you have read permissions\n"+\ "source must point to a file for which you have read permissions\n"+\
"destination must point to a file or directory for which you have write permissions" "destination must point to a file or directory for which you have write permissions"
parser = OptionParser(usage=usage) parser = OptionParser(usage=usage)
@ -222,7 +222,7 @@ def main():
if len(args) != 2: if len(args) != 2:
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
if args[0].startswith("device:"): if args[0].startswith("prs500:"):
outfile = args[1] outfile = args[1]
path = args[0][7:] path = args[0][7:]
if path.endswith("/"): path = path[:-1] if path.endswith("/"): path = path[:-1]
@ -236,7 +236,7 @@ def main():
sys.exit(1) sys.exit(1)
dev.get_file(path, outfile) dev.get_file(path, outfile)
outfile.close() outfile.close()
elif args[1].startswith("device:"): elif args[1].startswith("prs500:"):
try: try:
infile = open(args[0], "r") infile = open(args[0], "r")
except IOError, e: except IOError, e: