Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/opds.py
diff options
context:
space:
mode:
authorSayamindu Dasgupta <sayamindu@gmail.com>2009-11-05 19:20:22 (GMT)
committer Sayamindu Dasgupta <sayamindu@gmail.com>2009-11-05 19:20:22 (GMT)
commitc3fecd3f7233f9332e567378edef5bc7085c467c (patch)
tree36f8f60e4b78ebd63ae3d96b9ada5943fb7016f8 /opds.py
parentcbd9cbe67af4d8024fe84850a6e61f5d86f38dfd (diff)
Implement support for removable volumes
Diffstat (limited to 'opds.py')
-rw-r--r--opds.py60
1 files changed, 57 insertions, 3 deletions
diff --git a/opds.py b/opds.py
index 5720669..305a941 100644
--- a/opds.py
+++ b/opds.py
@@ -19,6 +19,7 @@
import feedparser
import threading
+import os
import gobject
@@ -36,7 +37,10 @@ class DownloadThread(threading.Thread):
self.stopthread = threading.Event()
def _download(self):
- feedobj = feedparser.parse(self.obj._uri + self.obj._queryterm.replace(' ', '+'))
+ if not self.obj.is_local():
+ feedobj = feedparser.parse(self.obj._uri + self.obj._queryterm.replace(' ', '+'))
+ else:
+ feedobj = feedparser.parse(self.obj._uri)
self.obj._feedobj = feedobj
self.obj.emit('completed')
@@ -56,10 +60,20 @@ class Book(object):
self._entry = entry
def get_title(self):
- return self._entry['title']
+ try:
+ ret = self._entry['title']
+ except KeyError:
+ ret = 'Unknown'
+
+ return ret
def get_author(self):
- return self._entry['author']
+ try:
+ ret = self._entry['author']
+ except KeyError:
+ ret = 'Unknown'
+
+ return ret
def get_download_links(self):
ret = {}
@@ -93,6 +107,18 @@ class Book(object):
return ret
+ def match(self, terms):
+ #TODO: Make this more comprehensive
+ for term in terms.split('+'):
+ if term in self.get_title():
+ return True
+ if term in self.get_author():
+ return True
+ if term in self.get_publisher():
+ return True
+
+ return False
+
class QueryResult(gobject.GObject):
__gsignals__ = {
@@ -138,6 +164,34 @@ class QueryResult(gobject.GObject):
def is_ready(self):
return self._ready
+ def is_local(self):
+ '''
+ Returns True in case of a local school
+ server or a local device
+ (yay! for sneakernet)
+ '''
+ return False
+
+class LocalVolumeQueryResult(QueryResult):
+ def __init__(self, path, queryterm):
+ QueryResult.__init__(self, os.path.join(path, 'catalog.xml'), queryterm)
+
+ def is_local(self):
+ return True
+
+ def get_book_list(self):
+ ret = []
+ if self._queryterm is None or self._queryterm is '':
+ for entry in self._feedobj['entries']:
+ ret.append(Book(entry))
+ else:
+ for entry in self._feedobj['entries']:
+ book = Book(entry)
+ if book.match(self._queryterm.replace(' ', '+')):
+ ret.append(book)
+
+ return ret
+
class FeedBooksQueryResult(QueryResult):
def __init__(self, queryterm):
QueryResult.__init__(self, _FEEDBOOKS_URI, queryterm)