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

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

removed Username from code

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        Counties = context.inputs.get('Counties', [])
32        if Counties == []:
33            BBox = context.inputs.get("BBox", None)
34            if BBox == None:
35                raise Exception("Invalid arguments provided. Must provide either a geographical bounding box or a list of counties.")
36
37        DataTypes = context.inputs.get("DataTypes", [])
38        StartDateTime = context.inputs['StartDateTime']
39        StartDateTime = gws_utils.revertDateTimeToLongString(StartDateTime)
40        log.warn("DATE TIME: %s, type = %s" % (StartDateTime, type(StartDateTime)))
41        EndDateTime = context.inputs['EndDateTime']
42        EndDateTime = gws_utils.revertDateTimeToLongString(EndDateTime)
43       
44        context.setStatus(STATUS.STARTED, 'Job is now running', 0)
45
46        # Always need a FileSet, even if empty
47        fileSet = context.outputs['FileSet'] = FileSet()
48
49        # Make path to output file
50        WFile = 'weather_stations.txt'
51        MyFilePath = context.processDir + '/outputs/' + WFile
52
53        # Call code to get Weather Stations
54        station_list = gws_utils.getStationList(Counties, BBox, DataTypes, StartDateTime,
55                           EndDateTime, MyFilePath)
56
57        context.outputs['ProcessSpecificContent'] = {
58                                    "WeatherStations": " ".join(station_list)} 
59
60        context.log.info('Written output file: %s' % WFile)
61        filesize = os.stat(MyFilePath)[stat.ST_SIZE]
62
63        fileSet = context.outputs['FileSet'] = FileSet()
64        fileSet.contents.append(FileSet(FLAG.DATA, WFile, filesize, 'Weather Stations File'))
65
66        context.setStatus(STATUS.COMPLETED, 'The End', 100)
67       
68        completionTime = time.time()
69        ddp_process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
70
71
72    def dryRun(self, context):
73
74        self.fileSet = context.outputs['FileSet'] = FileSet()
75        self.fileSet.contents.append(FileSet(FLAG.DATA, "testfile.txt", 30000, "Some file"))
76       
77        ddp_process_support.finishDryRun(context, [("meta", "data")], self.fileSet,
78                                         60, acceptedMessage='Dry run complete')
79 
Note: See TracBrowser for help on using the repository browser.