Changeset 142:814d4a3c6ca0
- Timestamp:
- 11/09/08 03:04:44 (3 years ago)
- Author:
- chris
- Branch:
- unix
- Message:
-
Added support for using a proxy to get files from weather.gov. In the [main] section a keyword called 'proxy' can be used. The form should be ' http://proxy.example.com:3128' for example.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r141
|
r142
|
|
| 27 | 27 | create script to ram all the code into a single file to make it more like the original program |
| 28 | 28 | </note> |
| 29 | | <note priority="medium" time="1226198990"> |
| | 29 | <note priority="medium" time="1226198990" done="1226199792"> |
| 30 | 30 | allow use of a proxy to fetch the xml files |
| | 31 | <comment> |
| | 32 | Added support, new config in [main] section called 'proxy' |
| | 33 | </comment> |
| 31 | 34 | </note> |
| 32 | 35 | </todo> |
-
|
r122
|
r142
|
|
| 65 | 65 | self.log = logging.getLogger('StormConfig') |
| 66 | 66 | self.__max_history = History.DEFAULT_MAX_HISTORICAL_EVENTS |
| | 67 | self.__proxy = '' |
| 67 | 68 | |
| 68 | 69 | super(StormConfig,self).__init__(__APPNAME__,config_file, log_config_file) |
| … |
… |
|
| 85 | 86 | |
| 86 | 87 | xstates = self.getRequired('main','states') |
| 87 | | if xstates: |
| | 88 | if(xstates): |
| 88 | 89 | self.__states = string.split(xstates, ',') |
| | 90 | |
| | 91 | self.__proxy = self.get('main','proxy', None) |
| 89 | 92 | |
| 90 | 93 | num_watchers = self.getRequired('main','watchers') |
| … |
… |
|
| 174 | 177 | str += "\n\t".join(self.__states) |
| 175 | 178 | |
| | 179 | str += "\nProxy: %i\n" % self.__proxy |
| 176 | 180 | str += "\nHistory: %i\n" % self.max_history |
| 177 | 181 | str += "\nDevices: %i\n" % len(self.devices) |
| … |
… |
|
| 219 | 223 | return self.__max_history |
| 220 | 224 | |
| | 225 | def getProxy(self): |
| | 226 | return self.__proxy |
| | 227 | |
| 221 | 228 | debug = property(getDebug,None,None) |
| 222 | 229 | max_history = property(getMaxHistory,None,None) |
| | 230 | proxy = property(getProxy,None,None) |
-
|
r122
|
r142
|
|
| 51 | 51 | |
| 52 | 52 | class StormWeather(XmlWeather): |
| 53 | | def __init__(self, state, history, simfetch = False, simalert = False): |
| 54 | | super(StormWeather,self).__init__(state,history,simfetch) |
| | 53 | def __init__(self, state, history, simfetch = False, simalert = False, proxy = None): |
| | 54 | super(StormWeather,self).__init__(state,history,simfetch,proxy) |
| 55 | 55 | self.log = logging.getLogger("StormWeather") |
| 56 | 56 | self.__alert_devs = [] |
-
|
r122
|
r142
|
|
| 51 | 51 | |
| 52 | 52 | class XmlWeather(object): |
| 53 | | def __init__(self, state, history, simfetch = False): |
| | 53 | def __init__(self, state, history, simfetch = False, proxy = None): |
| 54 | 54 | super(XmlWeather,self).__init__() |
| 55 | 55 | self.__data = '' |
| … |
… |
|
| 62 | 62 | self.__history = history |
| 63 | 63 | self.__simfetch = simfetch |
| | 64 | self.__proxy = proxy |
| 64 | 65 | self.log = logging.getLogger("XmlWeather") |
| 65 | 66 | |
| … |
… |
|
| 78 | 79 | self.__dom = minidom.parse("examples/" + self.__state.lower() + ".cap") |
| 79 | 80 | else: |
| 80 | | self.__dom = minidom.parse(urllib.urlopen(self.__url)) |
| | 81 | proxy = None |
| | 82 | if(self.__proxy): |
| | 83 | self.log.info("Using proxy: %s" % self.__proxy) |
| | 84 | proxy = { 'http' : self.__proxy } |
| | 85 | self.__dom = minidom.parse(urllib.urlopen(self.__url, proxies = proxy)) |
| 81 | 86 | except IOError,e: |
| 82 | 87 | # No net connection available, exit. |
-
|
r135
|
r142
|
|
| 115 | 115 | for state in conf.states: |
| 116 | 116 | log.info("State: " + state) |
| 117 | | xw = StormWeather(state,history,options.simfetch,options.simalert) |
| | 117 | xw = StormWeather(state,history,options.simfetch,options.simalert,conf.proxy) |
| 118 | 118 | #xw.display() |
| 119 | 119 | for dev in conf.devices: |