source: cows_wps/trunk/process_modules/get_weather_stations.py @ 6921

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/process_modules/get_weather_stations.py@6921
Revision 6921, 2.8 KB checked in by astephen, 10 years ago (diff)

updated processes

Line 
1"""
2get_weather_stations.py
3===================
4
5Process get_weather_stations that holds the GetWeatherStations class.
6
7"""
8
9import os, stat, time
10import sys
11import logging
12
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
17import process_modules.lib_get_weather_stations.utils as gws_utils
18
19
20log = logging.getLogger(__name__)
21log.setLevel(logging.DEBUG)
22
23
24class GetWeatherStations(object):
25    def __call__(self, context):
26       
27        startTime = time.time()
28        jobId = os.path.basename(context.processDir)
29
30        # Parse the inputs
31        Username = context.inputs['Username']
32        Counties = context.inputs.get('Counties', [])
33        if Counties == []:
34            BBox = context.inputs.get("BBox", None)
35            if BBox == None:
36                raise Exception("Invalid arguments provided. Must provide either a geographical bounding box or a list of counties.")
37
38        DataTypes = context.inputs.get("DataTypes", [])
39        StartDateTime = context.inputs['StartDateTime']
40        StartDateTime = gws_utils.revertDateTimeToLongString(StartDateTime)
41        log.warn("DATE TIME: %s, type = %s" % (StartDateTime, type(StartDateTime)))
42        EndDateTime = context.inputs['EndDateTime']
43        EndDateTime = gws_utils.revertDateTimeToLongString(EndDateTime)
44       
45        context.setStatus(STATUS.STARTED, 'Job is now running', 0)
46
47        # Always need a FileSet, even if empty
48        fileSet = context.outputs['FileSet'] = FileSet()
49
50        # Make path to output file
51        WFile = 'weather_stations.txt'
52        MyFilePath = context.processDir + '/outputs/' + WFile
53
54        # Call code to get Weather Stations
55        station_list = gws_utils.getStationList(Counties, BBox, DataTypes, StartDateTime,
56                           EndDateTime, MyFilePath)
57
58        context.outputs['ProcessSpecificContent'] = {
59                                    "WeatherStations": " ".join(station_list)} 
60
61        context.log.info('Written output file: %s' % WFile)
62        filesize = os.stat(MyFilePath)[stat.ST_SIZE]
63
64        fileSet = context.outputs['FileSet'] = FileSet()
65        fileSet.contents.append(FileSet(FLAG.DATA, WFile, filesize, 'Weather Stations File'))
66
67        context.setStatus(STATUS.COMPLETED, 'The End', 100)
68       
69        completionTime = time.time()
70        ddp_process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
71
72
73    def dryRun(self, context):
74
75        self.fileSet = context.outputs['FileSet'] = FileSet()
76        self.fileSet.contents.append(FileSet(FLAG.DATA, "testfile.txt", 30000, "Some file"))
77       
78        ddp_process_support.finishDryRun(context, [("meta", "data")], self.fileSet,
79                                         60, acceptedMessage='Dry run complete')
80 
Note: See TracBrowser for help on using the repository browser.