From 2eba26fab4f26af32825b1dccc84dfd50fb54cbb Mon Sep 17 00:00:00 2001 From: afabiani Date: Fri, 14 Sep 2018 11:20:31 +0200 Subject: [PATCH] - Version 2.14.1 --- .gitignore | 1 + setup.py | 2 +- src/wpsremote/computation_job_input.py | 18 +++++++++--------- src/wpsremote/computation_job_inputs.py | 6 +++--- src/wpsremote/computation_job_param.py | 4 ++-- src/wpsremote/input_parameter.py | 9 +++++++-- src/wpsremote/input_parameters.py | 7 +++---- src/wpsremote/output_file_parameter.py | 15 +++++++++++---- src/wpsremote/servicebot.py | 1 + .../xmpp_data/configs/myservice/service.config | 3 ++- 10 files changed, 40 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 9de9e67..d6e426f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.py[cod] *.suo +*.bak /build/ RemoteWPS1.pyproj diff --git a/setup.py b/setup.py index 4c3bfc9..26b2319 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( name = "wps-remote", - version = "2.14.0", + version = "2.14.1", author = "GeoServer Developers", author_email = "geoserver-devel@lists.sourceforge.net", description = "A library that allows users to publish their executables as GeoServer WPS Processes through the XMPP protocol", diff --git a/src/wpsremote/computation_job_input.py b/src/wpsremote/computation_job_input.py index 3690605..316237d 100644 --- a/src/wpsremote/computation_job_input.py +++ b/src/wpsremote/computation_job_input.py @@ -14,13 +14,14 @@ class ComputationJobInput(object): - def __init__(self, name, input_type, title, description, default=None, formatter=None): + def __init__(self, name, input_type, title, description, default=None, formatter=None, input_mime_type=None): self._name = name self._type = input_type self._default = default self._formatter = formatter self._title = title self._description = description + self._input_mime_type = input_mime_type self._value = None self._value_converted = None self._allowed_chars = string.printable.replace(' ','') @@ -37,7 +38,7 @@ def _validate_and_convert(self, value): elif (self._type=='url'): if all(c in self._allowed_chars_url for c in value): return value - elif self._type=='application/json': + elif self._type in ['application/json', 'application/xml']: return json.loads(value) elif (self._type=='datetime'): if self._formatter: @@ -52,15 +53,13 @@ def _validate_and_convert(self, value): raise TypeError("Cannot validate and convert value " + str(value) + " for type " + self._type) - def _type_checking(self, value): try: self._validate_and_convert( value ) return self._type except TypeError: return False - - + def validate(self): if (not self.has_value()): raise TypeError("cannot find a value for parameter " + self.get_name()) @@ -84,14 +83,12 @@ def set_value(self, value): res = False try: - res= self.validate() + res = self.validate() if not res: raise TypeError("cannot set value " + str(self._value) + " for parameter " + self.get_name() + " with type " + self._type) except: raise TypeError("cannot set value " + str(self._value) + " for parameter " + self.get_name() + " with type " + self._type) - - def get_value(self): if type(self._value_converted) is list and len(self._value_converted)==1: return self._value_converted[0] @@ -101,6 +98,9 @@ def get_value(self): def get_type(self): return self._type + def get_input_mime_type(self): + return self._input_mime_type + def get_value_string(self): if type(self._value) is list and len(self._value)==1: if type(self._value[0]) is datetime.datetime: @@ -138,7 +138,7 @@ def get_name(self): def as_json_string(self): #{"type": "string", "description": "A persons surname", "max": 1, "default": "Meier"} res={} - attrib_to_convert = ['_type', "_title", "_default", "_description", "_min", "_max"] #missing _enum + attrib_to_convert = ['_type', '_title', '_default', '_description', '_min', '_max', '_input_mime_type'] #missing _enum attribute_list = [a for a in dir(self) if not a.startswith('__') and not callable(getattr(self, a))] attribute_list_filtered = [x for x in attribute_list if x in attrib_to_convert] for a in attribute_list_filtered: diff --git a/src/wpsremote/computation_job_inputs.py b/src/wpsremote/computation_job_inputs.py index 255cd66..039abb1 100644 --- a/src/wpsremote/computation_job_inputs.py +++ b/src/wpsremote/computation_job_inputs.py @@ -44,7 +44,8 @@ def create_from_dict(paremeters_types_defs): formatter = d['formatter'] if "formatter" in d else None mininum = int(d['min']) if "min" in d else 1 maximum = int(d['max']) if "max" in d else 1 - input_to_add = computation_job_param.ComputationJobParam(name, d['type'], title, d['description'], default, formatter, mininum, maximum) + input_mime_type = d['input_mime_type'] if "input_mime_type" in d else None + input_to_add = computation_job_param.ComputationJobParam(name, d['type'], title, d['description'], default, formatter, mininum, maximum, input_mime_type) elif d['class'] == 'const': title = d['title'] if "title" in d else None input_to_add = computation_job_const.ComputationJobConst(name, d['type'], title, d['description'], d['value']) @@ -53,7 +54,7 @@ def create_from_dict(paremeters_types_defs): else: raise TypeError("Cannot create computational job input without attribute class") cji.add_input( input_to_add ) - + return cji def __init__(self): @@ -88,7 +89,6 @@ def names(self): def __getitem__(self, k): return self._inputs[k] - def as_DLR_protocol(self): #[('result', '{"type": "string", ...ut.xml" }')] res = [] diff --git a/src/wpsremote/computation_job_param.py b/src/wpsremote/computation_job_param.py index b4a8d97..b676cd0 100644 --- a/src/wpsremote/computation_job_param.py +++ b/src/wpsremote/computation_job_param.py @@ -12,8 +12,8 @@ class ComputationJobParam(computation_job_input.ComputationJobInput): - def __init__(self, name, input_type, title, descr, default=None, formatter=None, min_occurencies=0, max_occurencies=1): - super(ComputationJobParam, self).__init__(name, input_type, title, descr, default, formatter) + def __init__(self, name, input_type, title, descr, default=None, formatter=None, min_occurencies=0, max_occurencies=1, input_mime_type=None): + super(ComputationJobParam, self).__init__(name, input_type, title, descr, default, formatter, input_mime_type) self._min = min_occurencies self._max = max_occurencies diff --git a/src/wpsremote/input_parameter.py b/src/wpsremote/input_parameter.py index a647834..c05ab0e 100644 --- a/src/wpsremote/input_parameter.py +++ b/src/wpsremote/input_parameter.py @@ -13,6 +13,7 @@ import json class InputParameter(object): + def __init__(self, name): self._name=name self._alias=None @@ -23,6 +24,7 @@ def __init__(self, name): self._max=1 self._default = None self._formatter = None + self._input_mime_type = None self._allowed_chars = string.printable.replace('-','').replace(' ','') self._value=None @@ -90,6 +92,9 @@ def validate(self): def get_name(self): return self._alias if self._alias <> None else self._name + def get_input_mime_type(self): + return self._input_mime_type + def get_name_no_alias(self): return self._name @@ -99,9 +104,9 @@ def get_cmd_line(self): def as_json_string(self): #{"type": "string", "description": "A persons surname", "max": 1, "default": "Meier"} res={} - attrib_to_convert = ['_type', "_title", "_description", "_min", "_max", "_default"] + attrib_to_convert = ['_type', '_title', '_description', '_min', '_max', '_default', '_input_mime_type'] attribute_list = [a for a in dir(self) if not a.startswith('__') and not callable(getattr(self, a))] attribute_list_filtered = [x for x in attribute_list if x in attrib_to_convert] for a in attribute_list_filtered: res[a[1:]] = getattr(self, a) - return json.dumps(res) \ No newline at end of file + return json.dumps(res) diff --git a/src/wpsremote/input_parameters.py b/src/wpsremote/input_parameters.py index b543f74..f6e7caa 100644 --- a/src/wpsremote/input_parameters.py +++ b/src/wpsremote/input_parameters.py @@ -15,14 +15,13 @@ class InputParameters(object): - @staticmethod def create_from_config(input_sections): '''Create a InputParameters object. input_sections: a dictionary such as { input1 : [( 'par1_input1_name' , par1_input1_value ), ( 'par2_input1_name' , par2_input1_value ), ...], input2 : [ .... ], ... } ''' - input_sections_reshaped=OrderedDict() + input_sections_reshaped = OrderedDict() #force the order of sections in config files: [input1], [input2], etc for k in sorted(input_sections): d=dict(input_sections[k]) @@ -88,7 +87,7 @@ def checkForCodeInsertion(self, argList): maliciousCommands = ['>', '<', '>>', '|', '>&', '<&'] # Check for bad code insertion maliciousCode = ['eval(', 'exec(', 'execfile(', 'input('] - + # Evaluate malicious commands if any(e in maliciousCommands for e in argList): raise IOError('Found bad code in user input') @@ -96,4 +95,4 @@ def checkForCodeInsertion(self, argList): for element in argList: for code in maliciousCode: if code in element: - raise IOError('Found bad code in user input') \ No newline at end of file + raise IOError('Found bad code in user input') diff --git a/src/wpsremote/output_file_parameter.py b/src/wpsremote/output_file_parameter.py index 787c332..56ffd6e 100644 --- a/src/wpsremote/output_file_parameter.py +++ b/src/wpsremote/output_file_parameter.py @@ -63,7 +63,7 @@ def as_json_string(self): attribute_list_filtered = [x for x in attribute_list if x in attrib_to_convert] for a in attribute_list_filtered: res[a[1:]] = getattr(self, a) - return json.dumps(res) + return json.dumps(res) def get_value(self): if self._backup_on_wps_execution_shared_dir != None and self._backup_on_wps_execution_shared_dir and self._wps_execution_shared_dir != None: @@ -103,6 +103,9 @@ def get_description(self): def get_title(self): return self._title + def get_output_mime_type(self): + return self._output_mime_type + def is_publish_as_layer(self): return (self._publish_as_layer != None and self._publish_as_layer == "true") @@ -208,6 +211,9 @@ def get_description(self): def get_title(self): return self._title + def get_output_mime_type(self): + return self._output_mime_type + def is_publish_as_layer(self): return (self._publish_as_layer != None and self._publish_as_layer == "true") @@ -314,7 +320,7 @@ def get_value(self): dst = bkp_dir.abspath() + "/" + filepath.basename() filepath.copy(dst) dst = path.path(dst) - + if len(files_to_publish) > 0: files_to_publish = files_to_publish + ";" files_to_publish = files_to_publish + dst.abspath() @@ -356,6 +362,9 @@ def get_description(self): def get_title(self): return self._title + def get_output_mime_type(self): + return self._output_mime_type + def is_publish_as_layer(self): return (self._publish_as_layer != None and self._publish_as_layer == "true") @@ -375,5 +384,3 @@ def get_metadata(self): if metadata_file.isfile(): return metadata_file.text() return ' ' - - diff --git a/src/wpsremote/servicebot.py b/src/wpsremote/servicebot.py index 4b543d9..415bc91 100644 --- a/src/wpsremote/servicebot.py +++ b/src/wpsremote/servicebot.py @@ -31,6 +31,7 @@ class ServiceBot(object): + """This script is the remote WPS agent. One instance of this agent runs on each computational node connected to the WPS for each algorithm available. The script runs continuosly. """ def __init__(self, remote_config_filepath, service_config_filepath): diff --git a/src/wpsremote/xmpp_data/configs/myservice/service.config b/src/wpsremote/xmpp_data/configs/myservice/service.config index 1c71469..e54fb60 100644 --- a/src/wpsremote/xmpp_data/configs/myservice/service.config +++ b/src/wpsremote/xmpp_data/configs/myservice/service.config @@ -42,7 +42,8 @@ process_blacklist = [resource consuming process name1, resource consuming proces class = param name = interval title = Elevation Interval -type = int +type = application/json +input_mime_type = application/json description = Elevation interval between contours. min = 1 max = 1