Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@sugarlabs.org>2011-03-22 20:31:52 (GMT)
committer Gonzalo Odiard <godiard@sugarlabs.org>2011-03-22 20:31:52 (GMT)
commit00fd70c220788a86a6ad4a5f826e23c5dc2f02eb (patch)
tree6d55e0d7929beb4120c3c1468302d8b80d5dbdf9
parent42d499f0c562e03f4fc1da1162299128c8c4162c (diff)
The parameters for the opds servers are configured in a file.
If the file /etc/get-books exists, is readed to load configuration this can be used by a deployment to add or change the sources.
-rwxr-xr-xGetIABooksActivity.py60
-rw-r--r--get-books.cfg13
-rw-r--r--opds.py26
3 files changed, 63 insertions, 36 deletions
diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py
index 56778ce..9402b3f 100755
--- a/GetIABooksActivity.py
+++ b/GetIABooksActivity.py
@@ -49,6 +49,7 @@ from gettext import gettext as _
import pango
import dbus
import gobject
+import ConfigParser
from listview import ListView
import opds
@@ -56,7 +57,8 @@ import languagenames
import devicemanager
_MIMETYPES = {'PDF': u'application/pdf', 'EPUB': u'application/epub+zip'}
-_SOURCES = {'Internet Archive': 'internet-archive', 'Feedbooks': 'feedbooks'}
+_SOURCES = {}
+_SOURCES_CONFIG = {}
_logger = logging.getLogger('get-ia-books-activity')
@@ -93,6 +95,10 @@ class GetIABooksActivity(activity.Activity):
self.queryresults = None
self._getter = None
+ self._read_configuration()
+ if os.path.exists('/etc/get-books.cfg'):
+ self._read_configuration('/etc/get-books.cfg')
+
if OLD_TOOLBAR:
toolbox = activity.ActivityToolbox(self)
@@ -127,6 +133,25 @@ class GetIABooksActivity(activity.Activity):
activity_toolbar.keep.props.visible = False
self._create_controls()
+ def _read_configuration(self, file_name='get-books.cfg'):
+ logging.error('Reading configuration')
+ config = ConfigParser.ConfigParser()
+ config.readfp(open(file_name))
+ self.show_images = True
+ if config.has_option('GetBooks', 'show_images'):
+ self.show_images = config.getboolean('GetBooks', 'show_images')
+
+ for section in config.sections():
+ if section != 'GetBooks':
+ name = config.get(section, 'name')
+ _SOURCES[section] = name
+ repo_config = {}
+ repo_config['query_uri'] = config.get(section, 'query_uri')
+ repo_config['opds_cover'] = config.get(section, 'opds_cover')
+ _SOURCES_CONFIG[section] = repo_config
+ logging.error('_SOURCES %s' % _SOURCES)
+ logging.error('_SOURCES_CONFIG %s' % _SOURCES_CONFIG)
+
def _add_search_controls(self, toolbar):
book_search_item = gtk.ToolItem()
toolbar.search_entry = iconentry.IconEntry()
@@ -444,27 +469,18 @@ class GetIABooksActivity(activity.Activity):
self.queryresults.cancel()
self.queryresults = None
- # This must be kept in sync with the sources list
- if source == 'feedbooks':
- if search_text is None:
- return
- elif len(search_text) == 0:
- self._alert(_('Error'),
- _('You must enter at least one search word.'))
- self._books_toolbar.search_entry.grab_focus()
- return
- self.queryresults = opds.FeedBooksQueryResult(search_text,
- self.window)
- elif source == 'internet-archive':
- if search_text is None:
- return
- elif len(search_text) == 0:
- self._alert(_('Error'),
- _('You must enter at least one search word.'))
- self._books_toolbar.search_entry.grab_focus()
- return
- self.queryresults = opds.InternetArchiveQueryResult(search_text,
- self.window)
+ if search_text is None:
+ return
+ elif len(search_text) == 0:
+ self._alert(_('Error'),
+ _('You must enter at least one search word.'))
+ self._books_toolbar.search_entry.grab_focus()
+ return
+
+ if source in _SOURCES_CONFIG:
+ repo_configuration = _SOURCES_CONFIG[source]
+ self.queryresults = opds.RemoteQueryResult(repo_configuration,
+ search_text, self.window)
else:
self.queryresults = opds.LocalVolumeQueryResult( \
source, search_text, self.window)
diff --git a/get-books.cfg b/get-books.cfg
new file mode 100644
index 0000000..2b102c7
--- /dev/null
+++ b/get-books.cfg
@@ -0,0 +1,13 @@
+[GetBooks]
+show_images = yes
+
+[Feedbooks]
+name = Feedbooks
+query_uri = http://feedbooks.com/books/search.atom?query=
+opds_cover = http://opds-spec.org/image
+
+[Internet Archive]
+name = Internet Archive
+query_uri = http://bookserver.archive.org/catalog/opensearch?q=
+opds_cover = http://opds-spec.org/image
+#opds_cover = http://opds-spec.org/image/thumbnail
diff --git a/opds.py b/opds.py
index 26b833d..16532c4 100644
--- a/opds.py
+++ b/opds.py
@@ -54,7 +54,7 @@ class DownloadThread(threading.Thread):
feedobj = feedparser.parse(self.obj._uri)
for entry in feedobj['entries']:
- self.obj._booklist.append(Book(entry))
+ self.obj._booklist.append(Book(self.obj._configuration, entry))
self.obj._feedobj = feedobj
self.obj.emit('updated', self.midway)
self.obj._ready = True
@@ -71,9 +71,10 @@ class DownloadThread(threading.Thread):
class Book(object):
- def __init__(self, entry, basepath=None):
+ def __init__(self, configuration, entry, basepath=None):
self._entry = entry
self._basepath = basepath
+ self._configuration = configuration
def get_title(self):
try:
@@ -133,7 +134,7 @@ class Book(object):
try:
ret = {}
for link in self._entry['links']:
- if link['rel'] == _REL_OPDS_COVER:
+ if link['rel'] == self._configuration['opds_cover']:
if self._basepath is not None and \
not (link['href'].startswith('http') or \
link['href'].startswith('ftp')):
@@ -165,9 +166,10 @@ class QueryResult(gobject.GObject):
([gobject.TYPE_BOOLEAN])),
}
- def __init__(self, uri, queryterm, win):
+ def __init__(self, configuration, queryterm, win):
gobject.GObject.__init__(self)
- self._uri = uri
+ self._configuration = configuration
+ self._uri = self._configuration['query_uri']
self._queryterm = queryterm
self._win = win
self._feedobj = None
@@ -246,8 +248,8 @@ class QueryResult(gobject.GObject):
class LocalVolumeQueryResult(QueryResult):
def __init__(self, path, queryterm, win):
- QueryResult.__init__(self, os.path.join(path, 'catalog.xml'),
- queryterm, win)
+ configuration = {'query_uri': os.path.join(path, 'catalog.xml')}
+ QueryResult.__init__(self, configuration, queryterm, win)
def is_local(self):
return True
@@ -265,11 +267,7 @@ class LocalVolumeQueryResult(QueryResult):
return ret
-class FeedBooksQueryResult(QueryResult):
- def __init__(self, queryterm, win):
- QueryResult.__init__(self, _FEEDBOOKS_URI, queryterm, win)
+class RemoteQueryResult(QueryResult):
-
-class InternetArchiveQueryResult(QueryResult):
- def __init__(self, queryterm, win):
- QueryResult.__init__(self, _INTERNETARCHIVE_URI, queryterm, win)
+ def __init__(self, configuration, queryterm, win):
+ QueryResult.__init__(self, configuration, queryterm, win)