Example #1
0
	def reloadGraphs(self) :
		"reloads the graph list"
		r = self.connection.session.get(self.graphsURL)
		data = r.json()
		if r.status_code == 200 :
			self.graphs = {}
			for graphData in data["graphs"] :
				try :
					self.graphs[graphData["_key"]] = GR.getGraphClass(graphData["_key"])(self, graphData)
				except KeyError :
					self.graphs[graphData["_key"]] = Graph(self, graphData)
		else :
			raise UpdateError(data["errorMessage"], data)
Example #2
0
	def reloadGraphs(self) :
		"reloads the graph list"
		r = self.connection.session.get(self.graphsURL)
		data = r.json()
		if r.status_code == 200 :
			self.graphs = {}
			for graphData in data["graphs"] :
				try :
					self.graphs[graphData["_key"]] = GR.getGraphClass(graphData["_key"])(self, graphData)
				except KeyError :
					self.graphs[graphData["_key"]] = Graph(self, graphData)
		else :
			raise UpdateError(data["errorMessage"], data)
Example #3
0
	def createGraph(self, name, createCollections = True) :
		"""Creates a graph and returns it. 'name' must be the name of a class inheriting from Graph.
		You can decide weither or not you want non existing collections to be created by setting the value of 'createCollections'.
		If the value if 'false' checks will be performed to make sure that every collection mentionned in the edges definition exist. Raises a ValueError in case of
		a non-existing collection."""

		def _checkCollectionList(lst) :
			for colName in lst :
				if not COL.isCollection(colName) :
					raise ValueError("'%s' is not a defined Collection" % colName)

		graphClass = GR.getGraphClass(name)

		ed = []
		for e in graphClass._edgeDefinitions :
			if not createCollections :
				if not COL.isEdgeCollection(e.edgesCollection) :
					raise ValueError("'%s' is not a defined Edge Collection" % e.edgesCollection)
				_checkCollectionList(e.fromCollections)
				_checkCollectionList(e.toCollections)

			ed.append(e.toJson())
		
		if not createCollections :
			_checkCollectionList(graphClass._orphanedCollections)

		payload = {
				"name": name,
				"edgeDefinitions": ed,
				"orphanCollections": graphClass._orphanedCollections
			}
		

		payload = json.dumps(payload)
		r = self.connection.session.post(self.graphsURL, data = payload)
		data = r.json()

		if r.status_code == 201 or r.status_code == 202 :
			self.graphs[name] = graphClass(self, data["graph"])
		else :
			raise CreationError(data["errorMessage"], data)		
		return self.graphs[name]
Example #4
0
    def createGraph(self, name, createCollections=True):
        """Creates a graph and returns it. 'name' must be the name of a class inheriting from Graph.
		You can decide weither or not you want non existing collections to be created by setting the value of 'createCollections'.
		If the value if 'false' checks will be performed to make sure that every collection mentionned in the edges definition exist. Raises a ValueError in case of
		a non-existing collection."""
        def _checkCollectionList(lst):
            for colName in lst:
                if not COL.isCollection(colName):
                    raise ValueError("'%s' is not a defined Collection" %
                                     colName)

        graphClass = GR.getGraphClass(name)

        ed = []
        for e in graphClass._edgeDefinitions:
            if not createCollections:
                if not COL.isEdgeCollection(e.edgesCollection):
                    raise ValueError("'%s' is not a defined Edge Collection" %
                                     e.edgesCollection)
                _checkCollectionList(e.fromCollections)
                _checkCollectionList(e.toCollections)

            ed.append(e.toJson())

        if not createCollections:
            _checkCollectionList(graphClass._orphanedCollections)

        payload = {
            "name": name,
            "edgeDefinitions": ed,
            "orphanCollections": graphClass._orphanedCollections
        }

        payload = json.dumps(payload)
        r = requests.post(self.graphsURL, data=payload)
        data = r.json()
        if r.status_code == 201:
            self.graphs[name] = graphClass(self, data["graph"])
        else:
            raise CreationError(data["errorMessage"], data)
        return self.graphs[name]