source: cows_wps/trunk/process_modules/wcs_wrapper.py @ 7565

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/process_modules/wcs_wrapper.py@7565
Revision 7565, 3.7 KB checked in by astephen, 10 years ago (diff)

Working on how the multiple dependencies on dynamic args will work.
Including WCSWrapper. Cross-domain security is still an issue.

Line 
1"""
2wcs_wrapper.py
3===================
4
5Process wcs_wrapper that holds the WCSWrapper class.
6
7"""
8
9# Standard library imports
10import os, stat, time, sys, logging
11
12# WPS imports
13from cows_wps.process_handler.fileset import FileSet, FLAG
14import cows_wps.process_handler.process_support as process_support
15from cows_wps.process_handler.context.process_status import STATUS
16import process_modules.process_base
17
18# Import process-specific modules
19
20# NOTE ABOUT LOGGING:
21# You can log with the context.log object
22
23log = logging.getLogger(__name__)
24log.setLevel(logging.DEBUG)
25
26
27class WCSWrapper(process_modules.process_base.ProcessBase):
28
29    # Define arguments that we need to set from inputs
30    # Based on args listed in process config file
31    args_to_set = ["Step"]
32
33    # Define defaults for arguments that might not be set
34    # A dictionary of arguments that we can over-write default values for
35    # Some args might be mutually-exclusive or inclusive so useful to set
36    # here as well as in the config file.
37    input_arg_defaults = {}
38
39    # Define a dictionary for arguments that need to be processed
40    # before they are set (with values as the function doing the processing).
41    arg_processers = {}
42
43   
44    def _executeProc(self, context, dry_run):
45        """
46        This is called to step through the various parts of the process
47        executing the actual process if ``dry_run`` is False and just
48        returning information on the volume and duration of the outputs
49        if ``dry_run`` is True.
50        """
51        # Call standard _setup
52        self._setup(context)
53        a = self.args
54
55        if not dry_run:
56            # Now set status to started
57            context.setStatus(STATUS.STARTED, 'Job is now running', 0)
58
59        # Add output file
60        outputFile = 'output.txt'
61        outputFilePath = os.path.join(context.processDir, "outputs", outputFile)
62
63        if not dry_run:
64            # Really generate output
65            outputList = range(0, 10000, a["Step"])
66            fout = open(outputFilePath, "w")
67            fout.write("\n".join([str(i) for i in outputList]))
68            fout.close()
69
70            size = os.path.getsize(outputFilePath)
71       
72            # Add the output list to the XML output section: ProcessSpecificContent
73            context.outputs['ProcessSpecificContent'] = {"OutputList": " ".join([str(i) for i in outputList])} 
74
75        else:
76            # Make it up for dry run
77            outputList = [2,3,5,7,8,9,10]
78            size = 2345 
79
80        if not dry_run:
81            # We can log information at any time to the main log file
82            context.log.info('Written output file: %s' % outputFilePath)
83        else:
84            context.log.debug("Running dry run.")
85
86        # Add the stations file to the outputs
87        self._addFileToOutputs(outputFilePath, 'Output File', size = size)
88
89        if not dry_run:
90            # Finish up by calling function to set status to complete and zip up files etc
91            # In this case we set keep = True so that output file is accessible to downstream process
92            # outside of the main output zip file (so downstream process does not need to unzip it).
93            # This is fine as files are small.
94            process_support.finishProcess(context, self.fileSet, self.startTime, keep = True)
95        else:
96            estimated_duration = 10 # seconds
97            process_support.finishDryRun(context, [], self.fileSet,
98                            estimated_duration, acceptedMessage = 'Dry run complete')           
99
100
101    def _validateInputs(self):
102        """
103        Runs specific checking of arguments and their compatibility.
104        """
105        if self.args["Step"] > 1000:
106            raise Exception("Invalid arguments provided. 'Step' must be less than 1000.")
Note: See TracBrowser for help on using the repository browser.