Changeset 7159 for cows_wps


Ignore:
Timestamp:
12/07/10 13:51:05 (9 years ago)
Author:
astephen
Message:

Added pp header listing process.

Location:
cows_wps/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • cows_wps/trunk/cows_wps/controllers/jobviewer.py

    r7086 r7159  
    134134                file_url = file_set_list[0].find("{" + self.namespace +  "}FileURL").text 
    135135                file_path = mapDownloadURLToFilePath(file_url) 
    136                 x = x.replace("send_to_extract_weather_data", 
    137                   '<a href="/submit/form?proc_id=ExtractUKStationData&StationsFile=%s">Use stations to extract UK weather data</a>' % file_path)  
     136                if self.status == "complete": 
     137                    x = x.replace("send_to_extract_weather_data", 
     138                            '<a href="/submit/form?proc_id=ExtractUKStationData&StationsFile=%s">Use stations to extract UK weather data</a>' % file_path)  
    138139 
    139140            elif item == "JobVolume": 
  • cows_wps/trunk/process_configs/ConfigTemplate.ini

    r6947 r7159  
    2020 
    2121[DataInputs] 
    22 MyInput = string 
     22Step = int 
    2323 
    2424[ProcessOutputs] 
  • cows_wps/trunk/process_modules/process_template.py

    r7014 r7159  
    88 
    99# Standard library imports 
    10 import os, stat, time, sys 
     10import os, stat, time, sys, logging 
    1111 
    1212# WPS imports 
     
    1414import cows_wps.process_handler.process_support as process_support 
    1515from cows_wps.process_handler.context.process_status import STATUS 
     16import process_modules.process_base 
    1617 
    1718# Import process-specific modules 
     
    2021# You can log with the context.log object 
    2122 
    22  
    23 class ProcessTemplate(object): 
    24     def __call__(self, context): 
    25          
    26         startTime = time.time() 
    27         jobId = os.path.basename(context.processDir) 
    28  
    29         # Parse the inputs 
    30         MyInput = context.inputs['MyInput'] 
    31          
    32         context.setStatus(STATUS.STARTED, 'Job is now running', 0) 
    33  
    34         # Always need a FileSet, even if empty 
    35         fileSet = context.outputs['FileSet'] = FileSet() 
    36  
    37         MyOutput = "MY OUTPUT IS GREAT" 
    38         context.outputs['ProcessSpecificContent'] = {"MyOutput": MyOutput, "TryAnArray": [1, 3, 567]}  
    39  
    40         MyFile = 'MyFile.txt' 
    41         MyFilePath = context.processDir + '/outputs/' + MyFile 
    42  
    43         fh = open(MyFilePath, 'w') 
    44         fh.write('You can write the input here if you like: %s.' % MyInput) 
    45         fh.close() 
    46  
    47         context.log.info('Written output file: %s' % MyFile) 
    48         filesize = os.stat(MyFilePath)[stat.ST_SIZE] 
    49  
    50         fileSet = context.outputs['FileSet'] = FileSet() 
    51         fileSet.contents.append(FileSet(FLAG.DATA, MyFile, filesize, 'The only output')) 
    52  
    53         context.setStatus(STATUS.COMPLETED, 'The End', 100) 
    54          
    55         completionTime = time.time() 
    56         process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime) 
     23log = logging.getLogger(__name__) 
     24log.setLevel(logging.DEBUG) 
    5725 
    5826 
    59     def dryRun(self, context): 
     27class ProcessTemplate(process_modules.process_base.ProcessBase): 
    6028 
    61         # Not implemented for sync jobs 
    62         pass 
     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 TracChangeset for help on using the changeset viewer.