Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Gueret <christophe.gueret@gmail.com>2011-10-05 16:15:42 (GMT)
committer Christophe Gueret <christophe.gueret@gmail.com>2011-10-05 16:15:42 (GMT)
commitef2bc076a3764c29db6853715bb22a4168806309 (patch)
tree1d02d18eda35aa9824478cebdfc0ebe47cd67c72
parentb44e149a4b5e8bd257633c1d45a3346a6fcff859 (diff)
Started to better split the journal from the rest of the semanticxo
stack
-rwxr-xr-xbin/datastore-service.py1
-rw-r--r--bin/test.py8
-rw-r--r--src/carquinyol/datastore.py11
-rw-r--r--src/carquinyol/filestore.py2
-rw-r--r--src/semanticstore/__init__.py (renamed from src/semanticxo/__init__.py)0
-rw-r--r--src/semanticstore/indexstore.py (renamed from src/semanticxo/indexstore.py)9
-rw-r--r--src/semanticstore/layoutmanager.py (renamed from src/semanticxo/layoutmanager.py)0
-rw-r--r--src/semanticstore/metadatastore.py37
-rw-r--r--src/semanticxo/datastore.py39
-rw-r--r--src/semanticxo/metadatastore.py100
-rw-r--r--src/semanticxo/sparql.py42
11 files changed, 52 insertions, 197 deletions
diff --git a/bin/datastore-service.py b/bin/datastore-service.py
index 419321c..404d151 100755
--- a/bin/datastore-service.py
+++ b/bin/datastore-service.py
@@ -2,6 +2,7 @@
import os
import sys
sys.path.append(os.path.join(os.path.expanduser('~'), 'Code/SemanticXO/datastore/src'))
+sys.path.append(os.path.join(os.path.expanduser('~'), 'Code/SemanticXO/common/src'))
import signal
import logging
diff --git a/bin/test.py b/bin/test.py
index c5ec7df..4cf777b 100644
--- a/bin/test.py
+++ b/bin/test.py
@@ -12,10 +12,10 @@ if os.path.exists("/tmp/olpc-session-bus"):
if __name__ == "__main__":
entry = datastore.create()
- entry.metadata['title'] = 'Terminal Activity'
- entry.metadata['activity'] = 'org.laptop.Terminal'
- entry.metadata['activity_id'] = 'fca2a2a11810059906890855469ddb0c56be6a2a'
- entry.metadata['icon-color'] = '#FF8F00,#B20008'
+ #entry.metadata['title'] = 'Terminal Activity'
+ #entry.metadata['activity'] = 'org.laptop.Terminal'
+ #entry.metadata['activity_id'] = 'fca2a2a11810059906890855469ddb0c56be6a2a'
+ #entry.metadata['icon-color'] = '#FF8F00,#B20008'
datastore.write(entry)
print "Saved %s" % entry.get_object_id()
#entry.destroy()
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 82c5748..d35bb69 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -32,10 +32,10 @@ from carquinyol import migration
from carquinyol.filestore import FileStore
from carquinyol.optimizer import Optimizer
-from semanticxo import layoutmanager
-from semanticxo.layoutmanager import MAX_QUERY_LIMIT
-from semanticxo.metadatastore import MetadataStore
-from semanticxo.indexstore import IndexStore
+from semanticstore import layoutmanager
+from semanticstore.layoutmanager import MAX_QUERY_LIMIT
+from semanticstore.metadatastore import MetadataStore
+from semanticstore.indexstore import IndexStore
# the name used by the logger
DS_LOG_CHANNEL = 'org.laptop.sugar.DataStore'
@@ -208,7 +208,7 @@ class DataStore(dbus.service.Object):
props['filesize'] = 0
self._metadata_store.store(uid, props)
- self._index_store.store(uid, props)
+ #self._index_store.store(uid, props)
self._file_store.store(uid, file_path, transfer_ownership,
lambda * args: self._create_completion_cb(async_cb,
async_err_cb,
@@ -263,7 +263,6 @@ class DataStore(dbus.service.Object):
props['filesize'] = 0
self._metadata_store.store(uid, props)
- self._index_store.store(uid, props)
if os.path.exists(self._file_store.get_file_path(uid)) and \
(not file_path or os.path.exists(file_path)):
diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py
index b2c0980..1433d96 100644
--- a/src/carquinyol/filestore.py
+++ b/src/carquinyol/filestore.py
@@ -21,7 +21,7 @@ import tempfile
import gobject
-from semanticxo import layoutmanager
+from semanticstore import layoutmanager
class FileStore(object):
diff --git a/src/semanticxo/__init__.py b/src/semanticstore/__init__.py
index e69de29..e69de29 100644
--- a/src/semanticxo/__init__.py
+++ b/src/semanticstore/__init__.py
diff --git a/src/semanticxo/indexstore.py b/src/semanticstore/indexstore.py
index 84e2be6..e500fe4 100644
--- a/src/semanticxo/indexstore.py
+++ b/src/semanticstore/indexstore.py
@@ -17,13 +17,12 @@
import logging
import os
import gobject
-import httplib
-import urllib
-from semanticxo import layoutmanager
+
+from semanticstore import layoutmanager
+from semanticstore.layoutmanager import MAX_QUERY_LIMIT
+from semanticstore.metadatastore import OLPC_TERMS
from semanticxo.sparql import SPARQL
-from semanticxo.layoutmanager import MAX_QUERY_LIMIT
-from semanticxo.metadatastore import OLPC_TERMS
_VALUE_UID = 0
_VALUE_TIMESTAMP = 1
diff --git a/src/semanticxo/layoutmanager.py b/src/semanticstore/layoutmanager.py
index 11623e8..11623e8 100644
--- a/src/semanticxo/layoutmanager.py
+++ b/src/semanticstore/layoutmanager.py
diff --git a/src/semanticstore/metadatastore.py b/src/semanticstore/metadatastore.py
new file mode 100644
index 0000000..dbccdd0
--- /dev/null
+++ b/src/semanticstore/metadatastore.py
@@ -0,0 +1,37 @@
+'''
+Created on Apr 11, 2011
+
+@author: cgueret
+'''
+import logging
+from semanticxo.datastore import TripleStore
+from rdflib import Namespace
+OLPC_TERMS = Namespace("http://example.org/terms#")
+
+class MetadataStore(object):
+ '''
+ Store metadata into the triple store using HTTP calls.
+ '''
+ def __init__(self):
+ pass
+
+ def store(self, uid, metadata):
+ logging.debug('[MDS] store ' + uid + ' ' + str(metadata))
+ TripleStore.store_object(uid, metadata)
+
+ def retrieve(self, uid, properties=None):
+ logging.debug('[MDS] retrieve %r' % uid)
+ return TripleStore.get_object(uid, properties)
+
+ def delete(self, uid):
+ logging.debug('[MDS] delete')
+ pass
+
+ def get_property(self, uid, key):
+ logging.debug('[MDS] get')
+ pass
+
+ def set_property(self, uid, key, value):
+ logging.debug('[MDS] set')
+ pass
+
diff --git a/src/semanticxo/datastore.py b/src/semanticxo/datastore.py
deleted file mode 100644
index 191c0e0..0000000
--- a/src/semanticxo/datastore.py
+++ /dev/null
@@ -1,39 +0,0 @@
-'''
-Created on 24 Sep 2011
-
-@author: cgueret
-'''
-from rdflib import ConjunctiveGraph, RDF, URIRef, Namespace, Literal
-
-OLPC = Namespace("http://example.org/")
-
-class TripleStoreObject(object):
- pass
-
-class TripleStore(object):
- '''
- The TripleStore is a generic object interface with a triple store
- '''
- def __init__(self, params):
- '''
- Constructor of the TripleStore
- if an hostname is indicated, query the triple store of that machine
- instead of the one at localhost
- '''
- hostname = 'localhost'
- if 'hostname' in params.keys():
- hostname = params['hostname']
- self.store_url = 'http://%s:8080/' % hostname
- self.device_uid = 'ABC1234567890' #TODO find how to get the serial number
-
- def _get_resource(self, uid):
- '''
- Return the URI associated to a particular UID
- '''
- return URIRef(OLPC['resource/%s' % uid])
-
- def get_object(self, uid):
- '''
- Get a specific object associated to this UID
- '''
- \ No newline at end of file
diff --git a/src/semanticxo/metadatastore.py b/src/semanticxo/metadatastore.py
deleted file mode 100644
index b8b4e7b..0000000
--- a/src/semanticxo/metadatastore.py
+++ /dev/null
@@ -1,100 +0,0 @@
-'''
-Created on Apr 11, 2011
-
-@author: cgueret
-'''
-import logging
-import httplib
-import time
-from rdflib import ConjunctiveGraph, RDF, URIRef, Namespace, Literal
-from semanticxo.sparql import SPARQL
-
-OLPC = Namespace("http://example.org/")
-OLPC_TERMS = Namespace("http://example.org/terms#")
-
-_QUERY_INT_KEY = ['timestamp', 'filesize', 'creation_time']
-
-class MetadataStore(object):
- '''
- Store metadata into the triple store using HTTP calls.
- '''
- def __init__(self):
- self._url = '127.0.0.1:8080'
-
- def store(self, uid, metadata):
- logging.debug('[MDS] store ' + uid + ' ' + str(metadata))
- metadata['uid'] = uid
-
- # Preprocess the metadata
- props = {}
- for key, value in metadata.items():
-
- # Hack to support activities that still pass properties named as
- # for example title:text.
- if ':' in key:
- key = key.split(':', 1)[0]
-
- # Re-encode strings
- if isinstance(value, unicode):
- value = value.encode('utf-8')
- elif not isinstance(value, basestring):
- value = str(value)
-
- # Save new binding
- props[key] = value
-
- # Compose and save the graph
- graph = ConjunctiveGraph()
- resource = self._get_resource(uid)
- graph.add((resource, RDF.type, OLPC_TERMS['DSObject']))
- for key, value in props.items():
- if isinstance(key, basestring) and isinstance(value, basestring):
- key = OLPC_TERMS[key]
- try:
- value = Literal(value)
- graph.add((resource, key, value))
- except:
- pass
-
- # Save it
- logging.debug('[MDS] save > %s' % graph.serialize())
- headers = { 'Accept' : '*/*', 'Content-Type': 'application/rdf+xml' }
- conn = httplib.HTTPConnection(self._url)
- conn.request("PUT", "/data/%s" % resource, body=graph.serialize(), headers=headers)
- conn.getresponse()
- conn.close()
-
-
- def retrieve(self, uid, properties=None):
- logging.debug('[MDS] retrieve %r' % uid)
- props = {}
- query = 'SELECT ?p ?o WHERE { <%s> ?p ?o. }' % self._get_resource(uid)
- sparql = SPARQL()
- for result in sparql.execute_select(query):
- if result['p'].startswith(OLPC_TERMS):
- key=result['p'].split(OLPC_TERMS)[1]
- if key in _QUERY_INT_KEY:
- props[key] = int(result['o'])
- else:
- props[key] = result['o']
-
- # HACK: This is expected to be always present
- if 'creation_time' not in props:
- props['creation_time'] = int(time.time())
-
- return props
-
- def delete(self, uid):
- print '[MDS] delete'
- pass
-
- def get_property(self, uid, key):
- print '[MDS] get'
- pass
-
- def set_property(self, uid, key, value):
- print '[MDS] set'
- pass
-
- def _get_resource(self, uid):
- return URIRef(OLPC['resource/%s' % uid])
diff --git a/src/semanticxo/sparql.py b/src/semanticxo/sparql.py
deleted file mode 100644
index 968ecef..0000000
--- a/src/semanticxo/sparql.py
+++ /dev/null
@@ -1,42 +0,0 @@
-'''
-Created on 25 Aug 2011
-
-@author: cgueret
-'''
-import httplib
-import urllib
-import cjson
-from rdflib import URIRef, Literal
-
-class SPARQL(object):
- '''
- classdocs
- '''
-
-
- def __init__(self):
- '''
- Constructor
- '''
- self._url = '127.0.0.1:8080'
-
- def execute_select(self, query):
- params = {'query': query, 'format' : 'json'}
- headers = {'Content-Type': 'application/x-www-form-urlencoded'}
- conn = httplib.HTTPConnection(self._url)
- conn.request("POST", "/sparql", urllib.urlencode(params), headers=headers)
- # Get the results
- response = conn.getresponse()
- r = cjson.decode(response.read(), all_unicode=False)
- # Recode them
- results = []
- for entry in r['results']['bindings']:
- result = {}
- for (name,data) in entry.iteritems():
- value = Literal(data['value'])
- if data['type']=='uri':
- value = URIRef(data['value'])
- result[name] = value
- results.append(result)
- conn.close()
- return results