From 6a8ed44d3e97eb18ff83ab92068cc9fd95a10034 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 Jan 2007 19:27:30 +0000 Subject: [PATCH] Cleanups and minor bug fixes. ls -h works again. Various unicode related bugs squashed. Version bump. --- src/libprs500/__init__.py | 2 +- src/libprs500/books.py | 3 ++- src/libprs500/cli/main.py | 4 ++-- src/libprs500/communicate.py | 4 +++- src/libprs500/libusb.py | 10 ++++++---- src/libprs500/lrf/meta.py | 7 ++++++- src/libprs500/prstypes.py | 2 +- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/libprs500/__init__.py b/src/libprs500/__init__.py index dd3d40e3c4..b3f4fda6f0 100644 --- a/src/libprs500/__init__.py +++ b/src/libprs500/__init__.py @@ -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 suit your distribution. """ -__version__ = "0.3.2" +__version__ = "0.3.3" __docformat__ = "epytext" __author__ = "Kovid Goyal " diff --git a/src/libprs500/books.py b/src/libprs500/books.py index d3c0e26298..56cc3e5304 100644 --- a/src/libprs500/books.py +++ b/src/libprs500/books.py @@ -94,7 +94,8 @@ class Book(object): self.root = root 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): return self.__repr__() diff --git a/src/libprs500/cli/main.py b/src/libprs500/cli/main.py index 4027778a3d..f9078f1ec7 100755 --- a/src/libprs500/cli/main.py +++ b/src/libprs500/cli/main.py @@ -79,7 +79,7 @@ class FileFormatter(object): def human_readable_size(): doc=""" File size in human readable form """ def fget(self): - human_readable(self.size) + return human_readable(self.size) return property(doc=doc, fget=fget) @apply @@ -208,7 +208,7 @@ def main(): elif command == "books": print "Books in main memory:" for book in dev.books(): - print unicode(book) + print book print "\nBooks on storage card:" for book in dev.books(oncard=True): print book elif command == "mkdir": diff --git a/src/libprs500/communicate.py b/src/libprs500/communicate.py index b71d9fab0a..6afc9af1bc 100755 --- a/src/libprs500/communicate.py +++ b/src/libprs500/communicate.py @@ -51,6 +51,7 @@ import os import time from tempfile import TemporaryFile from array import array +from functools import wraps from libprs500.libusb import Error as USBError 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] class Device(object): - """ Contains specific device independent methods """ + """ Contains device independent methods """ _packet_number = 0 #: Keep track of the packet number for packet tracing 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 USB interface via a call to L{close}. """ + @wraps(func) def run_session(*args, **kwargs): dev = args[0] res = None diff --git a/src/libprs500/libusb.py b/src/libprs500/libusb.py index 3ed5c71c37..2831059304 100644 --- a/src/libprs500/libusb.py +++ b/src/libprs500/libusb.py @@ -18,7 +18,7 @@ This module provides a thin ctypes based wrapper around libusb. import sys 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 _iswindows = 'win32' in sys.platform.lower() @@ -196,7 +196,7 @@ class DeviceHandle(Structure): if rsize < size: raise Error('Could not read ' + str(size) + ' bytes on the '\ 'control bus. Read: ' + str(rsize) + ' bytes.') - return tuple(arr) + return arr else: ArrayType = c_byte * size _libusb.usb_control_msg.argtypes = [POINTER(DeviceHandle), c_int, \ @@ -222,7 +222,7 @@ class DeviceHandle(Structure): if rsize < size: raise Error('Could not read ' + str(size) + ' bytes on the '\ 'bulk bus. Read: ' + str(rsize) + ' bytes.') - return tuple(arr) + return arr def bulk_write(self, endpoint, bytes, timeout=100): """ @@ -253,7 +253,9 @@ Bus._fields_ = [ \ ('next', POINTER(Bus)), \ ('previous', POINTER(Bus)), \ ('dirname', c_char * (PATH_MAX+1)), \ - ('devices', POINTER(Device)) + ('devices', POINTER(Device)), \ + ('location', c_uint), \ + ('root_dev', POINTER(Device))\ ] Device._fields_ = [ \ diff --git a/src/libprs500/lrf/meta.py b/src/libprs500/lrf/meta.py index a8d2a57549..e59d91512d 100644 --- a/src/libprs500/lrf/meta.py +++ b/src/libprs500/lrf/meta.py @@ -29,6 +29,7 @@ import zlib from shutil import copyfileobj from cStringIO import StringIO import xml.dom.minidom as dom +from functools import wraps from libprs500.prstypes import field @@ -233,6 +234,7 @@ class LRFMetaFile(object): Decorator that ensures that function calls leave the pos in the underlying file unchanged """ + @wraps(func) def restore_pos(*args, **kwargs): obj = args[0] pos = obj._file.tell() @@ -534,6 +536,9 @@ def main(): fields = LRFMetaFile.__dict__.items() for f in fields: 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: print "Thumbnail:", td + +if __name__ == '__main__': + main() diff --git a/src/libprs500/prstypes.py b/src/libprs500/prstypes.py index 3dd4b22193..2f0dc55065 100755 --- a/src/libprs500/prstypes.py +++ b/src/libprs500/prstypes.py @@ -615,7 +615,7 @@ class Response(Command): 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 # packet sent sometime before this packet was received rnumber = field(start=16, fmt=DWORD)