def Connect(uri=DEFAULT_URI): """ Establishes a connection to the graph database backend. It also does a few standard tasks to set up the models and server side scripts we depend on, so every utility that calls Connect() has a consistent environment. Returns a Graph() object. Example: g = Connect() # Connect using the standard default database info g = Connect("http://localhost:8182/graphs/myDB") # Use a custom DB """ config = Config(uri) g = Graph(config) # Set up the node and relationship proxies g.add_proxy("host", Host) g.add_proxy("flow", Flow) g.add_proxy("source", Source) g.add_proxy("contains", Contains) g.add_proxy("dest", Dest) g.add_proxy("connectedTo", ConnectedTo) g.add_proxy("fqdn", FQDN) g.add_proxy("dnsTransaction", DNSTransaction) g.add_proxy("resolved", Resolved) g.add_proxy("answer", Answer) g.add_proxy("queried", Queried) g.add_proxy("queriedServer", QueriedServer) g.add_proxy("lookedUp", LookedUp) g.add_proxy("resolvedTo", ResolvedTo) g.add_proxy("file", File) g.add_proxy("transferred", Transferred) g.add_proxy("sentTo", SentTo) g.add_proxy("sentBy", SentBy) g.add_proxy("httpTransaction", HTTPTransaction) g.add_proxy("uri", URI) g.add_proxy("userAgent", UserAgent) g.add_proxy("requestedBy", RequestedBy) g.add_proxy("requestedOf", RequestedOf) g.add_proxy("hostedBy", HostedBy) g.add_proxy("identifiedBy", IdentifiedBy) g.add_proxy("agent", Agent) g.add_proxy("sent", Sent) g.add_proxy("received", Received) g.add_proxy("account", Account) g.add_proxy("requested", Requested) g.add_proxy("uses", Uses) # Load in our groovy scripts g.scripts.update("groovy/gremlin.groovy") return g
def test_suite(): # pass in a db_name to test a specific database client = RexsterClient(db_name=db_name) BulbsTestCase.client = client BulbsTestCase.vertex_index_proxy = VertexIndexProxy BulbsTestCase.edge_index_proxy = EdgeIndexProxy BulbsTestCase.index_class = ManualIndex BulbsTestCase.graph = Graph(client.config) suite = bulbs_test_suite() #suite.addTest(unittest.makeSuite(RestTestCase)) suite.addTest(unittest.makeSuite(GremlinTestCase)) return suite
# -*- coding: utf-8 -*- ''' Created on 12 авг. 2014 г. @author: feelosoff ''' from bulbs.config import Config from bulbs.rexster import Graph, Edge, Vertex from bulbs.rexster.client import REXSTER_URI Edge() Vertex() c = Config('http://localhost:8182/graphs/myorientgraph') g = Graph(c) james = g.vertices.create(name="James") julie = g.vertices.create(name="Julie") g.edges.create(james, "knows", julie) if __name__ == '__main__': pass
from flask import json from flaskext.login import UserMixin from dagcuss import app class RexsterConnectionError(Exception): pass config = Config(app.config['REXSTER_DB_URI']) if app.config['BULBS_DEBUG']: config.set_logger(logging.DEBUG) try: graph = Graph(config) except socket.error: raise RexsterConnectionError( "Are you running Rexster on host/port pair in REXSTER_DB_URI?") graph.scripts.update(os.path.join(os.path.dirname(__file__), 'gremlin.groovy')) def element_to_model(e, model_cls): if e == None: return None m = model_cls(e._client) m._initialize(e._result) return m class User(Node, UserMixin):