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

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

Added some templates.

Line 
1"""
2MY_MODULE.py
3============
4
5Process MY_MODULE that does MY_DESCRIPTION.
6
7"""
8
9import os, stat, time
10
11from cows_wps.process_handler.fileset import FileSet, FLAG
12import cows_wps.process_handler.ddp_process_support as ddp_process_support
13from cows_wps.process_handler.context.process_status import STATUS
14
15class MyProcess(object):
16    def __call__(self, context):
17       
18        startTime = time.time()
19        jobId = os.path.basename(context.processDir)
20
21        # Parse the inputs
22        Username = context.inputs['Username']
23        MyArgument = context.inputs['MyArgument']
24       
25        context.setStatus(STATUS.STARTED, 'Job is now running', 0)
26
27        # Always need a FileSet, even if empty
28        fileSet = context.outputs['FileSet'] = FileSet()
29
30        MyOutput = "MY OUTPUT IS GREAT"
31        context.outputs['ProcessSpecificContent'] = {"MyOutput": MyOutput} 
32
33        MyFile = 'MyFile.txt'
34        MyFilePath = context.processDir + '/outputs/' + MyFile
35
36        fh = open(MyFilePath, 'w')
37        fh.write('You can write anything in MyFile.')
38        fh.close()
39
40        context.log.info('Written output file: %s' % MyFile)
41        filesize = os.stat(MyFilePath)[stat.ST_SIZE]
42
43        fileSet = context.outputs['FileSet'] = FileSet()
44        fileSet.contents.append(FileSet(FLAG.DATA, MyFile, filesize, 'The only output'))
45
46        context.setStatus(STATUS.COMPLETED, 'The End', 100)
47       
48        completionTime = time.time()
49        ddp_process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
50
51
52    def dryRun(self, context):
53
54        # Not implemented for sync jobs
55        pass
Note: See TracBrowser for help on using the repository browser.