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 05:18:44 (GMT)
committer Andrés Ambrois <andresambrois@gmail.com>2010-08-24 09:13:33 (GMT)
commit762835adc5631961848bdf13a57dd67473531189 (patch)
tree417faa95843951e19e35794eced889c08cc6aab2
parent5e2ec829b70aba6c15b6780e4fbaebcbb562965f (diff)
Add creation_time property.
-rw-r--r--src/carquinyol/datastore.py22
-rw-r--r--src/carquinyol/indexstore.py15
2 files changed, 37 insertions, 0 deletions
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)