source: cows_wps/trunk/process_modules/process_template.py @ 6948

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

removed Username from code

RevLine 
[5960]1"""
[6106]2process_template.py
3===================
[5960]4
[6106]5Process process_template that holds the ProcessTemplate class.
[5960]6
7"""
8
[6116]9# Standard library imports
[6124]10import os, stat, time, sys
[5960]11
[6116]12# WPS imports
[5960]13from cows_wps.process_handler.fileset import FileSet, FLAG
14import cows_wps.process_handler.ddp_process_support as ddp_process_support
15from cows_wps.process_handler.context.process_status import STATUS
16
[6116]17# Import process-specific modules
[6106]18
[6124]19# NOTE ABOUT LOGGING:
20# You can log with the context.log object
[6116]21
22
[6106]23class ProcessTemplate(object):
[5960]24    def __call__(self, context):
25       
26        startTime = time.time()
27        jobId = os.path.basename(context.processDir)
28
29        # Parse the inputs
[5985]30        MyInput = context.inputs['MyInput']
[5960]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"
[5985]38        context.outputs['ProcessSpecificContent'] = {"MyOutput": MyOutput, "TryAnArray": [1, 3, 567]} 
[5960]39
40        MyFile = 'MyFile.txt'
41        MyFilePath = context.processDir + '/outputs/' + MyFile
42
43        fh = open(MyFilePath, 'w')
[5985]44        fh.write('You can write the input here if you like: %s.' % MyInput)
[5960]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        ddp_process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
57
58
59    def dryRun(self, context):
60
61        # Not implemented for sync jobs
62        pass
Note: See TracBrowser for help on using the repository browser.