Cleanups and minor bug fixes. ls -h works again. Various unicode related bugs squashed. Version bump.

This commit is contained in:
Kovid Goyal 2007-01-13 19:27:30 +00:00
parent 0be8846706
commit 6a8ed44d3e
7 changed files with 21 additions and 11 deletions

View File

@ -36,6 +36,6 @@ the following rule in C{/etc/udev/rules.d/90-local.rules} ::
You may have to adjust the GROUP and the location of the rules file to You may have to adjust the GROUP and the location of the rules file to
suit your distribution. suit your distribution.
""" """
__version__ = "0.3.2" __version__ = "0.3.3"
__docformat__ = "epytext" __docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>" __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"

View File

@ -94,7 +94,8 @@ class Book(object):
self.root = root self.root = root
def __repr__(self): def __repr__(self):
return self.title + u" by " + self.author + u" at " + self.path return self.title.encode('utf-8') + " by " + \
self.author.encode('utf-8') + " at " + self.path.encode('utf-8')
def __str__(self): def __str__(self):
return self.__repr__() return self.__repr__()

View File

@ -79,7 +79,7 @@ class FileFormatter(object):
def human_readable_size(): def human_readable_size():
doc=""" File size in human readable form """ doc=""" File size in human readable form """
def fget(self): def fget(self):
human_readable(self.size) return human_readable(self.size)
return property(doc=doc, fget=fget) return property(doc=doc, fget=fget)
@apply @apply
@ -208,7 +208,7 @@ def main():
elif command == "books": elif command == "books":
print "Books in main memory:" print "Books in main memory:"
for book in dev.books(): for book in dev.books():
print unicode(book) print book
print "\nBooks on storage card:" print "\nBooks on storage card:"
for book in dev.books(oncard=True): print book for book in dev.books(oncard=True): print book
elif command == "mkdir": elif command == "mkdir":

View File

@ -51,6 +51,7 @@ import os
import time import time
from tempfile import TemporaryFile from tempfile import TemporaryFile
from array import array from array import array
from functools import wraps
from libprs500.libusb import Error as USBError from libprs500.libusb import Error as USBError
from libprs500.libusb import get_device_by_id from libprs500.libusb import get_device_by_id
@ -65,7 +66,7 @@ MINIMUM_COL_WIDTH = 12 #: Minimum width of columns in ls output
KNOWN_USB_PROTOCOL_VERSIONS = [0x3030303030303130L] KNOWN_USB_PROTOCOL_VERSIONS = [0x3030303030303130L]
class Device(object): class Device(object):
""" Contains specific device independent methods """ """ Contains device independent methods """
_packet_number = 0 #: Keep track of the packet number for packet tracing _packet_number = 0 #: Keep track of the packet number for packet tracing
def log_packet(self, packet, header, stream=sys.stderr): def log_packet(self, packet, header, stream=sys.stderr):
@ -157,6 +158,7 @@ class PRS500Device(Device):
An L{usb.USBError} will cause the library to release control of the An L{usb.USBError} will cause the library to release control of the
USB interface via a call to L{close}. USB interface via a call to L{close}.
""" """
@wraps(func)
def run_session(*args, **kwargs): def run_session(*args, **kwargs):
dev = args[0] dev = args[0]
res = None res = None

View File

@ -18,7 +18,7 @@ This module provides a thin ctypes based wrapper around libusb.
import sys import sys
from ctypes import cdll, POINTER, byref, pointer, Structure, \ from ctypes import cdll, POINTER, byref, pointer, Structure, \
c_ubyte, c_ushort, c_int, c_char, c_void_p, c_byte c_ubyte, c_ushort, c_int, c_char, c_void_p, c_byte, c_uint
from errno import EBUSY, ENOMEM from errno import EBUSY, ENOMEM
_iswindows = 'win32' in sys.platform.lower() _iswindows = 'win32' in sys.platform.lower()
@ -196,7 +196,7 @@ class DeviceHandle(Structure):
if rsize < size: if rsize < size:
raise Error('Could not read ' + str(size) + ' bytes on the '\ raise Error('Could not read ' + str(size) + ' bytes on the '\
'control bus. Read: ' + str(rsize) + ' bytes.') 'control bus. Read: ' + str(rsize) + ' bytes.')
return tuple(arr) return arr
else: else:
ArrayType = c_byte * size ArrayType = c_byte * size
_libusb.usb_control_msg.argtypes = [POINTER(DeviceHandle), c_int, \ _libusb.usb_control_msg.argtypes = [POINTER(DeviceHandle), c_int, \
@ -222,7 +222,7 @@ class DeviceHandle(Structure):
if rsize < size: if rsize < size:
raise Error('Could not read ' + str(size) + ' bytes on the '\ raise Error('Could not read ' + str(size) + ' bytes on the '\
'bulk bus. Read: ' + str(rsize) + ' bytes.') 'bulk bus. Read: ' + str(rsize) + ' bytes.')
return tuple(arr) return arr
def bulk_write(self, endpoint, bytes, timeout=100): def bulk_write(self, endpoint, bytes, timeout=100):
""" """
@ -253,7 +253,9 @@ Bus._fields_ = [ \
('next', POINTER(Bus)), \ ('next', POINTER(Bus)), \
('previous', POINTER(Bus)), \ ('previous', POINTER(Bus)), \
('dirname', c_char * (PATH_MAX+1)), \ ('dirname', c_char * (PATH_MAX+1)), \
('devices', POINTER(Device)) ('devices', POINTER(Device)), \
('location', c_uint), \
('root_dev', POINTER(Device))\
] ]
Device._fields_ = [ \ Device._fields_ = [ \

View File

@ -29,6 +29,7 @@ import zlib
from shutil import copyfileobj from shutil import copyfileobj
from cStringIO import StringIO from cStringIO import StringIO
import xml.dom.minidom as dom import xml.dom.minidom as dom
from functools import wraps
from libprs500.prstypes import field from libprs500.prstypes import field
@ -233,6 +234,7 @@ class LRFMetaFile(object):
Decorator that ensures that function calls leave the pos Decorator that ensures that function calls leave the pos
in the underlying file unchanged in the underlying file unchanged
""" """
@wraps(func)
def restore_pos(*args, **kwargs): def restore_pos(*args, **kwargs):
obj = args[0] obj = args[0]
pos = obj._file.tell() pos = obj._file.tell()
@ -534,6 +536,9 @@ def main():
fields = LRFMetaFile.__dict__.items() fields = LRFMetaFile.__dict__.items()
for f in fields: for f in fields:
if "XML" in str(f): if "XML" in str(f):
print str(f[1]) + ":", lrf.__getattribute__(f[0]) print str(f[1]) + ":", lrf.__getattribute__(f[0]).encode('utf-8')
if options.get_thumbnail: if options.get_thumbnail:
print "Thumbnail:", td print "Thumbnail:", td
if __name__ == '__main__':
main()

View File

@ -615,7 +615,7 @@ class Response(Command):
first 16 bytes have the same structure. first 16 bytes have the same structure.
""" """
SIZE = 32 #: Size of response packets in the SONY protocol SIZE = 32 #: Size of response packets in the SONY protocol
# Response number, the command number of a command # Response number, the command number of a command
# packet sent sometime before this packet was received # packet sent sometime before this packet was received
rnumber = field(start=16, fmt=DWORD) rnumber = field(start=16, fmt=DWORD)