[Sugar-devel] [PATCH v1 4/5] Add ctime property to the index and datastore

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


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

diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 93ad419..9f0be96 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -154,8 +154,11 @@ class DataStore(dbus.service.Object):
         uid = str(uuid.uuid4())
         logging.debug('datastore.create %r', uid)
 
+        ctime = int(time.time())
         if not props.get('timestamp', ''):
-            props['timestamp'] = int(time.time())
+            props['timestamp'] = ctime
+        if not props.get('ctime', ''):
+            props['ctime'] = ctime
 
         if os.path.exists(file_path):
             stat = os.stat(file_path)
@@ -196,8 +199,11 @@ class DataStore(dbus.service.Object):
                async_cb, async_err_cb):
         logging.debug('datastore.update %r', uid)
 
+        timestamp = int(time.time())
+        if not props.get('ctime', ''):
+            props['ctime'] = props.get('timestamp', timestamp)
         if not props.get('timestamp', ''):
-            props['timestamp'] = int(time.time())
+            props['timestamp'] = timestamp
 
         if os.path.exists(file_path):
             stat = os.stat(file_path)
diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
index 121ae25..49b6c09 100644
--- a/src/carquinyol/indexstore.py
+++ b/src/carquinyol/indexstore.py
@@ -61,6 +61,7 @@ _QUERY_TERM_MAP = {
 _QUERY_VALUE_MAP = {
     'timestamp': {'number': _VALUE_TIMESTAMP, 'type': float},
     'filesize': {'number': _VALUE_FILESIZE, 'type': int},
+    'ctime': {'number': _VALUE_CTIME, 'type': int},
 }
 
 
@@ -72,6 +73,8 @@ class TermGenerator (xapian.TermGenerator):
         document.add_value(_VALUE_TITLE, properties.get('title', '').strip())
         document.add_value(_VALUE_FILESIZE,
             xapian.sortable_serialise(int(properties['filesize'])))
+        document.add_value(_VALUE_CTIME,
+            xapian.sortable_serialise(int(properties['ctime'])))
 
         self.set_document(document)
 
@@ -286,6 +289,10 @@ class IndexStore(object):
             enquire.set_sort_by_value(_VALUE_TIMESTAMP, True)
         elif order_by == '-timestamp':
             enquire.set_sort_by_value(_VALUE_TIMESTAMP, False)
+        elif order_by == '+ctime':
+            enquire.set_sort_by_value(_VALUE_CTIME, True)
+        elif order_by == '-ctime':
+            enquire.set_sort_by_value(_VALUE_CTIME, False)
         elif order_by == '+title':
             enquire.set_sort_by_value(_VALUE_TITLE, True)
         elif order_by == '-title':
-- 
1.6.3.3



More information about the Sugar-devel mailing list