Changeset 7065


Ignore:
Timestamp:
23/06/10 21:57:39 (9 years ago)
Author:
astephen
Message:

More work on process_base.py module.

Location:
cows_wps/trunk/process_modules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cows_wps/trunk/process_modules/get_weather_stations.py

    r7063 r7065  
    1616 
    1717import process_modules.lib_get_weather_stations.utils as gws_utils 
     18import process_modules.process_base 
    1819 
    1920 
     
    2223 
    2324 
    24 class GetWeatherStations(object): 
     25class GetWeatherStations(process_modules.process_base.ProcessBase): 
    2526 
    2627    # Define arguments that we need to set from inputs 
     
    4647        if ``dry_run`` is True. 
    4748        """ 
    48         # Always record start time for duration in outputs 
    49         startTime = time.time() 
    50  
    51         # Always need a FileSet, even if empty 
    52         self.fileSet = context.outputs['FileSet'] = FileSet() 
    53  
    54         # parse the inputs and set dictionary: self.args 
    55         self._parseInputs(context.inputs) 
    56  
    57         # Check inputs are compatible 
    58         self._validateInputs() 
     49        # Call standard _setup 
     50        self._setup(context) 
    5951 
    6052        if not dry_run: 
     
    10496 
    10597 
    106     def _parseInputs(self, inputs): 
    107         """ 
    108         Parse the inputs into an instance dictionary and set defaults where required. 
    109         """ 
    110         self.args = {} 
    111          
    112         for key in self.args_to_set: 
    113             if key in self.input_arg_defaults.keys(): 
    114                 deft = self.input_arg_defaults[key] 
    115                 value = inputs.get(key, deft) 
    116  
    117             elif key not in inputs.keys(): 
    118                 raise KeyError("Must provide argument '%s' when calling '%s'." % (key, self.__class__.__name__)) 
    119           
    120             else: 
    121                 value = inputs[key] 
    122  
    123             # Process arg if required 
    124             if key in self.arg_processers.keys(): 
    125                 value = apply(self.arg_processers[key], [value]) 
    126  
    127             self.args[key] = value 
    128  
    129         return 
    130  
    131  
    13298    def _validateInputs(self): 
    13399        """ 
     
    136102        if self.args["Counties"] == [] and self.args["BBox"] == None: 
    137103            raise Exception("Invalid arguments provided. Must provide either a geographical bounding box or a list of counties.") 
    138  
    139  
    140     def _addFileToOutputs(self, fpath, info = 'An output file.', file_flag = FLAG.DATA, size = None): 
    141         """ 
    142         Adds the file to the fileSet outputs. If ``size`` is set (as in  
    143         a dry-run) then use it, otherwise get real size of file. 
    144         """ 
    145         if size == None: 
    146             size = os.stat(fpath)[stat.ST_SIZE] 
    147  
    148         fname = os.path.split(fpath)[-1] 
    149         self.fileSet.contents.append(FileSet(file_flag, fname, size, info)) 
    150  
    151  
    152     def OLDdryRun(self, context): 
    153  
    154         self.fileSet = context.outputs['FileSet'] = FileSet() 
    155         self.fileSet.contents.append(FileSet(FLAG.DATA, "testfile.txt", 30000, "Some file")) 
    156          
    157         process_support.finishDryRun(context, [("meta", "data")], self.fileSet, 
    158                                          60, acceptedMessage='Dry run complete') 
    159    
    160  
    161     def OLD__call__(self, context): 
    162         """ 
    163         This is where the WPS controller calls the process. 
    164         """ 
    165         # Always record start time for duration in outputs 
    166         startTime = time.time() 
    167         jobId = os.path.basename(context.processDir) 
    168  
    169         # Parse the inputs 
    170         Counties = context.inputs.get('Counties', []) 
    171         if Counties == []: 
    172             BBox = context.inputs.get("BBox", None) 
    173             if BBox == None: 
    174                 raise Exception("Invalid arguments provided. Must provide either a geographical bounding box or a list of counties.") 
    175  
    176         DataTypes = context.inputs.get("DataTypes", []) 
    177         StartDateTime = context.inputs['StartDateTime'] 
    178         StartDateTime = gws_utils.revertDateTimeToLongString(StartDateTime) 
    179         log.warn("DATE TIME: %s, type = %s" % (StartDateTime, type(StartDateTime))) 
    180         EndDateTime = context.inputs['EndDateTime'] 
    181         EndDateTime = gws_utils.revertDateTimeToLongString(EndDateTime) 
    182          
    183         context.setStatus(STATUS.STARTED, 'Job is now running', 0) 
    184  
    185         # Always need a FileSet, even if empty 
    186         self.fileSet = context.outputs['FileSet'] = FileSet() 
    187  
    188         # Make path to output file 
    189         WFile = 'weather_stations.txt' 
    190         MyFilePath = context.processDir + '/outputs/' + WFile 
    191  
    192         # Call code to get Weather Stations 
    193         station_list = gws_utils.getStationList(Counties, BBox, DataTypes, StartDateTime, 
    194                            EndDateTime, MyFilePath) 
    195  
    196         context.outputs['ProcessSpecificContent'] = { 
    197                                     "WeatherStations": " ".join(station_list)}  
    198         context.outputs['job_details']['job_capabilities'] = "send_to_extract_weather_data" 
    199  
    200         context.log.info('Written output file: %s' % WFile) 
    201         filesize = os.stat(MyFilePath)[stat.ST_SIZE] 
    202  
    203         self.fileSet.contents.append(FileSet(FLAG.DATA, WFile, filesize, 'Weather Stations File')) 
    204  
    205         # Set keep = True so that weather station files are accessible to downstream process 
    206         # without unzipping. This is fine as files are small. 
    207         process_support.finishProcess(context, self.fileSet, startTime, keep = True) 
  • cows_wps/trunk/process_modules/process_base.py

    r7063 r7065  
    155155        Runs specific checking of arguments and their compatibility. 
    156156        """ 
    157         if self.args["Counties"] == [] and self.args["BBox"] == None: 
    158             raise Exception("Invalid arguments provided. Must provide either a geographical bounding box or a list of counties.") 
     157        pass 
    159158 
    160159 
Note: See TracChangeset for help on using the changeset viewer.