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
suit your distribution.
"""
__version__ = "0.3.2"
__version__ = "0.3.3"
__docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"

View File

@ -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__()

View File

@ -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":

View File

@ -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

View File

@ -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_ = [ \

View File

@ -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()