Ejemplo n.º 1
0
    def sync(self,
             host,
             graph_name,
             username=None,
             password=None,
             dry_run=False):
        """
        Sync the current internal spec using the given graph on the given host.

        :param host: The host in <hostname>:<port> or <hostname> format
        :type host: str
        :param graph_name: The name of the graph as defined in rexster.xml
        :type graph_name: str
        :param username: The username for the rexster server
        :type username: str
        :param password: The password for the rexster server
        :type password: str
        :param dry_run: If true then the generated Gremlin will just be printed
        :type dry_run: boolean

        """
        def _get_name(x):
            """
            Return the name for the given object.

            :param x: The object
            :type x: Property, Edge, KeyIndex
            :rtype: str
            
            """
            if isinstance(x, Property) or isinstance(x, KeyIndex):
                return x.name
            elif isinstance(x, Edge):
                return x.label
            raise RuntimeError("Invalid object type {}".format(type(x)))

        if not dry_run:
            from thunderdome.connection import setup, execute_query
            setup(hosts=[host],
                  graph_name=graph_name,
                  username=username,
                  password=password,
                  index_all_fields=False)

        q = "def t = null"
        for x in self._results:
            name = _get_name(x)
            q += "t = g.getType('{}')\n".format(name)
            q += "if (t == null) {\n"
            q += "  {}\n".format(x.gremlin)
            q += "} else {\n"
            q += "  {} = g.getType('{}')\n".format(name, name)
            q += "}\n"
        q += "null"

        print q

        from thunderdome.connection import execute_query
        if not dry_run:
            return execute_query(q)
Ejemplo n.º 2
0
    def sync(self, host, graph_name, username=None, password=None):
        """
        Sync the current internal spec using the given graph on the given host.

        :param host: The host in <hostname>:<port> or <hostname> format
        :type host: str
        :param graph_name: The name of the graph as defined in rexster.xml
        :type graph_name: str
        :param username: The username for the rexster server
        :type username: str
        :param password: The password for the rexster server
        :type password: str

        """
        from thunderdome.connection import setup, execute_query
        setup(hosts=[host],
              graph_name=graph_name,
              username=username,
              password=password,
              index_all_fields=False)

        first_undefined = self._get_first_undefined(self._results)

        if first_undefined is None:
            return

        first_undefined = first_undefined[0]

        q = ""

        # Assign any already defined types to variables and search for the
        # first undefined type to be used as the starting point for executing
        # the remaining statements.
        results = []
        for i,x in enumerate(self._results):
            if isinstance(x, Property):
                if x.name == first_undefined:
                    results = self._results[i:]
                    break
                else:
                    q += "{} = g.getType('{}')\n".format(x.name, x.name)
            elif isinstance(x, Edge):
                if x.label == first_undefined:
                    results = self._results[i:]
                    break
                else:
                    q += "{} = g.getType('{}')\n".format(x.label, x.label)
            elif isinstance(x, KeyIndex):
                if x.name == first_undefined:
                    results = self._results[i:]
                    break

        for stmt in results:
            q += "{}\n".format(stmt.gremlin)
        q += "g.stopTransaction(SUCCESS)"

        print q

        execute_query(q)
Ejemplo n.º 3
0
    def sync(self, host, graph_name, username=None, password=None, dry_run=False):
        """
        Sync the current internal spec using the given graph on the given host.

        :param host: The host in <hostname>:<port> or <hostname> format
        :type host: str
        :param graph_name: The name of the graph as defined in rexster.xml
        :type graph_name: str
        :param username: The username for the rexster server
        :type username: str
        :param password: The password for the rexster server
        :type password: str
        :param dry_run: If true then the generated Gremlin will just be printed
        :type dry_run: boolean

        """

        def _get_name(x):
            """
            Return the name for the given object.

            :param x: The object
            :type x: Property, Edge, KeyIndex
            :rtype: str
            
            """
            if isinstance(x, Property) or isinstance(x, KeyIndex):
                return x.name
            elif isinstance(x, Edge):
                return x.label
            raise RuntimeError("Invalid object type {}".format(type(x)))

        if not dry_run:
            from thunderdome.connection import setup, execute_query

            setup(hosts=[host], graph_name=graph_name, username=username, password=password, index_all_fields=False)

        q = "def t = null"
        for x in self._results:
            name = _get_name(x)
            q += "t = g.getType('{}')\n".format(name)
            q += "if (t == null) {\n"
            q += "  {}\n".format(x.gremlin)
            q += "} else {\n"
            q += "  {} = g.getType('{}')\n".format(name, name)
            q += "}\n"
        q += "null"

        print q

        from thunderdome.connection import execute_query

        if not dry_run:
            return execute_query(q)
Ejemplo n.º 4
0
 def setUpClass(cls):
     super(BaseThunderdomeTestCase, cls).setUpClass()
     if not connection._hosts:
         connection.setup(['localhost'], 'thunderdome')
Ejemplo n.º 5
0
 def setUpClass(cls):
     super(BaseThunderdomeTestCase, cls).setUpClass()
     if not connection._hosts:
         connection.setup(['localhost'], 'thunderdome')
Ejemplo n.º 6
0
from datetime import datetime
from thunderdome.connection import setup
import thunderdome
from machete.base.config import config

host = config["rexster_host"]

setup([host], "machete", index_all_fields=False)


class BaseVertex(thunderdome.Vertex):
    created_at = thunderdome.DateTime(default=datetime.now)

    def __repr__(self):
        return "<{}:{}>".format(self.__class__.__name__, self.vid)

    @property
    def id(self):
        return self.vid

    @id.setter
    def id(self, id):
        self.vid = id

    @property
    def json(self):
        result = {}
        for name, col in self._columns.items():
            result[col.db_field or name] = col.to_python(getattr(self, name, None))

        # api is nicer with id instead of vid