From 762835adc5631961848bdf13a57dd67473531189 Mon Sep 17 00:00:00 2001 From: Andrés Ambrois Date: Tue, 24 Aug 2010 05:18:44 +0000 Subject: Add creation_time property. --- diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py index 2c0a7f0..fb999b2 100644 --- a/src/carquinyol/datastore.py +++ b/src/carquinyol/datastore.py @@ -167,6 +167,17 @@ class DataStore(dbus.service.Object): if not props.get('timestamp', ''): props['timestamp'] = int(time.time()) + # FIXME: Support for the deprecated ctime property. Remove in 0.92. + if 'ctime' in props: + try: + props['creation_time'] = time.mktime(time.strptime( + migration.DATE_FORMAT, props['ctime'])) + except (TypeError, ValueError): + pass + + if 'creation_time' not in props: + props['creation_time'] = time.time() + if os.path.exists(file_path): stat = os.stat(file_path) props['filesize'] = stat.st_size @@ -209,6 +220,17 @@ class DataStore(dbus.service.Object): if not props.get('timestamp', ''): props['timestamp'] = int(time.time()) + # FIXME: Support for the deprecated ctime property. Remove in 0.92. + if 'ctime' in props: + try: + props['creation_time'] = time.mktime(time.strptime( + migration.DATE_FORMAT, props['ctime'])) + except (TypeError, ValueError): + pass + + if 'creation_time' not in props: + props['creation_time'] = time.time() + if os.path.exists(file_path): stat = os.stat(file_path) props['filesize'] = stat.st_size diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py index b659db3..8a3de30 100644 --- a/src/carquinyol/indexstore.py +++ b/src/carquinyol/indexstore.py @@ -30,6 +30,7 @@ _VALUE_TIMESTAMP = 1 _VALUE_TITLE = 2 # 3 reserved for version support _VALUE_FILESIZE = 4 +_VALUE_CREATION_TIME = 5 _PREFIX_NONE = 'N' _PREFIX_FULL_VALUE = 'F' @@ -60,6 +61,7 @@ _QUERY_TERM_MAP = { _QUERY_VALUE_MAP = { 'timestamp': {'number': _VALUE_TIMESTAMP, 'type': float}, 'filesize': {'number': _VALUE_FILESIZE, 'type': int}, + 'creation_time': {'number': _VALUE_CREATION_TIME, 'type': float}, } @@ -76,6 +78,15 @@ class TermGenerator (xapian.TermGenerator): except (ValueError, TypeError): logging.debug('Invalid value for filesize property: %s', properties['filesize']) + if 'creation_time' in properties: + try: + document.add_value( + _VALUE_CREATION_TIME, xapian.sortable_serialise( + float(properties['creation_time']))) + except (ValueError, TypeError): + logging.debug('Invalid value for creation_time property: %s', + properties['creation_time']) + self.set_document(document) @@ -300,6 +311,10 @@ class IndexStore(object): enquire.set_sort_by_value(_VALUE_FILESIZE, True) elif order_by == '-filesize': enquire.set_sort_by_value(_VALUE_FILESIZE, False) + elif order_by == '+creation_time': + enquire.set_sort_by_value(_VALUE_CREATION_TIME, True) + elif order_by == '-creation_time': + enquire.set_sort_by_value(_VALUE_CREATION_TIME, False) else: logging.warning('Unsupported property for sorting: %s', order_by) -- cgit v0.9.1