Commits

Lynn Rees  committed 4b3172d

- updates

  • Participants
  • Parent commits e426522

Comments (0)

Files changed (16)

File graphalchemy/finders.py

 __all__ = ('links', 'nodes')
 
 conf = octopus.S
-direct = getattr(octopus, 'direct')
+direct = getattr(octopus.decorators, 'direct')
 
 
 class Finder(octopus.things.context):

File graphalchemy/generics/collectors.py

 __all__ = ('Links', 'Nodes')
 
 conf = octopus.S
-direct = getattr(octopus, 'direct')
+direct = getattr(octopus.decorators, 'direct')
 
 
 class Links(LinksMixin):

File graphalchemy/generics/elements.py

 __all__ = ('Link', 'Node')
 
 conf = octopus.S
-direct = getattr(octopus, 'direct')
-defer = getattr(octopus, 'defer')
+direct = getattr(octopus.decorators, 'direct')
+defer = getattr(octopus.decorators, 'defer')
 
 
 class Generic(ElementMixin, octopus.things.manager):

File graphalchemy/graphs.py

 __all__ = ['Graph']
 
 conf = octopus.S
-factory = getattr(octopus, 'factory')
+factory = getattr(octopus.decorators, 'factory')
 
 
-class Session(octopus.locals.things):
+class Session(octopus.locals.thing):
 
     '''graph session'''
 
-    # link manager
-    links = factory(conf.manager.link, conf.appspace, 'M')
-    # node monager
-    nodes = factory(conf.manager.node, conf.appspace, 'M')
+    def __init__(self, manager, max_length):
+        '''
+        init
 
+        @param manager: graph manager
+        '''
+        super(Session, self).__init__(manager, max_length)
+        self.nodes = self.M.nodes
+        self.links = self.M.links
 
-class Graph(octopus.globals.things):
+    def __exit__(self, e, b, c):
+        with self.nodes.transaction:
+            self.commit()
+
+
+class Graph(octopus.globals.thing):
 
     '''graph interface'''
 
+    # session class
     _session_class = Session
+    # link manager
+    links = factory(conf.manager.link, conf.appspace)
+    # node monager
+    nodes = factory(conf.manager.node, conf.appspace)
 
     def __init__(self, url, **kw):
         '''
     @property
     def session(self):
         '''session manager'''
-        with self.nodes.transaction:
-            return super(Graph, self).session
+        return self._session_class(self, self.max_length)
 
     def close(self):
         '''run abort callbacks'''

File graphalchemy/managers.py

 reader = conf.reader
 wrapper = conf.wrapper
 writer = conf.writer
-direct = getattr(octopus, 'direct')
-factory = getattr(octopus, 'factory')
-forward = getattr(octopus, 'forward')
+direct = getattr(octopus.decorators, 'direct')
+factory = getattr(octopus.decorators, 'factory')
+forward = getattr(octopus.decorators, 'forward')
 
 
 class Manager(octopus.things.client):

File graphalchemy/mixins/collectors.py

 conf = octopus.S
 appspace = conf.appspace
 finder = conf.model.finder
-direct = getattr(octopus, 'direct')
+direct = getattr(octopus.decorators, 'direct')
 
 
 class CollectorsMixin(octopus.locals.context):

File graphalchemy/mixins/elements.py

 __all__ = ('LinksMixin', 'NodesMixin')
 
 conf = getattr(octopus, 'S')
-defer = getattr(octopus, 'defer')
+defer = getattr(octopus.decorators, 'defer')
+direct = getattr(octopus.decorators, 'direct')
 
 
 class ElementMixin(object):
     '''graph element'''
 
     # graph connector
-    _g = getattr(octopus, 'direct')(conf.manager.graph, conf.appspace)
+    _g = direct(conf.manager.graph, conf.appspace)
 
     def __init__(self, element=None, **kw):
         '''

File graphalchemy/models/collectors.py

 __all__ = ('In', 'Nodes', 'Out')
 
 conf = octopus.S
-direct = getattr(octopus, 'direct')
+direct = getattr(octopus.decorators, 'direct')
 
 
 class Nodes(NodesMixin):
             )
 
 
-class Direction(octopus.locals.context):
+class Direction(octopus.things.context):
 
     '''direction definition'''
 

File graphalchemy/models/elements.py

 __all__ = ['Node']
 
 conf = octopus.S
-class_defer = getattr(octopus, 'class_defer')
-defer = getattr(octopus, 'defer')
-direct = getattr(octopus, 'direct')
+class_defer = getattr(octopus.decorators, 'class_defer')
+defer = getattr(octopus.decorators, 'defer')
+direct = getattr(octopus.decorators, 'direct')
 
 
 class Node(NodeMixin, ElementMixin, octopus.things.thing):

File graphalchemy/readers.py

 # settings
 conf = octopus.S
 # decorators
-direct = getattr(octopus, 'direct')
-factory = getattr(octopus, 'factory')
-service = getattr(octopus, 'service')
+direct = getattr(octopus.decorators, 'direct')
+factory = getattr(octopus.decorators, 'factory')
+service = getattr(octopus.decorators, 'service')
 
 
 class Reader(octopus.things.server):

File graphalchemy/tests/test_graph.py

 
     def test_create(self):
         self.assertTrue(hasattr(self.graph, '_db'))
-        self.assertTrue(hasattr(self.graph, 'nodes'))
-        self.assertTrue(hasattr(self.graph, 'links'))
+        self.assertTrue(hasattr(self.graph.session, 'nodes'))
+        self.assertTrue(hasattr(self.graph.session, 'links'))
 
     def tearDown(self):
         try:

File graphalchemy/tests/test_managers.py

         self.graph = Graph('foo')
 
     def test_create_node_writer(self):
-        self.assertTrue(hasattr(self.graph.nodes, '_reader'))
-        self.assertTrue(hasattr(self.graph.nodes, 'clone'))
-        self.assertTrue(hasattr(self.graph.nodes, 'build'))
-        self.assertTrue(hasattr(self.graph.nodes, 'version'))
-        self.assertTrue(hasattr(self.graph.nodes, 'revert'))
-        self.assertTrue(hasattr(self.graph.nodes, 'wrap'))
-        self.assertTrue(hasattr(self.graph.nodes, 'update'))
-        self.assertTrue(hasattr(self.graph.nodes, 'index_one'))
-        self.assertTrue(hasattr(self.graph.nodes, 'index_many'))
-        self.assertTrue(hasattr(self.graph.nodes, 'delete_property'))
-        self.assertTrue(hasattr(self.graph.nodes, 'delete_element'))
-        self.assertTrue(hasattr(self.graph.nodes, 'autoslug'))
+        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, '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_element'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'autoslug'))
 
     def test_create_link_writer(self):
-        self.assertTrue(hasattr(self.graph.links, '_writer'))
-        self.assertTrue(hasattr(self.graph.links, 'build'))
-        self.assertTrue(hasattr(self.graph.links, 'create'))
-        self.assertTrue(hasattr(self.graph.links, 'update'))
-        self.assertTrue(hasattr(self.graph.links, 'index_one'))
-        self.assertTrue(hasattr(self.graph.links, 'index_many'))
-        self.assertTrue(hasattr(self.graph.links, 'delete_property'))
-        self.assertTrue(hasattr(self.graph.links, 'delete_element'))
-        self.assertTrue(hasattr(self.graph.links, 'autoslug'))
+        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_element'))
+        self.assertTrue(hasattr(self.graph.session.links, 'autoslug'))
 
     def test_create_node_reader(self):
-        self.assertTrue(hasattr(self.graph.nodes, '_reader'))
-        self.assertTrue(hasattr(self.graph.nodes, 'root'))
-        self.assertTrue(hasattr(self.graph.nodes, 'anchor'))
-        self.assertTrue(hasattr(self.graph.nodes, 'filter_by'))
-        self.assertTrue(hasattr(self.graph.nodes, 'filter'))
-        self.assertTrue(hasattr(self.graph.nodes, 'get'))
-        self.assertTrue(hasattr(self.graph.nodes, 'reference'))
-        self.assertTrue(hasattr(self.graph.nodes, 'root'))
-        self.assertTrue(hasattr(self.graph.nodes, 'traverse'))
-        self.assertTrue(hasattr(self.graph.nodes, 'traversed'))
-        self.assertTrue(hasattr(self.graph.nodes, 'walk'))
-        self.assertTrue(hasattr(self.graph.nodes, 'walked'))
-        self.assertTrue(hasattr(self.graph.nodes, 'r'))
+        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, 'get'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'reference'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'root'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'traverse'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'traversed'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'walk'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'walked'))
+        self.assertTrue(hasattr(self.graph.session.nodes, 'r'))
 
     def test_create_link_reader(self):
-        self.assertTrue(hasattr(self.graph.nodes, '_writer'))
-        self.assertTrue(hasattr(self.graph.links, 'filter_by'))
-        self.assertTrue(hasattr(self.graph.links, 'filter'))
-        self.assertTrue(hasattr(self.graph.links, 'get'))
-        self.assertTrue(hasattr(self.graph.links, 'traverse'))
-        self.assertTrue(hasattr(self.graph.links, 'traversed'))
-        self.assertTrue(hasattr(self.graph.links, 'walk'))
-        self.assertTrue(hasattr(self.graph.links, 'walked'))
-        self.assertTrue(hasattr(self.graph.links, 'r'))
+        self.assertTrue(hasattr(self.graph.session.links, '_writer'))
+        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, 'traverse'))
+        self.assertTrue(hasattr(self.graph.session.links, 'traversed'))
+        self.assertTrue(hasattr(self.graph.session.links, 'walk'))
+        self.assertTrue(hasattr(self.graph.session.links, 'walked'))
+        self.assertTrue(hasattr(self.graph.session.links, 'r'))
 
     def tearDown(self):
         self.graph._db.shutdown()

File graphalchemy/tests/test_models.py

     graph.register(Con)
     graph.register(Idea)
     graph.on('abort', cleanup)
-    with graph.session as session:
-        graph.nodes.w.create_index('roots')
-        session.join(Question)
-        Question.referrer(user=1)
-        session.join(Idea)
-        Idea.referrer(user=1)
-        session.join(Pro)
-        Pro.referrer(user=1)
-        session.join(Con)
-        Con.referrer(user=1)
-        session.join(Tag)
-        Tag.referrer(user=1)
-        tag_1 = Tag.nodes.create(_status=1, text='wicked problem', user=1)
+    with graph.session as Session:
+        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)
+        tag_1 = Tag(_status=1, text='wicked problem', user=1)
+        Session.add(tag_1)
         tag_1.index_under('tags', 'name', 'wicked problem')
-        tag_2 = Tag.nodes.create(text='avoid', user=1, _status=1)
+        tag_2 = Tag(text='avoid', user=1, _status=1)
+        Session.add(tag_2)
         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_1 = Question(
             _status=1,
             down=0,
             up=0,
             user=1,
         )
+        Session.add(question_1)
         question_1.weigh_anchor(user=1)
         question_1.index_under('questions', 'tag', 'wicked problem')
         tag_1.link('TAGGED', question_1)
             up=0,
             user=1,
         )
-        question_1.questions.add(question_2, user=1)
-        idea_2 = question_2.ideas.create(
+        Session.add(question_2)
+        question_1.questions.link(question_2, user=1)
+        idea_2 = Question(
             _status=1,
             down=0,
             text="You are confused",
             user=1,
             link_props=dict(user=1),
         )
-        pro_1 = idea_2.pros.create(
+        Session.add(idea_2)
+        question_2.ideas.link(idea_2)
+        pro_1 = Pro(
             _status=1,
             down=0,
             text="I'd certainly feel confused",
             user=1,
             link_props=dict(user=1),
         )
+        Session.add(pro_1)
+        idea_2.pros.link(pro_1)
         pro_1.up = 6
         pro_1.text = "I'd certainly really feel confused"
         pro_1.user = 2
-        con_1 = idea_2.cons.create(
+        con_1 = Idea(
             _status=1,
             down=0,
             text="I don't feel confused",
             user=1,
             link_props=dict(user=1),
         )
-        idea_3 = question_2.ideas.create(
+        Session.add(con_1)
+        idea_2.cons.link(con_1)
+        idea_3 = Idea(
             _status=1,
             down=0,
             text="You are flummoxed",
             user=1,
             link_props=dict(user=1),
         )
-        question_3 = idea_3.questions.create(
+        Session.add(idea_3)
+        question_2.ideas.link(idea_3)
+        question_3 = Question(
             _status=1,
             down=0,
             text="Isn't that the same as confusion?",
             user=1,
             link_props=dict(user=1),
         )
-        idea_4 = question_3.ideas.create(
+        Session.add(question_3)
+        idea_3.questions.link(question_3)
+        idea_4 = Question(
             _status=1,
             down=0,
             text="No",
             user=1,
             link_props=dict(user=1),
         )
+        Session.add(idea_4)
+        question_3.ideas.link(idea_4)
         idea_4.text = 'No, Really'
-        idea_5 = question_3.ideas.create(
+        idea_5 = Question(
             _status=1,
             down=0,
             text='Yes, but faster!',
             user=1,
             link_props=dict(user=1),
         )
-        con_3 = idea_5.cons.create(
+        Session.add(idea_5)
+        question_3.ideas.link(idea_5)
+        con_3 = Idea(
             _status=1,
             down=0,
             text="Spans both positions",
             user=1,
             link_props=dict(user=1),
         )
+        Session.add(con_3)
+        idea_5.cons.link(con_3)
         con_3.user = 2
-        idea_6 = question_2.ideas.create(
+        idea_6 = Question(
             _status=1,
             down=0,
             text="You are surrounded by hellfire",
             user=1,
             link_props=dict(user=1),
         )
-        question_4 = idea_6.questions.create(
+        Session.add(idea_6)
+        question_2.ideas.link(idea_6)
+        question_4 = Idea(
             _status=1,
             down=0,
             text="Is there no appeal from hellfire?",
             user=1,
             link_props=dict(user=1),
         )
-        idea_7 = question_4.ideas.create(
+        Session.add(question_4)
+        idea_6.questions.link(question_4)
+        idea_7 = Question(
             _status=1,
             down=0,
             text="You better hope there's an appeal",
             user=1,
             link_props=dict(user=1),
         )
-        idea_1 = question_1.ideas.create(
+        Session.add(idea_7)
+        question_4.ideas.link(idea_7)
+        idea_1 = Idea(
             _status=1,
             down=0,
             text='DUCK!',
             user=1,
             link_props=dict(user=1),
         )
-        question_5 = idea_7.questions.create(
+        Session.add(idea_1)
+        question_1.ideas.link(idea_1)
+        question_5 = Question(
             _status=1,
             down=0,
             text="Isn't that a simple problem?",
             user=1,
             link_props=dict(user=1),
         )
+        Session.add(question_5)
+        idea_7.questions.link(question_5)
         question_5.up = 15
-        pro_2 = idea_1.pros.create(
+        pro_2 = Pro(
             _status=1,
             down=0,
             text="It's simple",
             user=1,
             link_props=dict(user=1),
         )
+        Session.add(pro_2)
+        idea_1.pros.link(pro_2)
         pro_4 = pro_2.fork()
+        Session.add(pro_4)
         pro_2.user = pro_4.user
-        pro_3 = idea_1.pros.create(
+        pro_3 = Pro(
             _status=1,
             down=0,
             text='It avoids wicked problems shaped like projectiles',
             user=1,
             link_props=dict(user=1),
         )
+        Session.add(pro_3)
+        idea_1.pros.link(pro_3)
         pro_3.down = 1
-        con_4 = idea_1.cons.create(
+        con_4 = Con(
             _status=1,
             down=0,
             text="It may not actually avoid the problem",
             user=1,
             link_props=dict(user=1),
         )
+        Session.add(con_4)
+        idea_1.cons.link(con_4)
         con_4.up = 1
-        con_5 = idea_1.cons.create(
+        con_5 = Con(
             _status=1,
             _versions=0,
             down=0,
             user=1,
             link_props=dict(user=1),
         )
+        Session.add(con_5)
+        idea_1.cons.link(con_5)
         con_5.text = 'Harder to do while asleep with your eyes closed'
         con_5.text = 'Much harder to do while asleep with your eyes closed'
-        pro_9 = idea_1.pros.create(
+        pro_9 = Pro(
             _status=1,
             down=0,
             text='It avoids wicked problems shaped like projectiles',
             user=1,
             link_props=dict(user=1),
         )
-        pro_9.delete()
+        Session.add(pro_9)
+        idea_1.pros.link(pro_9)
+        Session.delete(pro_9)
 
     try:
         # questions

File graphalchemy/tests/test_node_models.py

         from graphalchemy.generics.elements import Node
         self.graph.A.get(self.graph.S.model.finder.node)
         self.node_class = Node
-        self.node = self.graph.nodes.root()
+        self.node = self.graph.session.nodes.root()
 
     def test_general_instance(self):
         self.assertIsInstance(self.node, self.node_class)

File graphalchemy/wrappers.py

 
 conf = octopus.S
 appspace = conf.appspace
-direct = getattr(octopus, 'direct')
+direct = getattr(octopus.decorators, 'direct')
 finder = conf.model.finder
-forward = getattr(octopus, 'forward')
+forward = getattr(octopus.decorators, 'forward')
 reader = conf.reader
 writer = conf.writer
 

File graphalchemy/writers.py

 backends = conf.backends
 db = conf.key.db
 # decorators
-direct = getattr(octopus, 'direct')
-factory = getattr(octopus, 'factory')
-service = getattr(octopus, 'service')
+direct = getattr(octopus.decorators, 'direct')
+factory = getattr(octopus.decorators, 'factory')
+service = getattr(octopus.decorators, 'service')
 
 
 class Writer(octopus.things.server):