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

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

more fixes and improvements

Line 
1"""
2process_template.py
3===================
4
5Process process_template that holds the ProcessTemplate class.
6
7"""
8
9# Standard library imports
10import os, stat, time
11
12# WPS imports
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
17# Import process-specific modules
18
19
20# Set up logger
21log = logging.getLogger(__name__)
22log.setLevel(logging.DEBUG)
23
24
25class ProcessTemplate(object):
26    def __call__(self, context):
27       
28        startTime = time.time()
29        jobId = os.path.basename(context.processDir)
30
31        # Parse the inputs
32        Username = context.inputs['Username']
33        MyInput = context.inputs['MyInput']
34       
35        context.setStatus(STATUS.STARTED, 'Job is now running', 0)
36
37        # Always need a FileSet, even if empty
38        fileSet = context.outputs['FileSet'] = FileSet()
39
40        MyOutput = "MY OUTPUT IS GREAT"
41        context.outputs['ProcessSpecificContent'] = {"MyOutput": MyOutput, "TryAnArray": [1, 3, 567]} 
42
43        MyFile = 'MyFile.txt'
44        MyFilePath = context.processDir + '/outputs/' + MyFile
45
46        fh = open(MyFilePath, 'w')
47        fh.write('You can write the input here if you like: %s.' % MyInput)
48        fh.close()
49
50        context.log.info('Written output file: %s' % MyFile)
51        filesize = os.stat(MyFilePath)[stat.ST_SIZE]
52
53        fileSet = context.outputs['FileSet'] = FileSet()
54        fileSet.contents.append(FileSet(FLAG.DATA, MyFile, filesize, 'The only output'))
55
56        context.setStatus(STATUS.COMPLETED, 'The End', 100)
57       
58        completionTime = time.time()
59        ddp_process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
60
61
62    def dryRun(self, context):
63
64        # Not implemented for sync jobs
65        pass
Note: See TracBrowser for help on using the repository browser.