source: cows_wps/trunk/process_modules/ncdump_it.py @ 5985

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

lots of new bits.

Line 
1"""
2ncdump_it.py
3============
4
5"""
6
7import os, stat, time
8
9from cows_wps.process_handler.fileset import FileSet, FLAG
10import cows_wps.process_handler.ddp_process_support as ddp_process_support
11from cows_wps.process_handler.context.process_status import STATUS
12
13class NCDumpIt(object):
14
15    def __call__(self, context):
16       
17        startTime = time.time()
18        jobId = os.path.basename(context.processDir)
19
20        # Parse the inputs
21        Username = context.inputs['Username']
22        nc_file = context.inputs['FilePath']
23       
24        context.setStatus(STATUS.STARTED, 'Job is now running', 0)
25
26        # Always need a FileSet, even if empty
27        fileSet = context.outputs['FileSet'] = FileSet()
28
29        #MyOutput = "MY OUTPUT IS GREAT"
30        #context.outputs['ProcessSpecificContent'] = {"MyOutput": MyOutput}
31
32        ncdump_file = 'output-ncdump.txt'
33        ncdump_path = context.processDir + '/outputs/' + ncdump_file
34
35#        nc_file = "/disks/droplet1/hadrm3/data/HadRM3_PPE/nc/afixq/ape/afixqa.peo2sep.nc"
36#        eg_path = "/disks/droplet1/hadrm3/data/HadRM3_PPE/nc/afixq/ape/afixqa.peo2oct.nc"
37
38        if not os.path.isfile(nc_file):
39            raise Exception("The file path provided is not valid: %s" % nc_file)
40
41        os.system("/usr/local/bin/ncdump -h %s > %s" % (nc_file, ncdump_path))
42                   
43        context.log.info('Written output file: %s' % ncdump_path)
44        filesize = os.stat(ncdump_path)[stat.ST_SIZE]
45
46        fileSet = context.outputs['FileSet'] = FileSet()
47        fileSet.contents.append(FileSet(FLAG.DATA, ncdump_file, filesize, 'The only output'))
48
49        context.setStatus(STATUS.COMPLETED, 'The End', 100)
50       
51        completionTime = time.time()
52        ddp_process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
53
54
55    def dryRun(self, context):
56
57        # Not implemented for sync jobs
58        pass
Note: See TracBrowser for help on using the repository browser.