Changeset 99:67a50fe6b39d

Show
Ignore:
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:
6 modified
1 copied

Legend:

Unmodified
Added
Removed
  • .todo

    r86 r99  
    11<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> 
    28    <note priority="medium" time="1224639946" done="1224726839"> 
    39        handle the quiet command line option.  need to figure out how to get the python logger to override the console handler. 
     
    1218        </comment> 
    1319    </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> 
    2020    <note priority="medium" time="1224639895"> 
    2121        create script to ram all the code into a single file to make it more like the original program 
    2222    </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> 
    2329</todo> 
  • AlertDevice.py

    r87 r99  
    8585                                (spot,state) = loc.split(',') 
    8686                        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) 
    8888                                sys.exit(3) 
    8989 
  • ExecutionAlertDevice.py

    r81 r99  
    4141 
    4242import subprocess 
     43import os 
    4344 
    4445from AlertDevice import * 
    4546 
    46 class MediaAlertDevice(AlertDevice): 
    47         def __init__(self,mediaInfo,alerts,areas): 
    48                 super(MediaAlertDevice,self).__init__(alerts,areas) 
    49                 self.__mediaInfo = mediaInfo 
     47class ExecutionAlertDevice(AlertDevice): 
     48        def __init__(self,exeInfo,alerts,areas): 
     49                super(ExecutionAlertDevice,self).__init__(alerts,areas) 
     50                self.__exeInfo = exeInfo 
    5051 
    5152        def display(self): 
     
    5354 
    5455        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__() 
    5859                return str 
    5960 
    6061        def send(self,alert): 
    6162                if(alert.type & ALERT): 
    62                         self._play(self.__mediaInfo.alert) 
     63                        self._execute(self.__exeInfo.alert,alert) 
    6364                if(alert.type & FORECAST): 
    64                         self._play(self.__mediaInfo.forecast) 
     65                        self._execute(self.__exeInfo.forecast,alert) 
    6566                if(alert.type & STATEMENT): 
    66                         self._play(self.__mediaInfo.statement) 
     67                        self._execute(self.__exeInfo.statement,alert) 
    6768                if(alert.type & ADVISORY): 
    68                         self._play(self.__mediaInfo.advisory) 
     69                        self._execute(self.__exeInfo.advisory,alert) 
    6970                if(alert.type & WATCH): 
    70                         self._play(self.__mediaInfo.watch) 
     71                        self._execute(self.__exeInfo.watch,alert) 
    7172                if(alert.type & WARNING): 
    72                         self._play(self.__mediaInfo.warning) 
     73                        self._execute(self.__exeInfo.warning,alert) 
    7374 
    74         def _play(self,file): 
     75        def _execute(self,exe,alert): 
    7576                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)) 
    8079                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)) 
    8281 
    83 class MediaAlertDeviceInfo(object): 
     82class ExecutionAlertDeviceInfo(object): 
    8483        def __init__(self): 
    85                 self.__player = None 
    8684                self.__forecast = None 
    8785                self.__statement = None 
     
    9088                self.__warning = None 
    9189                self.__alert = None 
    92  
    93         def setPlayer(self,player): 
    94                 self.__player = player 
    95  
    96         def getPlayer(self): 
    97                 return self.__player 
    9890 
    9991        def setAlert(self,alert): 
     
    133125                return self.__warning 
    134126 
    135         player = property(getPlayer,setPlayer,None) 
    136127        alert = property(getAlert,setAlert,None) 
    137128        forecast = property(getForecast,setForecast,None) 
     
    145136 
    146137        def __str__(self): 
    147                 str = "Media Info\n" 
    148  
    149                 if(self.player): 
    150                         str += "\tPlayer: " + self.player + "\n" 
     138                str = "Execution Info\n" 
    151139 
    152140                if(self.alert): 
  • MediaAlertDevice.py

    r81 r99  
    4141 
    4242import subprocess 
     43import os 
    4344 
    4445from AlertDevice import * 
  • StormConfig.py

    r92 r99  
    5151from MythtvAlertDevice import * 
    5252from SmsAlertDevice import * 
     53from ExecutionAlertDevice import * 
    5354 
    5455__APPNAME__ = "StormXmlSiren" 
     
    7576                jabberInfo          = JabberAlertDeviceInfo() 
    7677                mediaInfo           = MediaAlertDeviceInfo() 
     78                exeInfo             = ExecutionAlertDeviceInfo() 
    7779 
    7880                xstates = self.getRequired('main','states') 
     
    101103                mediaInfo.warning = self.get('media','warning') 
    102104                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') 
    103112 
    104113                for i in range(1,int(num_watchers)+1): 
     
    131140                                if(dev == "media"): 
    132141                                        self.devices.append(MediaAlertDevice(mediaInfo,alerts,areas)) 
     142                                if(dev == "execution"): 
     143                                        self.devices.append(ExecutionAlertDevice(exeInfo,alerts,areas)) 
    133144 
    134145        def __str__(self): 
  • WeatherAlert.py

    r82 r99  
    8686                return self.cap_item.type 
    8787 
     88        def getState(self): 
     89                return self.cap_item.state 
     90 
     91        def getCounty(self): 
     92                return self.cap_item.county 
     93 
    8894        id = property(getId,None,None) 
    8995        event = property(getEvent,None,None) 
    9096        type = property(getType,None,None) 
     97        state = property(getState,None,None) 
     98        county = property(getCounty,None,None) 
    9199 
    92100        area = property(getArea,None,None) 
  • examples/StormXmlSiren.conf

    r94 r99  
    11[main] 
    22states = TX,TN 
    3 watchers = 13 
     3watchers = 14 
    44history=100 
    55 
     
    2525warning = spinout.wav 
    2626 
    27 [1] 
     27[execution] 
     28forecast = /home/cfreeze/bin/weather/forecast.sh 
     29statement = /home/cfreeze/bin/weather/statement.sh 
     30advisory = /home/cfreeze/bin/weather/advisory.sh 
     31watch = /home/cfreeze/bin/weather/watch.sh 
     32warning = /home/cfreeze/bin/weather/warning.sh 
     33 
     34[14] 
    2835device = mythtv 
    2936to = 192.168.9.240:6948 
     
    102109[13] 
    103110device = media 
     111alert = watch,warning 
     112areas = Rockwall,TX:Warren,TN 
     113 
     114[14] 
     115device = execution 
     116#alert = watch,warning 
    104117alert = 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 
     119areas = 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