Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
gh-981: Operations are generated and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
t92549 committed Jun 27, 2022
1 parent 2fb27e3 commit 6c6ae9c
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 2,786 deletions.
2 changes: 1 addition & 1 deletion python-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ from gafferpy import gaffer as g
from gafferpy import gaffer_connector

# Instantiate a connector
gc = gaffer_connector.GafferConnector("http://localhost:8080/rest/latest")
gc = gaffer_connector.GafferConnector("http://localhost:8080/rest")

# You can use the connector to perform get requests
schema = gc.execute_get(g.GetSchema())
Expand Down
2 changes: 1 addition & 1 deletion python-shell/src/examples/Gaffer-Python-Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"host = \"http://localhost:8080/rest/latest\""
"host = \"http://localhost:8080/rest\""
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions python-shell/src/examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def generate_domain_objects_chain(gc):
[
g.GetElements(
input=[g.EntitySeed(vertex='M5')],
seed_matching_type=g.SeedMatchingType.RELATED,
#seed_matching=g.SeedMatchingType.RELATED,
view=g.View(
edges=[
g.ElementDefinition(
Expand Down Expand Up @@ -960,4 +960,4 @@ def op_chain_in_json(gc):


if __name__ == "__main__":
run('http://localhost:8080/rest/latest', False)
run('http://localhost:8080/rest', False)
2 changes: 1 addition & 1 deletion python-shell/src/examples/example_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def count_all_elements_default_view(gc):
print()

if __name__ == "__main__":
run('http://localhost:8080/rest/latest', False)
run('http://localhost:8080/rest', False)
2 changes: 1 addition & 1 deletion python-shell/src/fishbowl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Things it should do:
from fishbowl.connector import GafferConnector
from fishbowl.fishbowl import Fishbowl

fb = Fishbowl(gaffer_connector=GafferConnector(host="http://localhost:8080/rest/latest"))
fb = Fishbowl(gaffer_connector=GafferConnector(host="http://localhost:8080/rest"))
```
Your python files will be appear in a folder called `generated`
They can be imported using the following command:
Expand Down
10 changes: 7 additions & 3 deletions python-shell/src/fishbowl/fishbowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, gaffer_connector, generated_directory_path="generated"):
self._gaffer_connector = gaffer_connector
self.generated_directory_path = generated_directory_path
print("Generating python Library from REST service")
self.__generate_library()
self._generate_library()
print("done")
print("To import operations, predicates and functions, use the following command:")
print("from " + generated_directory_path + " import *")
Expand All @@ -20,7 +20,7 @@ def _write_to_file(self, file_path, data):
with open(file_path, "w+") as file:
file.write(data)

def __generate_library(self):
def _generate_library(self):

if os.path.exists(self.generated_directory_path):
shutil.rmtree(self.generated_directory_path)
Expand Down Expand Up @@ -86,7 +86,11 @@ def _generate_functions(self, path, import_path, base_class):
return "\n".join(functions_python)

def _generate_operations(self):
operation_summaries = self._gaffer_connector.get("/graph/operations/details", json_result=True)
# Gaffer 2 spring-rest has an endpoint for every store operation, even ones unsupported by the store
try:
operation_summaries = self._gaffer_connector.get("/graph/operations/details/all", json_result=True)
except ConnectionError:
operation_summaries = self._gaffer_connector.get("/graph/operations/details", json_result=True)

operations_python = ["from gafferpy.gaffer_operations import Operation\n\n"]

Expand Down
31 changes: 7 additions & 24 deletions python-shell/src/gafferpy/gaffer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,9 @@ def get_url(self):
return self._url


class GetSchema(gaffer_operations.Operation, GetGraph):
CLASS = 'uk.gov.gchq.gaffer.store.operation.GetSchema'

def __init__(self,
compact=None,
options=None):
super().__init__(_class_name=self.CLASS,
options=options)

if compact is not None:
self.compact = compact
else:
self.compact = False

self._url = '/graph/config/schema'

def to_json(self):
operation = super().to_json()

if self.compact is not None:
operation['compact'] = self.compact

return operation

class GetSchema(GetGraph):
def __init__(self):
super().__init__('/graph/config/schema')

class GetFilterFunctions(GetGraph):
def __init__(self):
Expand Down Expand Up @@ -84,6 +63,10 @@ class GetOperations(GetGraph):
def __init__(self):
super().__init__('/graph/operations')

class GetAllOperationDetails(GetGraph):
def __init__(self):
super().__init__('/graph/operations/details/all')


class GetSerialisedFields(GetGraph):
def __init__(self, class_name=None):
Expand Down
Loading

0 comments on commit 6c6ae9c

Please sign in to comment.