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

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

fixed

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