source: cows_wps/trunk/cows_wps/lib/ui/proc_config_convertor.py @ 5958

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/lib/ui/proc_config_convertor.py@7095
Revision 5958, 2.5 KB checked in by astephen, 11 years ago (diff)

more updates for submission form.

Line 
1"""
2proc_config_convertor.py
3========================
4
5Converts what is in the process configuration file into a set of
6form elements.
7
8"""
9
10import logging
11import copy
12
13from cows_wps.utils.create_process_config import createProcessConfig
14
15
16log = logging.getLogger(__name__)
17
18class ProcConfigConvertor(object):
19    """
20    Class to convert process configuration into form element dict.
21    """
22
23    def convertConfig(self, proc_id):
24        proc_config = copy.deepcopy(createProcessConfig(proc_id)["Capabilities"])
25        can_cache = proc_config["wps_interface"]["caching_enabled"]
26        globals = self.convertGlobals(proc_config["globals"])
27        globals.append( ("Is process cachable?", str(can_cache)) )
28        inputs = self.convertInputs(proc_config["DataInputs"], proc_config["OrderedDataInputs"])
29        outputs = self.convertOutputs(proc_config["ProcessOutputs"])
30
31        resp = {"Process Information": globals,
32                "Inputs": inputs,
33                "Outputs": outputs}
34       
35        return resp
36
37    def convertGlobals(self, d):
38        "Returns an ordered list."
39        ordered_ids = ["Title", "ProcessDescription", "Abstract", "ProcessVersion"]
40        ordered_long_names = ["Process Name", "Short Description", "Full Description", "Version number"]
41        return self._genericMapper(d, ordered_ids, ordered_long_names)
42
43    def convertInputs(self, d, ordered_ids):
44        "Return an ordered list of [(id, long_name, value_dict)]."
45        ordered_long_names = ordered_ids
46        return self._genericMapper(d, ordered_ids, ordered_long_names)
47
48    def convertOutputs(self, d):
49        "Return an ordered list."
50        ordered_ids = ["NOT DONE YET"]
51        ordered_long_names = ["NOTE DONE YET"]
52        d["NOT DONE YET"] = "NOT DONE"
53        return self._genericMapper(d, ordered_ids, ordered_long_names)
54       
55    def _genericMapper(self, dct, ordered_ids, ordered_long_names):
56        """
57        Returns an ordered list of (long_name, dct[ordered_id]) pairs
58        built from dct values and ids. All values are converted to strings.
59        Length of ordered_ids and ordered_long_names must be the same.
60        """
61        if len(ordered_ids) != len(ordered_long_names):
62            log.exception("ordered_ids and ordered_long_names must be same length in call to _genericMapper().")
63
64        rt_list = []
65
66        for (i, id) in enumerate(ordered_ids):
67           
68            value = dct[id]
69            if type(value) != type({1:2}): value = str(value)
70            key = ordered_long_names[i]
71            rt_list.append( (key, value) )
72
73        return rt_list
Note: See TracBrowser for help on using the repository browser.