Skip to content

Commit df63d08

Browse files
committed
dynamic graph loading
1 parent e05d902 commit df63d08

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

pyArango/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ def disconnect(self) :
8080

8181
class Connection(object) :
8282
"""This is the entry point in pyArango and directly handles databases."""
83-
def __init__(self, arangoURL = 'http://127.0.0.1:8529', username=None, password=None) :
83+
def __init__(self, arangoURL = 'http://127.0.0.1:8529', username=None, password=None, verbose=False) :
8484
self.databases = {}
85+
self.verbose = verbose
8586
if arangoURL[-1] == "/" :
8687
if ('url' not in vars()):
8788
raise Exception("you either need to define `url` or make arangoURL contain an HTTP-Host")

pyArango/graph.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class EdgeDefinition(object) :
5252
"""An edge definition for a graph"""
5353

5454
def __init__(self, edgesCollection, fromCollections, toCollections) :
55-
self.edgesCollection = self.name = edgesCollection
55+
self.name = edgesCollection
56+
self.edgesCollection = edgesCollection
5657
self.fromCollections = fromCollections
5758
self.toCollections = toCollections
5859

@@ -85,11 +86,28 @@ def __init__(self, database, jsonInit) :
8586
self._rev = jsonInit["_rev"]
8687
self._id = jsonInit["_id"]
8788

89+
orfs = set(self._orphanedCollections)
90+
for o in jsonInit["orphanCollections"] :
91+
if o not in orfs :
92+
self._orphanedCollections.append(o)
93+
if self.connection.verbose :
94+
print("Orphan collection %s is not in graph definition. Added it" % o)
95+
8896
self.definitions = {}
97+
edNames = set()
98+
for ed in self._edgeDefinitions :
99+
self.definitions[ed.edgesCollection] = ed.edgesCollection
100+
101+
for ed in jsonInit["edgeDefinitions"] :
102+
if ed["collection"] not in self.definitions :
103+
self.definitions[ed["collection"]] = EdgeDefinition(ed["collection"], fromCollections = ed["from"], toCollections = ed["to"])
104+
if self.connection.verbose :
105+
print("Edge definition %s is not in graph definition. Added it" % ed)
106+
89107
for de in self._edgeDefinitions :
90-
if de.name not in self.database.collections and not COL.isEdgeCollection(de.name) :
91-
raise KeyError("'%s' is not a valid edge collection" % de.name)
92-
self.definitions[de.name] = de
108+
if de.edgesCollection not in self.database.collections and not COL.isEdgeCollection(de.edgesCollection) :
109+
raise KeyError("'%s' is not a valid edge collection" % de.edgesCollection)
110+
self.definitions[de.edgesCollection] = de
93111

94112
self.URL = "%s/%s" % (self.database.graphsURL, self._key)
95113

0 commit comments

Comments
 (0)