# Run me from myproj/data, in same directory as shabti_triplestore.xml

# Change the conspec string to suit your required conditions

import rdflib
from rdflib.Graph import Graph
from rdflib import plugin
from rdflib.store import Store
from rdflib import URIRef
import os
storeIdentifier = "shabti_triplestore"
default_graph_uri = "http://shabti.bel-epa.com/data"

conspec = "host=localhost,user=httpd,db=shabti_triplestore"

store = 'MySQL'

def init_graph():
    s = plugin.get(store, Store)(storeIdentifier)
    s.destroy(conspec)
    s.open(conspec, create=False)
    graph = Graph(s, identifier = URIRef(default_graph_uri))
    graph.load(os.getcwd()+'/shabti_triplestore.xml')
    s.commit()
    print "%s triples written" % len(list(graph.triples((None, None, None))))
    s.close()

def confirm_init():
    s = plugin.get(store, Store)(storeIdentifier)
    s.open(conspec, create=False)
    graph = Graph(s, identifier = URIRef(default_graph_uri))
    print "%s triples read" % len(list(graph.triples((None, None, None))))
    

init_graph()
confirm_init()