Commits

Lynn Rees committed 06f31a0

- fixes

  • Participants
  • Parent commits 2403404

Comments (0)

Files changed (9)

File graphalchemy/__init__.py

 
 from inspect import ismodule
 
-from appspace.six import iteritems
+from stuf.six import iteritems
 
 __version__ = (0, 1, 0)
 

File graphalchemy/backends/neo4jem.py

 
 from inspect import ismodule
 
+from stuf.six import iteritems
 from lucenequerybuilder import Q
 from stuf.utils import getdefault
-from appspace.six import iteritems
 
 from graphalchemy.backends.utils import Backend, BackendRead
 

File graphalchemy/direct/elements.py

 '''direct element models'''
 
 from stuf.utils import lazy
+
 from graphalchemy.core import octopus, app
 from graphalchemy.mixins.elements import NodeMixin, ElementMixin
 
-
 __all__ = ('Link', 'Node')
 # settings
 conf = octopus.G
 
     '''graph object'''
 
-    # direct links collection
-    _links = app(conf.direct.collector.link, conf.directs)
-
     @staticmethod
     def _link():
         '''link class'''
         return '{0}: {1}'.format(self.kind, super(Link, self).__repr__())
 
     @lazy
-    def _p(self):
-        return self.session.links
-
-    @lazy
     def end(self):
         '''ending node of link'''
         return self.that if self.direction == 'incoming' else self.this
     @lazy
     def kind(self):
         '''kind of link'''
-        return self._r.kind(self.source)
+        return self._lr.kind(self.source)
 
     @lazy
     def start(self):

File graphalchemy/direct/workers.py

 # -*- coding: utf-8 -*-
 '''graph direct workers'''
 
-from appspace import AppLookupError
-
 from graphalchemy.core import octopus, app, factory, defer
 from graphalchemy.mixins.workers import WriterMixin, ReaderMixin
 
         return thing
 
     ###########################################################################
-    ## link read methods ######################################################
+    ## node read methods ######################################################
     ###########################################################################
 
-    def root(self):
-        '''reference root for graph'''
-        try:
-            G = self.G
-            return self.Q.app(G.root, G.userspace)
-        except AppLookupError:
-            root = self._r.root
-            root = self._model(root)
-            self.Q.register(root, G.root, G.userspace)
-            return root
-
     def walk(self, this, direction=None, label=None, keys=None, end='end'):
         '''
         iterate links and yield node from link

File graphalchemy/mixins/elements.py

 
 from stuf.utils import both, getcls, lazy, clsname
 
+from graphalchemy.core import octopus, factory, app
+
 __all__ = ('ElementMixin', 'NodesMixin')
+# settings
+conf = octopus.G
+backends = conf.backends
+db = conf.key.db
 
 
 class ElementMixin(object):
 
     '''graph element'''
 
+    # graph source
+    _db = app(conf.key.backend, conf.userspace)
+    # node reader
+    _lr = _r = factory(conf.read.link, backends, db)
+    # node writer
+    _lw = _w = factory(conf.write.link, backends, db)
+    # links collection
+    _links = app(conf.direct.collector.link, conf.directs)
+
     def __init__(self, element=None, **kw):
         '''
         init
         self.direction = kw.pop('direction', 'outgoing')
         super(ElementMixin, self).__init__(element, **kw)
 
+    def __repr__(self):
+        return '{0}: {1}'.format(
+            clsname(self), super(ElementMixin, self).__repr__(),
+        )
+
     @lazy
     def id(self):
         '''graph element id'''
-        return self._p.id(self.source)
+        return self._r.id(self.source)
 
     @both
     def links(self):
         '''sequence of all links'''
         return self._links(self, getcls(self))
 
-    def _source(self, this):
+    def _source(self, element):
         '''
         synchronized data structure
 
-        @param this: this element
+        @param element: this element
         '''
-        return self._p.properties(this)
+        return self._r.properties(element)
 
     def _refresh(self):
         '''refresh original'''
-        super(ElementMixin, self).sync()
         # reset links collector
         self.links.reset()
 
         @param index: graph index label (default: None)
         @param *indexed: properties to index
         '''
-        self._p.index_many(index, self, indexed)
+        self._r.index_many(index, self, indexed)
 
     def index_under(self, index, key, value):
         '''
         @param key: graph element property key
         @param value: graph element property value
         '''
-        self._p.index_one(index, key, value, self)
+        self._r.index_one(index, key, value, self)
 
 
 class NodeMixin(object):
 
     '''node element'''
 
-    def __repr__(self):
-        return '{0}: {1}'.format(
-            clsname(self), super(NodeMixin, self).__repr__(),
-        )
-
-    @lazy
-    def _p(self):
-        return self.session.nodes
+    # node reader
+    _nr = _r = factory(conf.read.node, backends, db)
+    # node writer
+    _nw = _w = factory(conf.write.node, backends, db)
 
     @lazy
     def nodes(self):
         @param node: the other node
         @param **kw: link properties
         '''
-        self.session.links.create(link, self, node, kw)
+        self._lw.create(link, self, node, kw)

File graphalchemy/models/elements.py

 __all__ = ['Node']
 # settings
 conf = octopus.G
-backends = conf.backends
-db = conf.key.db
 
 
 class Node(NodeMixin, ElementMixin, octopus.workflow.Thing):
 
     '''node model'''
 
-    # links collection
-    _links = app(conf.direct.collector.link, conf.directs)
     # node collection
     _nodes = app(conf.model.collector.node, conf.models)
 
         metas['fts_indexed'] = set(k for k in class_names(full_text=True))
         # properties to HTML escape
         metas['escaped'] = set(k for k in class_names(escaped=True))
-        existing = self.M.localize(self)
-        existing.update(metas)
-        return existing
+        return self.M.localize(self, metas)
 
     def _version(self):
         '''increment current snapshot number of node'''
 
     def anchor(self, anchor, **kw):
         '''link node to anchor'''
-        self.session.links.create(self.L.anchor_link, self, anchor, kw)
+        self._lw.create(self.L.anchor_link, self, anchor, kw)
 
     class Meta:
         # anchor link label

File graphalchemy/models/finders.py

 '''graph model finder'''
 
 from appspace import NoAppError
-from appspace.six import string_types
+from stuf.six import string_types
 
 from graphalchemy.core import octopus, app
 

File graphalchemy/models/workers.py

 
 from markupsafe import escape
 from stuf.utils import getcls
+from appspace import AppLookupError
 
 from graphalchemy.mixins.workers import WriterMixin
 from graphalchemy.core import octopus, app, factory, defer
     _db = app(conf.key.backend, conf.userspace)
     # model finder
     _finder = app(conf.model.finder.node, conf.models)
+    # direct model
+    _model = app(conf.direct.element.node, conf.directs)
     # model query
     _query = app(conf.model.reader.node, conf.models)
     # model user
     # raw
     raw = factory(conf.raw, conf.appspace, conf.key.session)
 
-    def _prepare(self, thing):
+    def _prepare(self, element):
         # snapshot if flag set
-        if thing.L.versioned:
-            self.using(getcls(thing)).snapshot(thing)
-        super(Nodes, self)._prepare(thing)
+        if element.L.versioned:
+            self.using(getcls(element)).snapshot(element)
+        super(Nodes, self)._prepare(element)
 
-    def _preprocess(self, thing, model):
+    def _preprocess(self, element, model):
         '''
         pre-process graph element
 
-        @param thing: graph object
+        @param element: graph object
         '''
         esc = escape
         for k in model.L.escaped:
-            thing[k] = esc(thing[k])
-        thing['_modified'] = self.now()
+            element[k] = esc(element[k])
+        element['_modified'] = self.now()
         # slug field
-        self._autoslug(thing, model)
+        self._autoslug(element, model)
 
     def _autoslug(self, properties, model):
         '''
         # add slug
         properties[slug_field] = tmpslug
 
-    def _postprocess(self, thing, model):
+    def _postprocess(self, element, model):
         '''
         postprocess graph node
 
-        @param thing: graph object
+        @param element: graph object
         '''
-        thing = model(thing)
+        element = model(element)
         L = model.L
         index = L.index
         index_one = self.index_one
         # index created date
         if index:
-            index_one(index, 'created', self.now(), thing)
+            index_one(index, 'created', self.now(), element)
         # index any listed properties
         if L.indexed:
-            self.index_many(index, thing, L.indexed)
+            self.index_many(index, element, L.indexed)
         # add a slug if present
         slug_from = L.slug_from
         if slug_from:
-            index_one(index, slug_from, getattr(thing, slug_from), thing)
+            index_one(index, slug_from, getattr(element, slug_from), element)
         # index properties that support full text search
         if L.fts_indexed:
-            self.index_many(L.fts_index, thing, L.fts_indexed)
-        return thing
+            self.index_many(L.fts_index, element, L.fts_indexed)
+        return element
 
     @defer
-    def _create(self, thing):
+    def _create(self, element):
         '''
         create a new graph node
 
         @param data: data
         '''
-        model = getcls(thing)
+        model = getcls(element)
         L = model.L
-        data = thing.final
+        data = element.final
         data.update(_created=self.now(), _model=L.name, _uuid=self.Q.uuid())
         # number of versions to maintain
         if L.versioned:
             data['_versions'] = 0
         self._preprocess(data, model)
-        thing = self._w.create(
+        element = self._w.create(
             data,
             L.reference_link,
             self.query(model).reference(),
             partial(self._postprocess, model=model),
         )
-        thing._refresh()
+        element._refresh()
 
     @defer
-    def _update(self, thing):
+    def _update(self, element):
         '''
         update a graph element's properties
 
-        @param thing: graph object
+        @param element: graph object
         '''
-        model = getcls(thing)
+        model = getcls(element)
         data = self.final
         self._preprocess(data)
-        self._w.update(thing, data, partial(self._postprocess, model=model))
-        thing._refresh()
+        self._w.update(element, data, partial(self._postprocess, model=model))
+        element._refresh()
 
     def query(self, model):
         '''
         '''
         return self._query(model)
 
-    def remove(self, thing):
-        self._w.delete(thing)
-        del thing
+    def remove(self, element):
+        '''
+        delete a graph element
+
+        @param model: graph model
+        '''
+        self._w.delete(element)
+        del element
+
+    def root(self):
+        '''reference root for graph'''
+        try:
+            G = self.G
+            return self.Q.app(G.root, G.userspace)
+        except AppLookupError:
+            root = self._r.root
+            root = self._model(root)
+            self.Q.add(root, G.root, G.userspace)
+            return root
 
     def using(self, model):
         '''

File graphalchemy/tests/test_managers.py

     def test_create_node_writer(self):
 #        self.assertTrue(hasattr(self.graph.session.nodes, '_reader'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'clone'))
-        self.assertTrue(hasattr(self.graph.session.nodes, 'build'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'create'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'version'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'revert'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'wrap'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'update'))
         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_property'))
         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, '_writer'))
-        self.assertTrue(hasattr(self.graph.session.links, 'build'))
         self.assertTrue(hasattr(self.graph.session.links, 'create'))
         self.assertTrue(hasattr(self.graph.session.links, 'update'))
         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_property'))
         self.assertTrue(hasattr(self.graph.session.links, 'delete'))
 
     def test_create_node_reader(self):
-#        self.assertTrue(hasattr(self.graph.session.nodes, '_reader'))
-        self.assertTrue(hasattr(self.graph.session.nodes, 'root'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'anchor'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'filter_by'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'filter'))
         self.assertTrue(hasattr(self.graph.session.nodes, 'walk'))
 
     def test_create_link_reader(self):
-#        self.assertTrue(hasattr(self.graph.session.links, '_writer'))
+        self.assertTrue(hasattr(self.graph.session.links, 'filter'))
         self.assertTrue(hasattr(self.graph.session.links, 'filter_by'))
-        self.assertTrue(hasattr(self.graph.session.links, 'filter'))
         self.assertTrue(hasattr(self.graph.session.links, 'get'))
+        self.assertTrue(hasattr(self.graph.session.links, 'kind'))
         self.assertTrue(hasattr(self.graph.session.links, 'traverse'))
         self.assertTrue(hasattr(self.graph.session.links, 'walk'))