Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrés Ambrois <andresambrois@gmail.com>2010-08-24 03:54:59 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-08-24 16:01:47 (GMT)
commit089ba387eafec10734ce3023665a163c531b82b4 (patch)
treec4c04e14b7c72ea35793d4ca818cbe050b8fb2a9
parent0c3d1b3aaeb0ca69693aa325e32e143a9fae047f (diff)
Add filesize property to the index.
Don't fail indexing if filesize is missing.
-rw-r--r--src/carquinyol/datastore.py12
-rw-r--r--src/carquinyol/indexstore.py14
2 files changed, 26 insertions, 0 deletions
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 82a6207..44df5a2 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -159,6 +159,12 @@ class DataStore(dbus.service.Object):
if not props.get('timestamp', ''):
props['timestamp'] = int(time.time())
+ if os.path.exists(file_path):
+ stat = os.stat(file_path)
+ props['filesize'] = stat.st_size
+ else:
+ props['filesize'] = 0
+
self._metadata_store.store(uid, props)
self._index_store.store(uid, props)
self._file_store.store(uid, file_path, transfer_ownership,
@@ -195,6 +201,12 @@ class DataStore(dbus.service.Object):
if not props.get('timestamp', ''):
props['timestamp'] = int(time.time())
+ if os.path.exists(file_path):
+ stat = os.stat(file_path)
+ props['filesize'] = stat.st_size
+ else:
+ props['filesize'] = 0
+
self._metadata_store.store(uid, props)
self._index_store.store(uid, props)
diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
index 62b843b..b659db3 100644
--- a/src/carquinyol/indexstore.py
+++ b/src/carquinyol/indexstore.py
@@ -28,6 +28,8 @@ from carquinyol.layoutmanager import MAX_QUERY_LIMIT
_VALUE_UID = 0
_VALUE_TIMESTAMP = 1
_VALUE_TITLE = 2
+# 3 reserved for version support
+_VALUE_FILESIZE = 4
_PREFIX_NONE = 'N'
_PREFIX_FULL_VALUE = 'F'
@@ -57,6 +59,7 @@ _QUERY_TERM_MAP = {
_QUERY_VALUE_MAP = {
'timestamp': {'number': _VALUE_TIMESTAMP, 'type': float},
+ 'filesize': {'number': _VALUE_FILESIZE, 'type': int},
}
@@ -66,6 +69,13 @@ class TermGenerator (xapian.TermGenerator):
document.add_value(_VALUE_TIMESTAMP,
xapian.sortable_serialise(float(properties['timestamp'])))
document.add_value(_VALUE_TITLE, properties.get('title', '').strip())
+ if 'filesize' in properties:
+ try:
+ document.add_value(_VALUE_FILESIZE,
+ xapian.sortable_serialise(int(properties['filesize'])))
+ except (ValueError, TypeError):
+ logging.debug('Invalid value for filesize property: %s',
+ properties['filesize'])
self.set_document(document)
@@ -286,6 +296,10 @@ class IndexStore(object):
enquire.set_sort_by_value(_VALUE_TITLE, True)
elif order_by == '-title':
enquire.set_sort_by_value(_VALUE_TITLE, False)
+ elif order_by == '+filesize':
+ enquire.set_sort_by_value(_VALUE_FILESIZE, True)
+ elif order_by == '-filesize':
+ enquire.set_sort_by_value(_VALUE_FILESIZE, False)
else:
logging.warning('Unsupported property for sorting: %s', order_by)