Commits

Lynn Rees  committed f10e5b0

- fix references

  • Participants
  • Parent commits 4b8c4bb

Comments (0)

Files changed (12)

File graphalchemy/generics/elements.py

 defer = octopus.decorators.defer
 
 
-class Generic(ElementMixin, octopus.things.lifecycle):
+class Generic(ElementMixin, octopus.things.workflow):
 
     '''generic graph model'''
 

File graphalchemy/graphs.py

 subscribe = octopus.decorators.subscribe
 
 
-class Session(octopus.locals.protocol):
+class Session(octopus.locals.process):
 
     '''graph session'''
 
         '''
         super(Session, self).__init__(manager, max_length)
         # pipe for abort
-        self.pipe('abort', self.nodes.close)
+        self.M.pipe('abort', self.nodes.close)
 
     def __exit__(self, e, b, c):
         with self.nodes.transaction:
         self.nodes.close()
 
 
-class Graph(octopus.globals.protocol):
+class Graph(octopus.globals.process):
 
     '''graph interface'''
 
         @param url: database url
         '''
         super(Graph, self).__init__(**kw)
+        # get query
+        Q = self.Q
+        # default settings
+        defaults = self.defaults
+        # required settings
+        required = self.required
+        # get appspace name
+        userspace = kw.pop('appspace', defaults.userspace)
+        # graph managers
+        graph_manager = kw.pop('manager', defaults.manager.graph)
         # database driver
-        database = kw.pop('database', self.defaults.backend)
+        database = kw.pop('database', defaults.backend)
         # freeze settings
-        self.freeze(
+        self.freeze({
+            # store graph manager name
+            'manager.graph': graph_manager,
+            # store userspace name
+            'userspace': userspace,
             # store database source
-            database=database,
+            'database': database,
             # store database configuration
-            url=url,
-        )
+            'url': url,
+        })
         # database configuration in url format
         self.url = url
         # open database
-        self._db = self.Q.apply(database, self.S.backends, url)
-        # add data source to userspace
-        self.Q.set(self._db, self.S.key.backend, self.S.userspace)
+        self._db = Q.apply(database, required.backends, url)
+        # add manager instance to appspace
+        Q.set(self, graph_manager, userspace)
+        # add data source to appspace
+        Q.set(self._db, self.S.key.backend, userspace)
 
     def __repr__(self):
         return '{name}@{url}'.format(

File graphalchemy/managers.py

 subscribe = octopus.decorators.subscribe
 
 
-class Manager(octopus.processors.lifecycle):
+class Manager(octopus.flows.process):
 
     '''graph element manager base'''
 

File graphalchemy/mixins/collections.py

 __all__ = ('LinksMixin', 'NodesMixin')
 
 
-class CollectionMixin(octopus.things.thing):
+class CollectionMixin(octopus.things.context):
 
     '''element collection'''
 
 
     @lazy
     def _inner(self):
-        # inner list
         return self._this.l.walked(self._this, self.direction)
 
 
 
     @lazy
     def _inner(self):
-        # inner list
         return self._this.n.walked(
             self._this, self.direction, keys=self.keys, end=self.link_end,
         )

File graphalchemy/mixins/elements.py

 # -*- coding: utf-8 -*-
 '''graph element mixins'''
 
-from stuf.utils import both, getcls, lazy, lazy_class, clsname
+from stuf.utils import both, getcls, lazy, clsname, either
 
 from graphalchemy.core import octopus
 
         '''graph element id'''
         return self._p.id(self.source)
 
-    @lazy_class
+    @either
     def l(self):
         '''link wrapper'''
-        return self._l()
+        return self.session.links.wrap(self._link())
 
     # prime link
     _p = l
         '''
         return self._p.properties(this)
 
-    @classmethod
-    def _l(cls):
-        '''link wrapper'''
-        return cls._g.links.wrap(cls._link())
-
     def _refresh(self):
         '''refresh original'''
         super(ElementMixin, self).sync()
         self.links.reset()
 
     @defer
-    def delete(self, indices=None):
-        '''
-        delete element
-
-        @param indices: list of indexes (default: None)
-        '''
-        self._p.delete_element(self, indices)
-
-    @defer
     def index_by(self, index=None, *indexed):
         '''
         index properties on a graph element
             clsname(self), super(NodeMixin, self).__repr__(),
         )
 
-    @lazy_class
+    @lazy
     def n(self):
         '''node wrapper'''
-        return self._n()
+        return self.session.nodes.wrap(self)
 
     # prime element
     _p = n
 
-    @both
+    @lazy
     def nodes(self):
         '''connector to all nodes linked to this node'''
         return self._nodes(self, getcls(self))
 
-    @nodes.expression
-    def nodes(self):
-        '''wrapper for this node'''
-        return self.n
-
-    @classmethod
-    def _l(cls):
-        '''link wrapper'''
-        return cls._g.links.wrap(cls._link())
-
-    @classmethod
-    def _n(cls):
-        '''node wrapper'''
-        return cls._g.nodes.wrap(cls)
-
     def _refresh(self):
         '''refresh node objects'''
         super(NodeMixin, self)._refresh()

File graphalchemy/models/elements.py

 #pylint: disable-msg=e0203,w0201
 '''graph element models'''
 
-from stuf.utils import lazy_class, selfname, either
+from stuf.utils import lazy_class, selfname
 
 from graphalchemy.core import octopus
 from graphalchemy.errors import ReversionError
 direct = octopus.decorators.direct
 
 
-class Node(NodeMixin, ElementMixin, octopus.things.protocol):
+class Node(NodeMixin, ElementMixin, octopus.things.process):
 
     '''node model'''
 
         existing.update(metas)
         return existing
 
-    @either
-    def anchor(self, **kw):
-        '''anchor node for model'''
-        return self.n.anchorer(**kw)
-
-    @either
-    def reference(self):
-        '''model reference node'''
-        return self.n.reference()
-
     @classmethod
     def _link(cls):
         return cls.Q.get(cls.S.generic.element.link, cls.S.generics)
         self.update({'_versions': self._current['_versions'] + 1})
         return self._current['_versions']
 
-    @class_defer
-    def anchorer(self, **kw):
-        '''build anchor for node'''
-        return self.n.anchor(**kw)
-
     def commit(self):
         '''save this node'''
         super(Node, self).commit()
         self._refresh()
 
     @defer
-    def delete(self, indices=None):
-        '''
-        delete element
-
-        @param indices: list of indexes (default: None)
-        '''
-        if indices is None:
-            indices = set(v for k, v in self.C if k.endswith('index'))
-        super(Node, self).delete(indices)
-
-    @defer
-    def fork(self):
-        '''make exact clone of this node'''
-        fork = self.n.clone(self)
-        self._refresh()
-        return fork
-
-    @defer
     def modify(self, kw):
         '''update node'''
         self.n.update(self, kw)
         self._refresh()
 
-    @class_defer
-    def referrer(self, **kw):
-        '''make referring node for this model'''
-        return self.n.refer(**kw)
-
     @defer
     def revert(self, version):
         '''
         return self._versioning(diff) if diff else {}
 
     @defer
-    def weigh_anchor(self, **kw):
+    def anchor(self, anchor, **kw):
         '''link node to anchor'''
-        self.l.make(self.C.anchor_link, self, self.n.anchorer(), kw)
+        self.l.make(self.C.anchor_link, self, anchor, kw)
 
     class Meta:
         # anchor link label

File graphalchemy/tests/test_db.py

     graph.pipe('anyway', cleanup)
     with graph.session as session:
         gn = session.nodes
-        gn.w.create_index('roots')
-        gn.w.create_index('questions')
-        gn.w.create_index('question_text', fts=True)
-        gn.w.create_index('ideas')
-        gn.w.create_index('idea_text', fts=True)
-        gn.w.create_index('pros')
-        gn.w.create_index('pro_text', fts=True)
-        gn.w.create_index('cons')
-        gn.w.create_index('con_text', fts=True)
-        gn.w.create_index('tags')
+        gn.index('roots')
+        gn.index('questions')
+        gn.index('question_text', fts=True)
+        gn.index('ideas')
+        gn.index('idea_text', fts=True)
+        gn.index('pros')
+        gn.index('pro_text', fts=True)
+        gn.index('cons')
+        gn.index('con_text', fts=True)
+        gn.index('tags')
         root = gn.root()
         question = gn.create(text='question reference node')
         question.index_under('roots', 'reference', 'question')
         con_5.index_by('con_text', 'text')
         con_5.link('CON_NODE_OF', con, user=1)
         con_5.link('CON_AGAINST', idea_1, user=1)
-    cleanup()
+
 
 if __name__ == '__main__':
     import cProfile

File graphalchemy/tests/test_managers.py

         self.assertTrue(hasattr(self.graph.session.nodes, 'index_one'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'index_many'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'delete_property'))
-        self.assertTrue(hasattr(self.graph.session.nodes, 'delete_element'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'delete'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'autoslug'))
 
     def test_create_link_writer(self):
         self.assertTrue(hasattr(self.graph.session.links, 'index_one'))
         self.assertTrue(hasattr(self.graph.session.links, 'index_many'))
         self.assertTrue(hasattr(self.graph.session.links, 'delete_property'))
-        self.assertTrue(hasattr(self.graph.session.links, 'delete_element'))
+        self.assertTrue(hasattr(self.graph.session.links, 'delete'))
         self.assertTrue(hasattr(self.graph.session.links, 'autoslug'))
 
     def test_create_node_reader(self):

File graphalchemy/tests/test_models.py

     graph.pipe('anyway', cleanup)
     with graph.session as Session:
         Session.join(Question, Idea, Pro, Con, Tag)
-        Session.nodes.w.create_index('roots')
-        question = Question.referrer(user=1)
-        Session.add(question)
-        idea = Idea.referrer(user=1)
-        Session.add(idea)
-        pro = Pro.referrer(user=1)
-        Session.add(pro)
-        con = Con.referrer(user=1)
-        Session.add(con)
-        tag = Tag.referrer(user=1)
-        Session.add(tag)
+        Session.nodes.index('roots')
+        Session.nodes.refer(Question, user=1)
+        Session.nodes.refer(Idea, user=1)
+        Session.nodes.refer(Pro, user=1)
+        Session.nodes.refer(Con, user=1)
+        Session.nodes.refer(Tag, user=1)
         tag_1 = Tag(_status=1, text='wicked problem', user=1)
         Session.add(tag_1)
         tag_1.index_under('tags', 'name', 'wicked problem')
         tag_2.index_under('tags', 'name', 'avoid')
         root = tag_2.n.root()
         root.data.public.text = 'This is the root'
-        question_0 = Question.anchorer(user=1)
-        Session.add(question_0)
+        question_0 = Session.nodes.anchor(Question, user=1)
         question_1 = Question(
             _status=1,
             down=0,
             user=1,
         )
         Session.add(question_1)
-        question_1.weigh_anchor(user=1)
+        question_1.anchor(question_0, user=1)
         question_1.index_under('questions', 'tag', 'wicked problem')
         tag_1.link('TAGGED', question_1)
         question_1.index_under('questions', 'tag', 'avoid')

File graphalchemy/tests/test_node_models.py

-# -*- coding: utf-8 -*-
-'''graph manager unit tests'''
-
-import shutil
-try:
-    import unittest2 as unittest
-except ImportError:
-    import unittest
-
-
-class TestNodeInstance(unittest.TestCase):
-
-    def setUp(self):
-        from graphalchemy.graphs import Graph
-        self.graph = Graph('foo')
-        from graphalchemy.generics.elements import Node
-        self.graph.A.get(self.graph.S.model.finder.node)
-        self.node_class = Node
-        self.node = self.graph.session.nodes.root()
-
-    def test_general_instance(self):
-        self.assertIsInstance(self.node, self.node_class)
-        self.assertTrue(hasattr(self.node.n, 'anchor'))
-        self.assertTrue(hasattr(self.node.n, 'filter'))
-        self.assertTrue(hasattr(self.node.n, 'get'))
-        self.assertTrue(hasattr(self.node.n, 'ize'))
-        self.assertTrue(hasattr(self.node.n, 'reference'))
-        self.assertTrue(hasattr(self.node.n, 'root'))
-        self.assertTrue(hasattr(self.node.n, 'traverse'))
-        self.assertTrue(hasattr(self.node.n, 'traversed'))
-        self.assertTrue(hasattr(self.node.n, 'walk'))
-        self.assertTrue(hasattr(self.node.n, 'walked'))
-
-    def tearDown(self):
-        self.graph._db.shutdown()
-        shutil.rmtree('foo')
-
-
-class TestNodeClass(unittest.TestCase):
-
-    def setUp(self):
-        from graphalchemy.graphs import Graph
-        self.graph = Graph('foo')
-        from graphalchemy.generics.elements import Node
-        self.node = Node
-
-    def test_node(self):
-        self.assertTrue(hasattr(self.node, 'id'))
-        self.assertTrue(hasattr(self.node, 'l'))
-        self.assertTrue(hasattr(self.node, 'links'))
-        self.assertTrue(hasattr(self.node, 'n'))
-        self.assertTrue(hasattr(self.node, 'nodes'))
-        self.assertTrue(hasattr(self.node, 'delete'))
-        self.assertTrue(hasattr(self.node, 'update'))
-
-    def test_create_node_writer(self):
-        self.assertTrue(hasattr(self.node.nodes, 'build'))
-        self.assertTrue(hasattr(self.node.nodes, 'clone'))
-        self.assertTrue(hasattr(self.node.nodes, 'version'))
-        self.assertTrue(hasattr(self.node.nodes, 'revert'))
-        self.assertTrue(hasattr(self.node.nodes, 'wrap'))
-        self.assertTrue(hasattr(self.node.nodes, 'update'))
-        self.assertTrue(hasattr(self.node.nodes, 'index_one'))
-        self.assertTrue(hasattr(self.node.nodes, 'index_many'))
-        self.assertTrue(hasattr(self.node.nodes, 'delete_property'))
-        self.assertTrue(hasattr(self.node.nodes, 'delete_element'))
-        self.assertTrue(hasattr(self.node.nodes, 'autoslug'))
-        self.assertTrue(hasattr(self.node.n, 'build'))
-        self.assertTrue(hasattr(self.node.n, 'clone'))
-        self.assertTrue(hasattr(self.node.n, 'version'))
-        self.assertTrue(hasattr(self.node.n, 'revert'))
-        self.assertTrue(hasattr(self.node.n, 'wrap'))
-        self.assertTrue(hasattr(self.node.n, 'update'))
-        self.assertTrue(hasattr(self.node.n, 'index_one'))
-        self.assertTrue(hasattr(self.node.n, 'index_many'))
-        self.assertTrue(hasattr(self.node.n, 'delete_property'))
-        self.assertTrue(hasattr(self.node.n, 'delete_element'))
-        self.assertTrue(hasattr(self.node.n, 'autoslug'))
-
-    def test_create_link_writer(self):
-        self.assertTrue(hasattr(self.node.links, 'build'))
-        self.assertTrue(hasattr(self.node.links, 'create'))
-        self.assertTrue(hasattr(self.node.links, 'update'))
-        self.assertTrue(hasattr(self.node.links, 'index_one'))
-        self.assertTrue(hasattr(self.node.links, 'index_many'))
-        self.assertTrue(hasattr(self.node.links, 'delete_property'))
-        self.assertTrue(hasattr(self.node.links, 'delete_element'))
-        self.assertTrue(hasattr(self.node.links, 'autoslug'))
-        self.assertTrue(hasattr(self.node.l, 'build'))
-        self.assertTrue(hasattr(self.node.l, 'create'))
-        self.assertTrue(hasattr(self.node.l, 'update'))
-        self.assertTrue(hasattr(self.node.l, 'index_one'))
-        self.assertTrue(hasattr(self.node.l, 'index_many'))
-        self.assertTrue(hasattr(self.node.l, 'delete_property'))
-        self.assertTrue(hasattr(self.node.l, 'delete_element'))
-        self.assertTrue(hasattr(self.node.l, 'autoslug'))
-
-    def test_create_node_reader(self):
-        self.assertTrue(hasattr(self.node, 'nodes'))
-        self.assertTrue(hasattr(self.node.nodes, 'r'))
-        self.assertTrue(hasattr(self.node.nodes, 'anchor'))
-        self.assertTrue(hasattr(self.node.nodes, 'filter_by'))
-        self.assertTrue(hasattr(self.node.nodes, 'filter'))
-        self.assertTrue(hasattr(self.node.nodes, 'get'))
-        self.assertTrue(hasattr(self.node.nodes, 'ize'))
-        self.assertTrue(hasattr(self.node.nodes, 'reference'))
-        self.assertTrue(hasattr(self.node.nodes, 'root'))
-        self.assertTrue(hasattr(self.node.nodes, 'traverse'))
-        self.assertTrue(hasattr(self.node.nodes, 'traversed'))
-        self.assertTrue(hasattr(self.node.nodes, 'walk'))
-        self.assertTrue(hasattr(self.node.nodes, 'walked'))
-        self.assertTrue(hasattr(self.node.n, 'r'))
-        self.assertTrue(hasattr(self.node.n, 'anchor'))
-        self.assertTrue(hasattr(self.node.n, 'filter_by'))
-        self.assertTrue(hasattr(self.node.n, 'filter'))
-        self.assertTrue(hasattr(self.node.n, 'get'))
-        self.assertTrue(hasattr(self.node.n, 'ize'))
-        self.assertTrue(hasattr(self.node.n, 'reference'))
-        self.assertTrue(hasattr(self.node.n, 'root'))
-        self.assertTrue(hasattr(self.node.n, 'traverse'))
-        self.assertTrue(hasattr(self.node.n, 'traversed'))
-        self.assertTrue(hasattr(self.node.n, 'walk'))
-        self.assertTrue(hasattr(self.node.n, 'walked'))
-
-    def test_create_link_reader(self):
-        self.assertTrue(hasattr(self.node.links, 'filter_by'))
-        self.assertTrue(hasattr(self.node.links, 'filter'))
-        self.assertTrue(hasattr(self.node.links, 'get'))
-        self.assertTrue(hasattr(self.node.links, 'ize'))
-        self.assertTrue(hasattr(self.node.links, 'traverse'))
-        self.assertTrue(hasattr(self.node.links, 'traversed'))
-        self.assertTrue(hasattr(self.node.links, 'walk'))
-        self.assertTrue(hasattr(self.node.links, 'walked'))
-        self.assertTrue(hasattr(self.node.l, 'filter'))
-        self.assertTrue(hasattr(self.node.l, 'get'))
-        self.assertTrue(hasattr(self.node.l, 'ize'))
-        self.assertTrue(hasattr(self.node.l, 'traverse'))
-        self.assertTrue(hasattr(self.node.l, 'traversed'))
-        self.assertTrue(hasattr(self.node.l, 'walk'))
-        self.assertTrue(hasattr(self.node.l, 'walked'))
-
-    def tearDown(self):
-        self.graph._db.shutdown()
-        shutil.rmtree('foo')
-
-
-if __name__ == '__main__':
-    unittest.main()

File graphalchemy/wrappers.py

 subscribe = octopus.decorators.subscribe
 
 
-class Wrapper(octopus.processors.lifecycle):
+class Wrapper(octopus.flows.process):
 
     '''graph model wrapper'''
 

File graphalchemy/writers.py

 backends = conf.backends
 db = conf.key.db
 # decorators
+defer = octopus.decorators.defer
 direct = octopus.decorators.direct
 factory = octopus.decorators.factory
 service = octopus.decorators.service
         '''get transaction'''
         return self.w.transaction
 
-    def delete_element(self, this, indices=None):
+    @defer
+    def remove(self, this, indices=None):
         '''
         delete graph element
 
         '''
         self.w.delete_element(this, indices)
 
+    def index(self, index, fts=False):
+        '''
+        create link index
+
+        @param index: node index name
+        @param fts: create a full text index (default: False)
+        '''
+        self.w.create_index(index, fts)
+
     def index_many(self, index, this, indexed):
         '''
         index properties on a graph element