add library capability and backend and application for archimede software aloes http://www.archimed.fr/aloes/presentation-et-avantages-12.html

Signed-off-by: jems <jems@ldjm.fr>
Signed-off-by: Romain Bignon <romain@symlink.me>
This commit is contained in:
jems 2012-03-13 19:49:55 +01:00 committed by Romain Bignon
commit 24ab551694
10 changed files with 484 additions and 0 deletions

View file

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Jérémy Monnet
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .boobooks import Boobooks
__all__ = ['Boobooks']

View file

@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2009-2012 Jeremy Monnet
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.library import ICapBook, Book
from weboob.tools.application.repl import ReplApplication
from weboob.tools.application.formatters.iformatter import IFormatter
__all__ = ['Boobooks']
class RentedListFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'date', 'author', 'name', 'late')
RED = ''
count = 0
def flush(self):
self.count = 0
def format_dict(self, item):
self.count += 1
if self.interactive:
backend = item['id'].split('@', 1)[1]
id = '#%d (%s)' % (self.count, backend)
else:
id = item['id']
s = u'%s%s%s %s%s (%s)' % (self.BOLD, id, self.NC, item['author'], item['name'], item['date'])
if item['late']:
s += u' %sLATE!%s' % (self.RED, self.NC)
return s
class Boobooks(ReplApplication):
APPNAME = 'boobooks'
VERSION = '0.b'
COPYRIGHT = 'Copyright(C) 2012 Jeremy Monnet'
CAPS = ICapBook
DESCRIPTION = "Console application allowing to list your books rented or booked at the library, " \
"book and search new ones, get your booking history (if available)."
EXTRA_FORMATTERS = {'rented_list': RentedListFormatter,
}
DEFAULT_FORMATTER = 'table'
COMMANDS_FORMATTERS = {'ls': 'rented_list',
'list': 'rented_list',
}
COLLECTION_OBJECTS = (Book, )

View file

@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2012 Jeremy Monnet
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime, date
from .collection import ICapCollection, CollectionNotFound
from .base import CapBaseObject
__all__ = ['ICapBook', 'Book']
class Book(CapBaseObject):
def __init__(self, id):
CapBaseObject.__init__(self, id)
self.add_field('name', basestring)
self.add_field('author', basestring)
self.add_field('location', basestring)
self.add_field('date', (datetime, date)) # which may be the due date
self.add_field('late', bool)
class ICapBook(ICapCollection):
def iter_resources(self, objs, split_path):
if Book in objs:
if len(split_path) > 0:
raise CollectionNotFound(split_path)
return self.iter_books()
def iter_books(self, pattern):
raise NotImplementedError()
def get_book(self, _id):
raise NotImplementedError()
def get_booked(self, _id):
raise NotImplementedError()
def get_rented(self, _id):
raise NotImplementedError()
def search_books(self, _string):
raise NotImplementedError()