[Sugar-devel] [PATCH v1 1/5] Add filesize property to the index

Andrés Ambrois andresambrois at gmail.com
Sun May 23 08:04:07 EDT 2010


Signed-off-by: Andrés Ambrois <andresambrois at gmail.com>
---
 src/carquinyol/datastore.py  |   12 ++++++++++++
 src/carquinyol/indexstore.py |   10 ++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index a556869..93ad419 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -157,6 +157,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,
@@ -193,6 +199,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 8a69334..121ae25 100644
--- a/src/carquinyol/indexstore.py
+++ b/src/carquinyol/indexstore.py
@@ -28,6 +28,9 @@ from carquinyol.layoutmanager import MAX_QUERY_LIMIT
 _VALUE_UID = 0
 _VALUE_TIMESTAMP = 1
 _VALUE_TITLE = 2
+# 3 reserved for version support
+_VALUE_FILESIZE = 4
+_VALUE_CTIME = 5
 
 _PREFIX_NONE = 'N'
 _PREFIX_FULL_VALUE = 'F'
@@ -57,6 +60,7 @@ _QUERY_TERM_MAP = {
 
 _QUERY_VALUE_MAP = {
     'timestamp': {'number': _VALUE_TIMESTAMP, 'type': float},
+    'filesize': {'number': _VALUE_FILESIZE, 'type': int},
 }
 
 
@@ -66,6 +70,8 @@ class TermGenerator (xapian.TermGenerator):
         document.add_value(_VALUE_TIMESTAMP,
             xapian.sortable_serialise(float(properties['timestamp'])))
         document.add_value(_VALUE_TITLE, properties.get('title', '').strip())
+        document.add_value(_VALUE_FILESIZE,
+            xapian.sortable_serialise(int(properties['filesize'])))
 
         self.set_document(document)
 
@@ -284,6 +290,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)
 
-- 
1.6.3.3



More information about the Sugar-devel mailing list