diff --git a/fish-bowl/fishbowl/fishbowl.py b/fish-bowl/fishbowl/fishbowl.py index 02be24c79..73f11657d 100644 --- a/fish-bowl/fishbowl/fishbowl.py +++ b/fish-bowl/fishbowl/fishbowl.py @@ -16,6 +16,10 @@ def __init__(self, gaffer_connector, generated_directory_path="generated"): print("To import operations, predicates and functions, use the following command:") print("from " + generated_directory_path + " import *") + def _write_to_file(self, file_path, data): + with open(file_path, "w+") as file: + file.write(data) + def __generate_library(self): if os.path.exists(self.generated_directory_path): @@ -23,17 +27,17 @@ def __generate_library(self): os.mkdir(self.generated_directory_path) - operations_python = self.__generate_operations() - functions_python = self.__generate_functions("/graph/config/transformFunctions") - predicates_python = self.__generate_functions("/graph/config/filterFunctions") + operations_python = self._generate_operations() + functions_python = self._generate_functions("/graph/config/transformFunctions") + predicates_python = self._generate_functions("/graph/config/filterFunctions") - write_to_file(os.path.join(self.generated_directory_path, "functions.py"), functions_python) - write_to_file(os.path.join(self.generated_directory_path, "predicates.py"), predicates_python) - write_to_file(os.path.join(self.generated_directory_path, "operations.py"), operations_python) - write_to_file(os.path.join(self.generated_directory_path, "__init__.py"), + self._write_to_file(os.path.join(self.generated_directory_path, "functions.py"), functions_python) + self._write_to_file(os.path.join(self.generated_directory_path, "predicates.py"), predicates_python) + self._write_to_file(os.path.join(self.generated_directory_path, "operations.py"), operations_python) + self._write_to_file(os.path.join(self.generated_directory_path, "__init__.py"), "__all__ = [ \"operations\", \"predicates\", \"functions\" ]\n") - def __generate_functions(self, path): + def _generate_functions(self, path): # functions is a list of function classes functions = self._gaffer_connector.get(path) @@ -72,7 +76,7 @@ def __generate_functions(self, path): return "\n".join(functions_python) - def __generate_operations(self): + def _generate_operations(self): operation_summaries = self._gaffer_connector.get("/graph/operations/details") operations_python = ["from fishbowl.core import *\n\n"] diff --git a/fish-bowl/fishbowl/util.py b/fish-bowl/fishbowl/util.py index 697bd556a..97304ee4c 100644 --- a/fish-bowl/fishbowl/util.py +++ b/fish-bowl/fishbowl/util.py @@ -1,32 +1,12 @@ -import re from fishbowl.core import ToJson -""" -Convert string from camelCase to snake_case -""" - - +# JsonConverter def camel_to_snake(name): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() -""" -Write data to a file -""" - - -def write_to_file(file_path, data): - file = open(file_path, "w+") - file.write(data) - file.close() - - -""" -Returns a json serializable dictionary based off an object -""" - - +# Move this def to_json(obj): if obj is None: return None diff --git a/python-shell/src/gafferpy/client/requests_client.py b/python-shell/src/gafferpy/client/requests_client.py index f45dee8e8..932bc06c0 100644 --- a/python-shell/src/gafferpy/client/requests_client.py +++ b/python-shell/src/gafferpy/client/requests_client.py @@ -86,7 +86,9 @@ def perform_request(self, method, target, headers=None, body=None): raise ConnectionError( 'HTTP error ' + str(error.response.status_code) + ': ' + error.response.text) - ## TODO: Fix json transform + if method == "GET": + return response.text + try: response_json = response.json() except json.JSONDecodeError: @@ -103,7 +105,5 @@ def perform_request(self, method, target, headers=None, body=None): return g.JsonConverter.from_json(result) - #return response.text - def __del__(self): self._session.close() diff --git a/python-shell/src/gafferpy/client/urllib_client.py b/python-shell/src/gafferpy/client/urllib_client.py index 22575e3fc..39cfd2ecd 100755 --- a/python-shell/src/gafferpy/client/urllib_client.py +++ b/python-shell/src/gafferpy/client/urllib_client.py @@ -58,9 +58,11 @@ def perform_request(self, method, target, headers=None, body=None): error_body) raise ConnectionError(new_error_string) - ## TODO: Fix json transform response_text = response.read().decode('utf-8') + if method == "GET": + return response_text + if self.verbose: print('Query response: ' + response_text) @@ -70,5 +72,3 @@ def perform_request(self, method, target, headers=None, body=None): result = None return g.JsonConverter.from_json(result) - - #return response.read().decode('utf-8')