Changeset 7016 for cows_wps


Ignore:
Timestamp:
14/06/10 12:31:27 (9 years ago)
Author:
astephen
Message:

fixes to use common finishProcess call

Location:
cows_wps/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cows_wps/trunk/cows_wps/process_handler/process_support.py

    r7013 r7016  
    1010from cows_wps.process_handler.context.process_status import STATUS 
    1111 
    12 import cows_wps.utils.ukcp09_copyright_file_utils as ukcp09_copyright_file_utils 
    1312 
    1413log = logging.getLogger(__name__) 
    1514 
    16 def finishProcess(context, requestMetadata, fileSet, startTime,  
    17                   finalMessage='The End', keep=False): 
     15def finishProcess(context, fileSet, startTime,  
     16                  finalMessage = 'The End', keep = False): 
    1817    """ 
    1918    Performs the common finishing up tasks for a processes __call__ method. 
    2019    """ 
    21      
    2220    writeMetadataFile(context, requestMetadata) 
    23     processOutputs(context, fileSet, dryRun=False, keep=keep) 
     21    processOutputs(context, fileSet, dryRun = False, keep = keep) 
    2422    context.setStatus(STATUS.COMPLETED, finalMessage, 100) 
     23 
    2524    completionTime = time.time()    
    2625    updateJobDetailsAfterCompletion(context, startTime, completionTime) 
    2726 
    2827def finishDryRun(context, requestMetadata, fileSet, duration,  
    29                  acceptedMessage="Process execution request has been accepted"): 
     28                 acceptedMessage = "Process execution request has been accepted"): 
    3029    """ 
    3130    Performs the common finishing up tasks for a processes dryRun method. 
    3231    """ 
    3332 
    34     _addCopyrightFileToDryrunFileset(fileSet) 
    35     writeMetadataFile(context, requestMetadata, dryRun=True) 
    36     processOutputs(context, fileSet, dryRun=True) 
     33    writeMetadataFile(context, requestMetadata, dryRun = True) 
     34    processOutputs(context, fileSet, dryRun = True) 
    3735    context.setStatus(STATUS.ACCEPTED, acceptedMessage , 0) 
     36 
    3837    updateJobDetailsAfterDryRun(context, duration) 
     38 
    3939 
    4040def makeMetadataFileItems(context, excludedMetadataInputs, cachable): 
     
    6666 
    6767     
    68 #---------------------------------------------------------------------------- 
    69 # This code would move to a common DDP module as it is used for multiple DDP processes. 
    70  
    71 def writeMetadataFile(context, metadataItems, fileprefix='metadata', format='xml', dryRun=False): 
    72     """ 
    73     Writes the given metadata items to a metadata file, either as 'xml' or plain text. Also  
    74     appends a FileSet object corresponding to the metadata file to the context['FileSet'] object. 
    75      
    76     if dryRun=True then no file will be written but and an estimated file size will be used to 
    77     create the FileSet object. 
    78      
    79     @param metadataItems: A sequence of (key, value) pairs. 
    80      
    81     """ 
    82     context.log.info("Writing metadata items: %s" % metadataItems) 
    83  
    84     metadata_file = '%s.%s' % (fileprefix, format) 
    85     metadata_path = os.path.join(context.outputDir, metadata_file) 
    86      
    87     lines = [] 
    88      
    89     if format == "xml": 
    90         lines.append("<UKCP09RequestDetails>\r\n") 
    91     else: 
    92         lines.append("UKCP09 Request Details:\r\n") 
    93  
    94     # These mapping should not be here but factoring them out would take time 
    95     # So, at least until launch they can stay here 
    96     # They are not identical to the ddp.utils.terminology_mapper stuff 
    97     key_map = {"TimeSlices": "TimePeriods", 
    98                "MeaningPeriod": "TemporalAverages", 
    99                "LocationType": "SpatialAverage"} 
    100      
    101     if metadataItems != None: 
    102         for (key, value) in metadataItems: 
    103  
    104             # Test if key should be mapped 
    105             if key in key_map.keys(): 
    106                 key = key_map[key] 
    107  
    108             if type(value) != type("string"): value = str(value) 
    109             value = value.replace(",", "") 
    110      
    111             if format == "xml": 
    112                 lines.append("    <%s>%s</%s>\r\n" % (key,value,key)) 
    113             else: 
    114                 lines.append("%s = %s\r\n" % (key, value)) 
    115  
    116     if format == "xml": 
    117         lines.append("</UKCP09RequestDetails>\r\n") 
    118  
    119      
    120     if not dryRun: 
    121         fout = open(metadata_path, 'w')  
    122         fout.writelines(lines) 
    123         fout.close() 
    124              
    125     fileSet = context.outputs['FileSet'] 
    126      
    127     if dryRun: 
    128         filesize = sum([len(s) for s in lines])         
    129     else: 
    130         filesize = os.stat(metadata_path)[stat.ST_SIZE] 
    131          
    132     fileSet.contents.append(FileSet(FLAG.DATA, metadata_file, filesize, 'metadata file')) 
    133  
    13468def processOutputs(context, fileSet, dryRun=False, keep=False): 
    13569    """ 
     
    14882        fileSet = dryRunZipFileSet(fileSet, context, maxFileVolume) 
    14983         
    150         #check that the fileset isn't too big 
     84        # check that the fileset isn't too big 
    15185        totalSize = sum([e.size for e in fileSet.contents]) 
    15286#        log.debug("Fileset size after zipping = %s" % (totalSize,)) 
     
    15892         
    15993    else: 
    160         fileSet = zipFileSet(fileSet, context, maxFileVolume, keep=keep) 
     94        fileSet = zipFileSet(fileSet, context, maxFileVolume, keep = keep) 
    16195     
    16296    return fileSet 
     
    229163    jobDetails['completion_date_time'] = completionDateTime.isoformat(' ') 
    230164     
    231 def _addCopyrightFileToDryrunFileset(fileSet): 
    232      
    233     (copyr_fname, copyr_fsize, copyr_finfo) = ukcp09_copyright_file_utils.getCopyrightFileDetailsForDryRun() 
    234     fileSet.contents.append(FileSet(FLAG.DATA, copyr_fname, copyr_fsize, copyr_finfo))     
    235      
  • cows_wps/trunk/process_modules/extract_uk_station_data.py

    r7014 r7016  
    117117            self._addFileToFileSet(df_path, "Station data file.", FLAG.DATA) 
    118118 
    119         context.setStatus(STATUS.COMPLETED, 'The End', 100) 
    120         completionTime = time.time() 
    121         process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime) 
     119#        context.setStatus(STATUS.COMPLETED, 'The End', 100) 
     120#        completionTime = time.time() 
     121#        process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime) 
     122        process_support.finishProcess(context, self.fileSet, startTime) 
    122123 
    123124 
Note: See TracChangeset for help on using the changeset viewer.