Make CapCollection understandable and useable by humans
* Make the declaration of fct and it in the constructor Collection, instead of adding them from the outside * Add a function to flatten a list containing collection (solves the radioob search crash) * Better display of collections in the "ls" command (and display both id and title) * The "cd" command goes to the root of the path (like the UNIX cd) * Move the Video object of canalplus in a correct path * Make Collection iterable * Add comments to CapCollection * Cache the result of fct in a Collection; it is only called once * CollectionNotFound errors can be more explicit by providing a path * Require utf-8 in collection paths * Code cleanups
This commit is contained in:
parent
10215d1e4c
commit
682e14c86a
14 changed files with 125 additions and 63 deletions
|
|
@ -854,6 +854,14 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
for obj in self.objects:
|
||||
if isinstance(obj, CapBaseObject):
|
||||
self.format(obj)
|
||||
elif isinstance(obj, Collection):
|
||||
if obj.id and obj.title:
|
||||
print u'Collection: %s%s%s (%s)' % \
|
||||
(self.BOLD, obj.id, self.NC, obj.title)
|
||||
elif obj.id:
|
||||
print u'Collection: %s%s%s' % (self.BOLD, obj.id, self.NC)
|
||||
else:
|
||||
print obj
|
||||
else:
|
||||
print obj.title
|
||||
|
||||
|
|
@ -861,13 +869,15 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
|
||||
def do_cd(self, line):
|
||||
"""
|
||||
cd PATH
|
||||
cd [PATH]
|
||||
|
||||
Follow a path.
|
||||
If empty, return home.
|
||||
"""
|
||||
line = line.encode('utf-8')
|
||||
|
||||
self.working_path.extend(line)
|
||||
if not len(line.strip()):
|
||||
self.working_path.home()
|
||||
else:
|
||||
self.working_path.extend(line)
|
||||
|
||||
objects = self._fetch_objects()
|
||||
if len(objects) == 0:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel
|
||||
# Copyright(C) 2010-2012 Nicolas Duhamel, Laurent Bachelier
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
|
|
@ -27,6 +27,9 @@ class Path(object):
|
|||
|
||||
|
||||
def extend(self, user_input):
|
||||
"""
|
||||
Add a new part to the current path
|
||||
"""
|
||||
|
||||
user_input = urllib.quote_plus(user_input)
|
||||
user_input = posixpath.normpath(user_input)
|
||||
|
|
@ -49,8 +52,17 @@ class Path(object):
|
|||
self._working_path = final_parse
|
||||
|
||||
def restore(self):
|
||||
"""
|
||||
Go to the previous path
|
||||
"""
|
||||
self._working_path = self._previous
|
||||
|
||||
def home(self):
|
||||
"""
|
||||
Go to the root
|
||||
"""
|
||||
self._previous = self._working_path
|
||||
self._working_path = []
|
||||
|
||||
def get(self):
|
||||
return copy.copy(self._working_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue