1. Lynn Rees
  2. graphalchemy

Commits

Lynn Rees  committed 4b8c4bb

- update

  • Participants
  • Parent commits 3e02012
  • Branches pu

Comments (0)

Files changed (5)

File graphalchemy/graphs.py

View file
 # -*- coding: utf-8 -*-
 '''graph interface'''
 
-from stuf.utils import clsname, selfname
+from stuf.utils import clsname
 
 from graphalchemy.core import octopus
 
 # settings
 conf = octopus.S
 # decorators
-factory = octopus.decorators.factory
+subscribe = octopus.decorators.subscribe
 
 
 class Session(octopus.locals.protocol):
 
     '''graph session'''
 
+    # link manager
+    links = subscribe(conf.manager.link, conf.appspace)
+    # node monager
+    nodes = subscribe(conf.manager.node, conf.appspace)
+
     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
+        # pipe for abort
+        self.pipe('abort', self.nodes.close)
 
     def __exit__(self, e, b, c):
         with self.nodes.transaction:
             self.commit()
 
+    def close(self):
+        '''run abort callbacks'''
+        self.nodes.close()
+
 
 class Graph(octopus.globals.protocol):
 
     '''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):
         '''
         @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', defaults.backend)
+        database = kw.pop('database', self.defaults.backend)
         # freeze settings
-        self.freeze({
-            # store graph manager name
-            'manager.graph': graph_manager,
-            # store userspace name
-            'userspace': userspace,
+        self.freeze(
             # 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 = 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)
-        # pipe for abort
-        self.pipe('abort', self.close)
+        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)
 
     def __repr__(self):
         return '{name}@{url}'.format(
             name=clsname(self._db).split('.')[-1], url=self.url,
         )
-
-    @property
-    def session(self):
-        '''session manager'''
-        return self._session_class(self, self.max_length)
-
-    def close(self):
-        '''run abort callbacks'''
-        self.nodes.w.close()
-
-    def register(self, model):
-        '''
-        add model class to appspace
-
-        @param model: graph element model
-        '''
-        self.Q.set(model, selfname(model), conf.userspace)

File graphalchemy/managers.py

View file
 subscribe = octopus.decorators.subscribe
 
 
-class Manager(octopus.things.sub):
+class Manager(octopus.processors.lifecycle):
 
     '''graph element manager base'''
 

File graphalchemy/readers.py

View file
         full text search using index
 
         @param index: name of index
-        @param queries: queries build with query builder
+        @param queries: queries built with query builder
         @param model: element model (default: None)
         '''
         if model is None:
             if anchor:
                 self.Q.set(anchor, anchor_link, userspace)
                 return anchor
+            
+    def close(self):
+        '''close database'''
+        self.r.close()
 
     @service('model')
     def reference(self, model=None):

File graphalchemy/wrappers.py

View file
 subscribe = octopus.decorators.subscribe
 
 
-class Wrapper(octopus.things.sub):
+class Wrapper(octopus.processors.lifecycle):
 
     '''graph model wrapper'''
 

File graphalchemy/writers.py

View file
         if model is None:
             model = self._finder(model)
         instance = model(**kw)
-        instance.save()
+        self.local.add(instance)
         return instance
 
     @staticmethod