Signed-off-by: Andrés Ambrois <andresambr...@gmail.com> --- src/carquinyol/datastore.py | 22 ++++++++++++++++++++-- src/carquinyol/indexstore.py | 17 +++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py index a556869..9f0be96 100644 --- a/src/carquinyol/datastore.py +++ b/src/carquinyol/datastore.py @@ -154,8 +154,17 @@ 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) + props['filesize'] = stat.st_size + else: + props['filesize'] = 0 self._metadata_store.store(uid, props) self._index_store.store(uid, props) @@ -190,8 +199,17 @@ 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) + 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..49b6c09 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,8 @@ _QUERY_TERM_MAP = { _QUERY_VALUE_MAP = { 'timestamp': {'number': _VALUE_TIMESTAMP, 'type': float}, + 'filesize': {'number': _VALUE_FILESIZE, 'type': int}, + 'ctime': {'number': _VALUE_CTIME, 'type': int}, } @@ -66,6 +71,10 @@ 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']))) + document.add_value(_VALUE_CTIME, + xapian.sortable_serialise(int(properties['ctime']))) self.set_document(document) @@ -280,10 +289,18 @@ 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': 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 _______________________________________________ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel