Changeset 99:67a50fe6b39d
- Timestamp:
- 10/25/08 00:01:07 (3 years ago)
- Author:
- chris
- Branch:
- unix
- Message:
-
added a generic execution device type that will allow others to script in extensions to StormXmlSiren.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r86
|
r99
|
|
| 1 | 1 | <todo version="0.1.19"> |
| | 2 | <note priority="medium" time="1224639856" done="1224727536"> |
| | 3 | handle the log configuration file override from the command line |
| | 4 | <comment> |
| | 5 | finished adding code to handle --logconf command line option |
| | 6 | </comment> |
| | 7 | </note> |
| 2 | 8 | <note priority="medium" time="1224639946" done="1224726839"> |
| 3 | 9 | handle the quiet command line option. need to figure out how to get the python logger to override the console handler. |
| … |
… |
|
| 12 | 18 | </comment> |
| 13 | 19 | </note> |
| 14 | | <note priority="medium" time="1224639856" done="1224727536"> |
| 15 | | handle the log configuration file override from the command line |
| 16 | | <comment> |
| 17 | | finished adding code to handle --logconf command line option |
| 18 | | </comment> |
| 19 | | </note> |
| 20 | 20 | <note priority="medium" time="1224639895"> |
| 21 | 21 | create script to ram all the code into a single file to make it more like the original program |
| 22 | 22 | </note> |
| | 23 | <note priority="medium" time="1224891222" done="1224892822"> |
| | 24 | create a new generic execution device that will invoke programs on the command line with certain arguments like id, alert type, area, etc.. |
| | 25 | <comment> |
| | 26 | done |
| | 27 | </comment> |
| | 28 | </note> |
| 23 | 29 | </todo> |
-
|
r87
|
r99
|
|
| 85 | 85 | (spot,state) = loc.split(',') |
| 86 | 86 | except Exception,e: |
| 87 | | self.log.error("Unable to parse location in [%s]" % loc) |
| | 87 | self.log.error("Unable to parse location in [%s]" % areas) |
| 88 | 88 | sys.exit(3) |
| 89 | 89 | |
-
|
r81
|
r99
|
|
| 41 | 41 | |
| 42 | 42 | import subprocess |
| | 43 | import os |
| 43 | 44 | |
| 44 | 45 | from AlertDevice import * |
| 45 | 46 | |
| 46 | | class MediaAlertDevice(AlertDevice): |
| 47 | | def __init__(self,mediaInfo,alerts,areas): |
| 48 | | super(MediaAlertDevice,self).__init__(alerts,areas) |
| 49 | | self.__mediaInfo = mediaInfo |
| | 47 | class ExecutionAlertDevice(AlertDevice): |
| | 48 | def __init__(self,exeInfo,alerts,areas): |
| | 49 | super(ExecutionAlertDevice,self).__init__(alerts,areas) |
| | 50 | self.__exeInfo = exeInfo |
| 50 | 51 | |
| 51 | 52 | def display(self): |
| … |
… |
|
| 53 | 54 | |
| 54 | 55 | def __str__(self): |
| 55 | | str = "MediaAlertDevice\n" + \ |
| 56 | | self.__mediaInfo.__str__() + \ |
| 57 | | super(MediaAlertDevice,self).__str__() |
| | 56 | str = "ExecutionAlertDevice\n" + \ |
| | 57 | self.__exeInfo.__str__() + \ |
| | 58 | super(ExecutionAlertDevice,self).__str__() |
| 58 | 59 | return str |
| 59 | 60 | |
| 60 | 61 | def send(self,alert): |
| 61 | 62 | if(alert.type & ALERT): |
| 62 | | self._play(self.__mediaInfo.alert) |
| | 63 | self._execute(self.__exeInfo.alert,alert) |
| 63 | 64 | if(alert.type & FORECAST): |
| 64 | | self._play(self.__mediaInfo.forecast) |
| | 65 | self._execute(self.__exeInfo.forecast,alert) |
| 65 | 66 | if(alert.type & STATEMENT): |
| 66 | | self._play(self.__mediaInfo.statement) |
| | 67 | self._execute(self.__exeInfo.statement,alert) |
| 67 | 68 | if(alert.type & ADVISORY): |
| 68 | | self._play(self.__mediaInfo.advisory) |
| | 69 | self._execute(self.__exeInfo.advisory,alert) |
| 69 | 70 | if(alert.type & WATCH): |
| 70 | | self._play(self.__mediaInfo.watch) |
| | 71 | self._execute(self.__exeInfo.watch,alert) |
| 71 | 72 | if(alert.type & WARNING): |
| 72 | | self._play(self.__mediaInfo.warning) |
| | 73 | self._execute(self.__exeInfo.warning,alert) |
| 73 | 74 | |
| 74 | | def _play(self,file): |
| | 75 | def _execute(self,exe,alert): |
| 75 | 76 | try: |
| 76 | | if(file): |
| 77 | | subprocess.Popen([self.__mediaInfo.player,file]).wait() |
| 78 | | else: |
| 79 | | print "Can not play alert media: (%s) not found" % file |
| | 77 | subprocess.Popen([exe,alert.id,WeatherTypes.toString(alert.type),alert.state,alert.county]).wait() |
| | 78 | self.log.info("Executing: [%s %s %s %s %s]" % (exe,alert.id,WeatherTypes.toString(alert.type),alert.state,alert.county)) |
| 80 | 79 | except os.error: |
| 81 | | print "Problem trying to play: " + file |
| | 80 | self.log.error("Problem Executing: [%s %s %s %s %s]" % (exe,alert.id,WeatherTypes.toString(alert.type),alert.state,alert.county)) |
| 82 | 81 | |
| 83 | | class MediaAlertDeviceInfo(object): |
| | 82 | class ExecutionAlertDeviceInfo(object): |
| 84 | 83 | def __init__(self): |
| 85 | | self.__player = None |
| 86 | 84 | self.__forecast = None |
| 87 | 85 | self.__statement = None |
| … |
… |
|
| 90 | 88 | self.__warning = None |
| 91 | 89 | self.__alert = None |
| 92 | | |
| 93 | | def setPlayer(self,player): |
| 94 | | self.__player = player |
| 95 | | |
| 96 | | def getPlayer(self): |
| 97 | | return self.__player |
| 98 | 90 | |
| 99 | 91 | def setAlert(self,alert): |
| … |
… |
|
| 133 | 125 | return self.__warning |
| 134 | 126 | |
| 135 | | player = property(getPlayer,setPlayer,None) |
| 136 | 127 | alert = property(getAlert,setAlert,None) |
| 137 | 128 | forecast = property(getForecast,setForecast,None) |
| … |
… |
|
| 145 | 136 | |
| 146 | 137 | def __str__(self): |
| 147 | | str = "Media Info\n" |
| 148 | | |
| 149 | | if(self.player): |
| 150 | | str += "\tPlayer: " + self.player + "\n" |
| | 138 | str = "Execution Info\n" |
| 151 | 139 | |
| 152 | 140 | if(self.alert): |
-
|
r81
|
r99
|
|
| 41 | 41 | |
| 42 | 42 | import subprocess |
| | 43 | import os |
| 43 | 44 | |
| 44 | 45 | from AlertDevice import * |
-
|
r92
|
r99
|
|
| 51 | 51 | from MythtvAlertDevice import * |
| 52 | 52 | from SmsAlertDevice import * |
| | 53 | from ExecutionAlertDevice import * |
| 53 | 54 | |
| 54 | 55 | __APPNAME__ = "StormXmlSiren" |
| … |
… |
|
| 75 | 76 | jabberInfo = JabberAlertDeviceInfo() |
| 76 | 77 | mediaInfo = MediaAlertDeviceInfo() |
| | 78 | exeInfo = ExecutionAlertDeviceInfo() |
| 77 | 79 | |
| 78 | 80 | xstates = self.getRequired('main','states') |
| … |
… |
|
| 101 | 103 | mediaInfo.warning = self.get('media','warning') |
| 102 | 104 | mediaInfo.alert = self.get('media','alert') |
| | 105 | |
| | 106 | exeInfo.forecast = self.get('execution','forecast') |
| | 107 | exeInfo.statement = self.get('execution','statement') |
| | 108 | exeInfo.advisory = self.get('execution','advisory') |
| | 109 | exeInfo.watch = self.get('execution','watch') |
| | 110 | exeInfo.warning = self.get('execution','warning') |
| | 111 | exeInfo.alert = self.get('execution','alert') |
| 103 | 112 | |
| 104 | 113 | for i in range(1,int(num_watchers)+1): |
| … |
… |
|
| 131 | 140 | if(dev == "media"): |
| 132 | 141 | self.devices.append(MediaAlertDevice(mediaInfo,alerts,areas)) |
| | 142 | if(dev == "execution"): |
| | 143 | self.devices.append(ExecutionAlertDevice(exeInfo,alerts,areas)) |
| 133 | 144 | |
| 134 | 145 | def __str__(self): |
-
|
r82
|
r99
|
|
| 86 | 86 | return self.cap_item.type |
| 87 | 87 | |
| | 88 | def getState(self): |
| | 89 | return self.cap_item.state |
| | 90 | |
| | 91 | def getCounty(self): |
| | 92 | return self.cap_item.county |
| | 93 | |
| 88 | 94 | id = property(getId,None,None) |
| 89 | 95 | event = property(getEvent,None,None) |
| 90 | 96 | type = property(getType,None,None) |
| | 97 | state = property(getState,None,None) |
| | 98 | county = property(getCounty,None,None) |
| 91 | 99 | |
| 92 | 100 | area = property(getArea,None,None) |
-
|
r94
|
r99
|
|
| 1 | 1 | [main] |
| 2 | 2 | states = TX,TN |
| 3 | | watchers = 13 |
| | 3 | watchers = 14 |
| 4 | 4 | history=100 |
| 5 | 5 | |
| … |
… |
|
| 25 | 25 | warning = spinout.wav |
| 26 | 26 | |
| 27 | | [1] |
| | 27 | [execution] |
| | 28 | forecast = /home/cfreeze/bin/weather/forecast.sh |
| | 29 | statement = /home/cfreeze/bin/weather/statement.sh |
| | 30 | advisory = /home/cfreeze/bin/weather/advisory.sh |
| | 31 | watch = /home/cfreeze/bin/weather/watch.sh |
| | 32 | warning = /home/cfreeze/bin/weather/warning.sh |
| | 33 | |
| | 34 | [14] |
| 28 | 35 | device = mythtv |
| 29 | 36 | to = 192.168.9.240:6948 |
| … |
… |
|
| 102 | 109 | [13] |
| 103 | 110 | device = media |
| | 111 | alert = watch,warning |
| | 112 | areas = Rockwall,TX:Warren,TN |
| | 113 | |
| | 114 | [14] |
| | 115 | device = execution |
| | 116 | #alert = watch,warning |
| 104 | 117 | alert = forecast,statement,advisory,watch,warning |
| 105 | | areas = Rockwall,TX:Collin,TX:Dallas,TX:Kaufman,TX:Hunt,TX:McMinnville,TN:Warren,TN:Cannon,TN:Coffee,TN:Grundy,TN:Sequatchie,TN:Van Buren,TN:White,TN:Dekalb,TN |
| | 118 | #areas = Rockwall,TX:Warren,TN |
| | 119 | areas = Rockwall,TX:Collin,TX:Dallas,TX:Kaufman,TX:Hunt,TX:McMinnville,TN:Warren,TN:Cannon,TN:Coffee,TN:Grundy,TN:Sequatchie,TN:Van Buren,TN:White,TN:Dekalb,TN:Galveston,TX |