blob: dbf5a6169350e0d3aca8874afb0211f61796d029 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
'''
Created on 29 Aug 2012
@author: cgueret
'''
# See http://www.dns-sd.org/ServiceTypes.html
# See http://www.floop.org.uk/eagle/discovering-sparql
# http://stackp.online.fr/?p=35
from semanticxo import graphstore, addressbook
from semanticxo.graphstore import GraphStore
__all__ = ["GraphReplicator"]
class GraphReplicator(object):
'''
The graph replicator connects to the local triple stores and those
found in the neighbourhood to replicate public graphs
'''
def __init__(self):
self._lock = 0
def check(self):
'''
Performs a round of check and copy
'''
# Prevent from calling this running twice
if self._lock == 1:
pass
self._lock = 1
# Get the list of contacts
contacts = addressbook.get_neighbours()
print contacts
# Iterate through all of them
for host in contacts.itervalues():
local_graph_store = graphstore.get_instance()
remote_graph_store = GraphStore(hostname=host)
# Get the list of graphs to sync and their modification date
local_graphs = local_graph_store.get_graphs_modification_date()
remote_graphs = remote_graph_store.get_graphs_modification_date()
# Iterate over all the graphs, copy locally those that are not already
# stored or for which there is a new version
for (uri,date) in remote_graphs.iteritems():
if uri not in local_graphs or date > local_graphs[uri]:
data_graph = remote_graph_store.get_graph(uri)
local_graph_store.persist_graph(data_graph)
self._lock = 0
_instance_repli = None
def get_instance():
global _instance_repli
if _instance_repli is None:
_instance_repli = GraphReplicator()
return _instance_repli
|