Commits

Lynn Rees committed 5541296

- settings

  • Participants
  • Parent commits 73d895e

Comments (0)

Files changed (10)

File graphalchemy/direct/elements.py

     @lazy
     def kind(self):
         '''kind of link'''
-        return self.r.kind(self.source)
+        return self._r.kind(self.source)
 
     @lazy
     def start(self):

File graphalchemy/direct/workers.py

         @param this: graph object
         @param indicies: graph indices (default: None)
         '''
-        self.w.delete(this, indices)
+        self._w.delete(this, indices)
 
     @defer
     def update(self, this, **data):
         @param this: graph object
         @param **data: data
         '''
-        self.w.update(this, data)
+        self._w.update(this, data)
         this._refresh()
         return this
 
         @param index: name of index
         @param queries: queries built with query builder
         '''
-        return self.r.filter(index, queries, self._model)
+        return self._r.filter(index, queries, self._model)
 
     def filter_by(self, index, key, value):
         '''
         @param key: keyword in index
         @param value: value in index (or second key)
         '''
-        return self.r.filter_by(index, key, value, self._model)
+        return self._r.filter_by(index, key, value, self._model)
 
     def get(self, element):
         '''
 
         @param element: element id
         '''
-        return self._model(self.r.get(element))
+        return self._model(self._r.get(element))
 
     def traverse(self, this, tester=None, links=None, unique=None):
         '''
         @param unique: how often to traverse the same element (default: None)
         '''
         model = self._model
-        for element in self.r.traverser(this, tester, links, unique):
+        for element in self._r.traverser(this, tester, links, unique):
             yield model(element)
 
 
     _db = app(conf.key.backend, conf.userspace)
     _model = app(conf.direct.element.link, conf.managers)
     # direct link reader
-    r = factory(conf.read.link, backends, db)
+    _r = factory(conf.read.link, backends, db)
     # direct link writer
-    w = factory(conf.write.link, backends, db)
+    _w = factory(conf.write.link, backends, db)
 
     ###########################################################################
     ## link write methods #####################################################
         @param **data: data
         '''
         data.update(_created=self.now(), _uuid=self.Q.uuid())
-        thing = self.w.create(link, start, end, data)
+        thing = self._w.create(link, start, end, data)
         thing._refresh()
         return thing
 
 
         @param element: graph element
         '''
-        return self.r.kind(element)
+        return self._r.kind(element)
 
     def walk(self, this, direction=None, label=None, keys=None):
         '''
         @param keys: keys to find on elements (default: None)
         '''
         model = self._model
-        for element in self.r.walker(this, direction, label, keys):
+        for element in self._r.walker(this, direction, label, keys):
             yield model(element)
 
 
 
     _model = app(conf.direct.element.node, conf.managers)
     # direct node reader
-    r = factory(conf.read.node, backends, db)
+    _r = factory(conf.read.node, backends, db)
     # direct node writer
-    w = factory(conf.write.node, backends, db)
+    _w = factory(conf.write.node, backends, db)
 
     ###########################################################################
     ## node write methods #####################################################
         @param **data: data
         '''
         data.update(_created=self.now(), _uuid=self.Q.uuid())
-        thing = self.w.create(data)
+        thing = self._w.create(data)
         thing._refresh()
         return thing
 
     def root(self):
         '''reference root for graph'''
         try:
-            S = self.S
-            return self.Q.app(S.root, S.userspace)
+            G = self.G
+            return self.Q.app(G.root, G.userspace)
         except AppLookupError:
-            root = self.r.root
+            root = self._r.root
             root = self._model(root)
-            self.Q.register(root, S.root, S.userspace)
+            self.Q.register(root, G.root, G.userspace)
             return root
 
     def walk(self, this, direction=None, label=None, keys=None, end='end'):
         @param end: which end of link to return (default: 'end')
         '''
         model = self._model
-        for element in self.r.walker(this, direction, label, keys, end):
+        for element in self._r.walker(this, direction, label, keys, end):
             yield model(element)

File graphalchemy/mixins/elements.py

 
         @param this: this element
         '''
-        return self.r.properties(this)
+        return self._r.properties(this)
 
     def _refresh(self):
         '''refresh original'''

File graphalchemy/mixins/workers.py

 
         @param element: a graph element
         '''
-        return self.r.id(element)
+        return self._r.id(element)
 
     def properties(self, element):
         '''
 
         @param element: element with properties
         '''
-        return self.r.properties(element)
+        return self._r.properties(element)
 
 
 class WriterMixin(object):
         @param index: node index name
         @param fts: create a full text index (default: False)
         '''
-        self.w.create_index(index, fts)
+        self._w.create_index(index, fts)
 
     @defer
     def index_many(self, index, this, indexed):
         @param this: graph object
         @param indexed: properties to index
         '''
-        self.w.index_many(self.r.index(index), this, indexed)
+        self._w.index_many(self._r.index(index), this, indexed)
 
     @defer
     def index_one(self, index, key, value, this):
         @param value: graph element property value
         @param this: graph object
         '''
-        self.w.index_one(self.r.index(index), key, value, this)
+        self._w.index_one(self._r.index(index), key, value, this)
 
     @staticmethod
     def now():

File graphalchemy/models/collections.py

         else:
             raise UnrelatedLinkError(
                 '{inst} instance is unrelated to {model}'.format(
-                    inst=node.C.name, model=self._model.C.name,
+                    inst=node.L.name, model=self._model.L.name,
                 )
             )

File graphalchemy/models/elements.py

     _nodes = app(conf.model.collector.node, conf.models)
 
     @lazy_class
-    def C(self):
+    def L(self):
         '''local settings'''
         metas = dict()
         # model name
 
     def anchor(self, anchor, **kw):
         '''link node to anchor'''
-        self.session.links.create(self.C.anchor_link, self, anchor, kw)
+        self.session.links.create(self.L.anchor_link, self, anchor, kw)
 
     class Meta:
         # anchor link label

File graphalchemy/models/finders.py

         '''
         if element is not None:
             try:
-                return self.Q.app(element['_model'], self.S.userspace)
+                return self.Q.app(element['_model'], self.G.userspace)
             except (NoAppError, KeyError):
                 pass
         elif isinstance(model, string_types):
-            return self.Q.app(model, self.S.userspace)
-        return model if model else self.manager
+            return self.Q.app(model, self.G.userspace)
+        return model if model else self.model
 
 
 class Links(Finder):
 
     '''link model finder'''
 
-    # manager link model
-    manager = app(conf.manager.element.link, conf.managers)
+    # direct link model
+    model = app(conf.direct.element.link, conf.managers)
 
 
 links = Links()
 
     '''node model finder'''
 
-    # manager node model
-    manager = app(conf.manager.element.node, conf.managers)
+    # direct node model
+    model = app(conf.direct.element.node, conf.managers)
 
 
 nodes = Nodes()

File graphalchemy/models/readers.py

     # model finder
     _finder = app(conf.model.finder.node, conf.appspace)
     # direct node reader
-    r = factory(conf.read.node, backends, db)
+    _r = factory(conf.read.node, backends, db)
     # direct node writer
-    w = factory(conf.write.node, backends, db)
+    _w = factory(conf.write.node, backends, db)
 
     def __init__(self, model):
         '''
     def anchor(self):
         '''anchor node for a graph model'''
         try:
-            C = self.model.C
-            anchor_link = C.anchor_link
-            S = self.S
-            userspace = S.userspace
+            L = self.model.L
+            anchor_link = L.anchor_link
+            G = self.G
+            userspace = G.userspace
             return self.Q.app(anchor_link, userspace)
         except AppLookupError:
-            label = S.anchor.label
-            anchor = self.filter_by(C.index, label, label)
+            label = G.anchor.label
+            anchor = self.filter_by(L.index, label, label)
             if anchor:
                 self.Q.add(anchor, anchor_link, userspace)
                 return anchor
     def reference(self):
         '''reference node for a model'''
         try:
-            S = self.S
-            C = self.model.C
-            return self.Q.app(C.reference_link, S.userspace)
+            G = self.G
+            L = self.model.L
+            return self.Q.app(L.reference_link, G.userspace)
         except AppLookupError:
-            label = S.reference.label
-            ref = self.filter_by(C.index, label, label)
+            label = G.reference.label
+            ref = self.filter_by(L.index, label, label)
             if ref:
-                self.Q.add(ref, C.reference_link, S.userspace)
+                self.Q.add(ref, L.reference_link, G.userspace)
                 return ref
 
     def filter(self, index, queries):
         @param index: name of index
         @param queries: queries built with query builder
         '''
-        return self.r.filter(index, queries, self.model)
+        return self._r.filter(index, queries, self.model)
 
     def filter_by(self, index, key, value):
         '''
         @param key: keyword in index
         @param value: value in index (or second key)
         '''
-        return self.r.filter_by(
+        return self._r.filter_by(
             index,
             key,
             value,
 
         @param element: element id
         '''
-        return self.model(self.r.get(element))
+        return self.model(self._r.get(element))
 
     def traverse(self, this, tester=None, links=None, unique=None):
         '''
         @param unique: how often to traverse the same element (default: None)
         '''
         finder = self._finder
-        for element in self.r.traverser(this, tester, links, unique):
+        for element in self._r.traverser(this, tester, links, unique):
             yield finder(element=element)(element)
 
     def walk(self, this, direction=None, label=None, keys=None, end='end'):
         @param end: which end of link to return (default: 'end')
         '''
         finder = self._finder
-        for element in self.r.walker(this, direction, label, keys, end):
+        for element in self._r.walker(this, direction, label, keys, end):
             yield finder(element=element)(element)

File graphalchemy/models/workers.py

     _query = app(conf.model.node.reader, conf.appspace)
     # model user
     _using = app(conf.model.node.writer, conf.appspace)
-    # direct node reader
-    r = factory(conf.read.node, backends, db)
-    # direct node writer
-    w = factory(conf.write.node, backends, db)
+    # node reader
+    _r = factory(conf.read.node, backends, db)
+    # node writer
+    _w = factory(conf.write.node, backends, db)
+    # direct
+    direct = factory(conf.direct.worker.node, conf.direct, 'session')
 
     def _autoslug(self, properties):
         '''
 
         @param properties: graph element properties
         '''
-        C = self.model.C
-        slug_from = C.slug_from
+        L = self.model.L
+        slug_from = L.slug_from
         if not slug_from:
             return
         slug = tmpslug = self.Q.slugify(properties[slug_from])
-        slug_field = C.slug_field
+        slug_field = L.slug_field
         # loop until unique slug is located
-        filter_by = self.r.filter_by
-        index = C.index
+        filter_by = self._r.filter_by
+        index = L.index
         for cnt in count(1):
             prev = filter_by(index, slug_field, tmpslug)
             if not prev:
         # add slug
         properties[slug_field] = tmpslug
 
+    def _prepare(self, this):
+        # snapshot if flag set
+        if this.L.versioned:
+            self.query(self.model).snapshot(this)
+        super(Nodes, self)._prepare(this)
+
     @defer
     def _create(self, data):
         '''
         @param data: data
         '''
         model = self.model
-        C = model.C
-        data.update(_created=self.now(), _model=C.name, _uuid=self.Q.uuid())
+        L = model.L
+        data.update(_created=self.now(), _model=L.name, _uuid=self.Q.uuid())
         # number of versions to maintain
-        if C.versioned:
+        if L.versioned:
             data['_versions'] = 0
         self._preprocess(data)
-        thing = self.w.create(
+        thing = self._w.create(
             data,
-            C.reference_link,
-            model.nodes.reference(),
+            L.reference_link,
+            self.query(model).reference(),
             partial(self._postprocess, model=model),
         )
         thing._refresh()
 
-    def _prepare(self, this):
-        # snapshot if flag set
-        if this.C.versioned:
-            self._snapshot(this)
-        super(Nodes, self)._prepare(this)
-
-    @defer
-    def _update(self, this, data):
-        '''
-        update a graph element's properties
-
-        @param this: graph object
-        @param data: data
-        '''
-        self._preprocess(data)
-        self.w.update(this, data, partial(self._postprocess, model=self.model))
-        this._refresh()
-
     def _preprocess(self, this):
         '''
         pre-process graph element
         @param this: graph object
         '''
         esc = escape
-        for k in self.model.C.escaped:
+        for k in self.model.L.escaped:
             this[k] = esc(this[k])
         this['_modified'] = self.now()
         # slug field
         @param this: graph object
         '''
         this = self.model(this)
-        C = self.model.C
-        index = C.index
+        L = self.model.L
+        index = L.index
         # index created date
         index_one = self.index_one
         if index:
             index_one(index, 'created', self.now(), this)
         # index any listed properties
-        indexed = C.indexed
+        indexed = L.indexed
         if indexed:
             self.index_many(index, this, indexed)
         # add a slug if present
-        slug_from = C.slug_from
+        slug_from = L.slug_from
         if slug_from:
             index_one(index, slug_from, getattr(this, slug_from), this)
         # index properties that support full text search
-        fts_indexed = C.fts_indexed
+        fts_indexed = L.fts_indexed
         if fts_indexed:
-            self.index_many(C.fts_index, this, fts_indexed)
+            self.index_many(L.fts_index, this, fts_indexed)
         return this
 
+    @defer
+    def _update(self, this, data):
+        '''
+        update a graph element's properties
+
+        @param this: graph object
+        @param data: data
+        '''
+        self._preprocess(data)
+        self._w.update(
+            this, data, partial(self._postprocess, model=self.model)
+        )
+        this._refresh()
+
     def query(self, model):
         '''
         query using a graph model

File graphalchemy/models/writers.py

     # model finder
     _finder = app(conf.model.finder.node, conf.appspace)
     # direct node reader
-    r = factory(conf.read.node, backends, db)
+    _r = factory(conf.read.node, backends, db)
     # direct node writer
-    w = factory(conf.write.node, backends, db)
+    _w = factory(conf.write.node, backends, db)
 
     def __init__(self, model):
         '''
     def anchor(self, **kw):
         '''create an anchor node'''
         model = self.model
-        C = model.C
-        name = C.name
-        S = self.S.anchor
-        label = S.label
+        L = model.L
+        name = L.name
+        G = self.G.anchor
+        label = G.label
         index_one = self.index_one
         def callback(node): #@IgnorePep8
             node = self._finder(element=node)(node)
             # put in root index
-            root_index = C.root_index
+            root_index = L.root_index
             if root_index:
                 index_one(root_index, label, name, node)
             # put in model index
-            index = C.index
+            index = L.index
             if index:
                 index_one(index, label, label, node)
             return node
         data = dict(
             _created=self.now(),
             _uuid=self.Q.uuid(),
-            text=S.description.format(name=name),
+            text=G.description.format(name=name),
         )
         data.update(kw)
-        return self.w.create(
+        return self._w.create(
             data,
-            C.reference_link,
+            L.reference_link,
             model.nodes.reference(),
             callback,
         )
         '''
         created = self.now()
         model = self.model
-        C = model.C
-        index = C.index
-        S = self.S.fork
+        L = model.L
+        index = L.index
+        G = self.G.fork
         if index:
             # create callback
             index_one = self.index_one
                 fork['_forked'] = thing.id
                 fork = model(fork)
                 # index fork
-                index_one(index, S.label, thing.id, fork)
+                index_one(index, G.label, thing.id, fork)
                 # index forked time
-                index_one(index, S.created, created, fork)
+                index_one(index, G.created, created, fork)
                 return fork
         else:
             callback = None
-        return self.w.clone(thing, C.fork_link, callback, _created=created)
+        return self._w.clone(thing, L.fork_link, callback, _created=created)
 
     @defer
     def refer(self, **kw):
         '''create a reference node'''
         finder = self._finder
         model = self.model
-        C = model.C
-        name = C.name
-        S = self.S.reference
-        label = S.label
-        w = self.w
+        L = model.L
+        name = L.name
+        G = self.G.reference
+        label = G.label
+        w = self._w
         index_one = w.index_one
         create_index = w.create_index
-        r = self.r
+        r = self._r
         def callback(node): #@IgnorePep8
             node = finder(element=node)(node)
             # put in root index
-            root_index = r.index(C.root_index)
+            root_index = r.index(L.root_index)
             index_one(root_index, label, name, node)
             # create any main index
-            index = C.index
+            index = L.index
             if index:
                 index_one(create_index(index), label, label, node)
             # create any full text index
-            fts_index = C.get('fts_index', False)
+            fts_index = L.get('fts_index', False)
             if fts_index:
                 create_index(fts_index, fts=True)
             return node
         data = dict(
             _created=h.now(),
             _uuid=self.Q.uuid(),
-            text=S.description.format(name=name),
+            text=G.description.format(name=name),
         )
         data.update(kw)
         return w.create(
-            data, C.reference_link, finder(element=root)(root), callback,
+            data, L.reference_link, finder(element=root)(root), callback,
         )
 
     @defer
         @param thing: graph object
         @param snapshot: snapshot to revert to
         '''
-        if thing.C.versioned:
+        if thing.L.versioned:
             self.snapshot(thing)
             self.update(
                 thing,
-                self.r.filter_by(self.S.snapshot.label, snapshot).properties,
+                self._r.filter_by(self.G.snapshot.label, snapshot).properties,
             )
             self.snapshot(thing)
         raise ReversionError('could not revert snapshot {0}'.format(snapshot))
             _hash=thing.hash_diff(),
             _version=thing._version()
         )
-        S = self.S.version
+        G = self.G.version
         model = self.model
-        C = model.C
-        index = C.index
+        L = model.L
+        index = L.index
         if index:
             # create callback if index
             index_one = self.index_one
             def callback(snapshot): #@IgnorePep8
                 snapshot = model(snapshot)
                 # index snapshot with parent snapshot
-                index_one(index, S.reference, thing.id, snapshot)
+                index_one(index, G.reference, thing.id, snapshot)
                 # index snapshot as snapshot
-                index_one(index, S.label, snapshot.id, snapshot)
+                index_one(index, G.label, snapshot.id, snapshot)
                 # index versioned time
-                index_one(index, S.created, created, snapshot)
+                index_one(index, G.created, created, snapshot)
                 return snapshot
         else:
             callback = None
         # create snapshot and link back to previous snapshot
         thing._refresh()
-        return self.w.create(
-            diff, C.version_link, thing, callback, _created=created,
+        return self._w.create(
+            diff, L.version_link, thing, callback, _created=created,
         )