Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-08-15 16:47:00 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-08-15 16:47:00 (GMT)
commitb2d40c3e077c78331bd581d199839faba97e7bd5 (patch)
tree8cf179db3f1a7a1510fcf04667c171c9e52617ba
parentdfcd49723178cb4c29aeb1800c7bb34d65cb9807 (diff)
Add "timestamp" property to Artifact to fully emulate DS
-rw-r--r--sugar_network/local/datastore.py6
-rw-r--r--sugar_network/local/dbus_datastore.py12
-rw-r--r--sugar_network/resources/artifact.py4
-rwxr-xr-xtests/units/datastore.py6
4 files changed, 20 insertions, 8 deletions
diff --git a/sugar_network/local/datastore.py b/sugar_network/local/datastore.py
index a1602e1..b5d51fa 100644
--- a/sugar_network/local/datastore.py
+++ b/sugar_network/local/datastore.py
@@ -35,7 +35,8 @@ MAP_PROPS = {
'tags': ('tags', lambda x: ' '.join(x), lambda x: str(x).split()),
'filesize': ('filesize', lambda x: str(x or 0), lambda x: int(x or 0)),
'creation_time': ('ctime', lambda x: str(x or 0), None),
- 'timestamp': ('mtime', lambda x: str(x or 0), None),
+ 'timestamp': ('timestamp', lambda x: str(x or 0),
+ lambda x: int(x or 0)),
'mtime': ('mtime', lambda x:
time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(x or 0)), None),
}
@@ -43,6 +44,7 @@ MAP_PROPS = {
ALL_SN_PROPS = (
'guid', 'context', 'keep', 'mime_type', 'title', 'description',
'activity_id', 'filesize', 'traits', 'tags', 'ctime', 'mtime',
+ 'timestamp',
)
_logger = logging.getLogger('local.datastore')
@@ -95,8 +97,6 @@ def populate(artifacts):
props[sn_prop] = typecast(value)
elif ds_prop == 'creation_time':
props['ctime'] = int(value)
- elif ds_prop == 'timestamp':
- props['mtime'] = int(value)
else:
props['traits'][ds_prop] = value
artifacts.create(props)
diff --git a/sugar_network/local/dbus_datastore.py b/sugar_network/local/dbus_datastore.py
index bceb140..815af9c 100644
--- a/sugar_network/local/dbus_datastore.py
+++ b/sugar_network/local/dbus_datastore.py
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
+import time
import tempfile
from cStringIO import StringIO
from os.path import exists
@@ -43,8 +44,6 @@ class Datastore(dbus_thread.Service):
event_type = event['event']
if event_type == 'create':
self.Created(event['guid'])
- elif event_type == 'update':
- self.Updated(event['guid'])
elif event_type == 'delete':
self.Deleted(event['guid'])
elif event_type == 'populate':
@@ -78,6 +77,7 @@ class Datastore(dbus_thread.Service):
@method(_INTERFACE, in_signature='a{sv}sb', out_signature='s',
async_callbacks=('reply_cb', 'error_cb'), byte_arrays=True)
def create(self, props, file_path, transfer_ownership, reply_cb, error_cb):
+ props['timestamp'] = int(props.get('timestamp', 0) or time.time())
self._update('POST', props, file_path, transfer_ownership,
reply_cb, error_cb)
@@ -85,8 +85,14 @@ class Datastore(dbus_thread.Service):
async_callbacks=('reply_cb', 'error_cb'), byte_arrays=True)
def update(self, uid, props, file_path, transfer_ownership,
reply_cb, error_cb):
+
+ def reply():
+ self.Updated(uid)
+ reply_cb()
+
+ props['timestamp'] = int(props.get('timestamp', 0) or time.time())
self._update('PUT', props, file_path, transfer_ownership,
- reply_cb, error_cb, guid=uid)
+ reply, error_cb, guid=uid)
@method(_INTERFACE, in_signature='a{sv}as', out_signature='aa{sv}u',
async_callbacks=('reply_cb', 'error_cb'))
diff --git a/sugar_network/resources/artifact.py b/sugar_network/resources/artifact.py
index d06de2c..8fd35b6 100644
--- a/sugar_network/resources/artifact.py
+++ b/sugar_network/resources/artifact.py
@@ -52,6 +52,10 @@ class Artifact(Resource):
def filesize(self, value):
return value
+ @ad.active_property(slot=8, prefix='M', typecast=int, default=0)
+ def timestamp(self, value):
+ return value
+
@ad.active_property(ad.StoredProperty, typecast=dict, default={})
def traits(self, value):
return value
diff --git a/tests/units/datastore.py b/tests/units/datastore.py
index 3253b07..339e073 100755
--- a/tests/units/datastore.py
+++ b/tests/units/datastore.py
@@ -95,7 +95,8 @@ class DatastoreTest(tests.Test):
'keep': False,
'mime_type': 'mime_type-1',
'tags': ['tag1', 'tag2', 'tag3'],
- 'mtime': 11,
+ 'timestamp': 11,
+ 'mtime': 0,
'title': {'en': 'title-1'},
'filesize': 1,
'traits': {'title_set_by_user': '1', 'prop': 'value-1'},
@@ -120,7 +121,8 @@ class DatastoreTest(tests.Test):
'keep': True,
'mime_type': 'mime_type-2',
'tags': ['tag4', 'tag5'],
- 'mtime': 4,
+ 'timestamp': 4,
+ 'mtime': 0,
'title': {'en': 'title-2'},
'filesize': 2,
'traits': {'title_set_by_user': '2', 'prop': 'value-2'},