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

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

adding more good stuff for the midas extraction bits.

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, sys
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# NOTE ABOUT LOGGING:
20# You can log with the context.log object
21
22
23class 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        Username = context.inputs['Username']
31        MyInput = context.inputs['MyInput']
32       
33        context.setStatus(STATUS.STARTED, 'Job is now running', 0)
34
35        # Always need a FileSet, even if empty
36        fileSet = context.outputs['FileSet'] = FileSet()
37
38        MyOutput = "MY OUTPUT IS GREAT"
39        context.outputs['ProcessSpecificContent'] = {"MyOutput": MyOutput, "TryAnArray": [1, 3, 567]} 
40
41        MyFile = 'MyFile.txt'
42        MyFilePath = context.processDir + '/outputs/' + MyFile
43
44        fh = open(MyFilePath, 'w')
45        fh.write('You can write the input here if you like: %s.' % MyInput)
46        fh.close()
47
48        context.log.info('Written output file: %s' % MyFile)
49        filesize = os.stat(MyFilePath)[stat.ST_SIZE]
50
51        fileSet = context.outputs['FileSet'] = FileSet()
52        fileSet.contents.append(FileSet(FLAG.DATA, MyFile, filesize, 'The only output'))
53
54        context.setStatus(STATUS.COMPLETED, 'The End', 100)
55       
56        completionTime = time.time()
57        ddp_process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
58
59
60    def dryRun(self, context):
61
62        # Not implemented for sync jobs
63        pass
Note: See TracBrowser for help on using the repository browser.