Changeset 187:b82b5be8e615

Show
Ignore:
Timestamp:
11/28/08 18:18:12 (3 years ago)
Author:
chris@…
Branch:
default
Parents:
186:fdaf10ceded4 (diff), 183:1e15754ebd2a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

moving the CAP 1.1 work in the default branch

Files:
9 removed
19 modified

Legend:

Unmodified
Added
Removed
  • .hgignore

    r161 r187  
    44*.elc 
    55*-orig 
     6*-rej 
    67*.swp 
    78.*.swp 
  • .hgignore

    r45 r187  
    33 
    44*.elc 
     5*-orig 
     6*-rej 
    57*.swp 
    68.*.swp 
  • StormSiren/AlertDevice.py

    r170 r187  
    5959                self.log = logging.getLogger('AlertDevice') 
    6060 
     61                self.log.setLevel(logging.INFO) 
    6162                self.__parse_weather_types(alerts) 
    6263                self.__parse_areas(areas) 
  • StormSiren/AlertDevice.py

    r184 r187  
    136136                return False 
    137137 
    138         def isCountyWanted(self,state,county): 
     138        def isAreaWanted(self,state,alert_areas): 
    139139                if(self.__areas.has_key(state)): 
    140                         if(county.lower() in self.__areas[state]): 
    141                                 return True 
     140                        for area in alert_areas: 
     141                                self.log.debug("checking if %s is in (%s)" % (area.lower(),self.__areas[state])) 
     142                                if(area.lower() in self.__areas[state]): 
     143                                        self.log.debug("%s IS IN (%s)" % (area.lower(),self.__areas[state])) 
     144                                        return True 
    142145                return False 
    143146 
     
    146149                if(self.isTypeWanted(cap_alert.type) and self.isStateWanted(cap_alert.state)): 
    147150                        self.log.debug("Testing[%s]: type and state match(%s/%i)" % (cap_alert.id, cap_alert.state, cap_alert.type)) 
    148                         if(self.isCountyWanted(cap_alert.state, cap_alert.county)): 
    149                                 self.log.info("Alert hit on county[%s/%s]: %s" % (cap_alert.county, cap_alert.state, cap_alert.id)) 
     151                        if(self.isAreaWanted(cap_alert.state, cap_alert.areas)): 
     152                                self.log.debug("Alert hit on area[%s/%s]: %s" % (cap_alert.state, cap_alert.id, cap_alert.areas)) 
    150153                                return True 
    151154                        else: 
    152                                 for loc in self.__areas[cap_alert.state]: 
    153                                         if(cap_alert.isLocationInDesc(loc)): 
    154                                                 self.log.info("Alert hit on location[%s/%s]: %s" % (loc, cap_alert.state, cap_alert.id)) 
    155                                                 return True 
     155                                self.log.debug("Testing[%s]: alert not in watched area(%s/%s)" % (cap_alert.id, cap_alert.state, cap_alert.areas)) 
     156                else: 
     157                        self.log.debug("Testing[%s]: Either wrong type or state (%s/%i)" % (cap_alert.id, cap_alert.state, cap_alert.type)) 
    156158                return False 
    157159#CODE END 
  • StormSiren/ExecutionAlertDevice.py

    r177 r187  
    5151                super(ExecutionAlertDevice,self).__init__(alerts,areas) 
    5252                self.__exeInfo = exeInfo 
     53                self.log = logging.getLogger('ExecutionAlertDevice') 
     54                self.log.setLevel(logging.DEBUG) 
    5355 
    5456        def display(self): 
  • StormSiren/ExecutionAlertDevice.py

    r184 r187  
    7979        def _execute(self,exe,alert): 
    8080                try: 
    81                         subprocess.Popen([exe,alert.id,WeatherTypes.toString(alert.type),alert.state,alert.county]).wait() 
    82                         self.log.info("Executing: [%s %s %s %s %s]" % (exe,alert.id,WeatherTypes.toString(alert.type),alert.state,alert.county)) 
     81                        subprocess.Popen([exe,alert.id,"\"" + WeatherTypes.toString(alert.type) + "\"",alert.state,"\"" + alert.getAreas() + "\""]).wait() 
     82                        self.log.info("Executing: [%s %s %s %s %s]" % (exe,alert.id,"\"" + WeatherTypes.toString(alert.type) + "\"",alert.state,"\"" + alert.getAreas() + "\"")) 
    8383                except os.error: 
    84                         self.log.error("Problem Executing: [%s %s %s %s %s]" % (exe,alert.id,WeatherTypes.toString(alert.type),alert.state,alert.county)) 
     84                        self.log.error("Problem Executing: [%s %s %s %s %s]" % (exe,alert.id,"\"" + WeatherTypes.toString(alert.type),alert.state,"\"" + alert.getAreas() + "\"")) 
    8585 
    8686class ExecutionAlertDeviceInfo(object): 
  • StormSiren/JabberAlertDevice.py

    r181 r187  
    4949        pass 
    5050 
    51  
    5251from AlertDevice import * 
    5352 
     
    6160                self.__to = to 
    6261                self.a = alerts 
     62                self.log = logging.getLogger('JabberAlertDevice') 
     63 
     64                self.log.setLevel(logging.INFO) 
    6365 
    6466        def display(self): 
  • StormSiren/JabberAlertDevice.py

    r184 r187  
    9696                        self.log.warn("Warning: unable to perform SASL auth os %s. Old authentication method used!" % jid) 
    9797 
    98                 cl.send(xmpp.protocol.Message(self.to,alert.detailed,None, alert.event + "(" + alert.area + ")")) 
     98                cl.send(xmpp.protocol.Message(self.to,alert.detailed,None, alert.headline + "(" + alert.getAreas() + ")")) 
    9999 
    100100class JabberAlertDeviceInfo(object): 
  • StormSiren/SmsAlertDevice.py

    r180 r187  
    4747        def __init__(self, to, textwidth, smtpInfo, alerts, areas): 
    4848                super(SmsAlertDevice,self).__init__(to, textwidth, smtpInfo, alerts, areas) 
     49                self.log = logging.getLogger('SmsAlertDevice') 
     50 
     51                self.log.setLevel(logging.INFO) 
    4952         
    5053        def display(self): 
  • StormSiren/SmsAlertDevice.py

    r184 r187  
    6060 
    6161        def send(self,alert): 
    62                 self.email(alert.terse,alert.event) 
     62                self.email(alert.terse,alert.headline) 
    6363                self.log.info('Paged ' + self.to + ' on bulletin ' + alert.id) 
  • StormSiren/StormConfig.py

    r176 r187  
    5959 
    6060class StormConfig(Config): 
    61         def __init__(self, config_file = None, log_config_file = None): 
     61        def __init__(self, config_file = None): 
     62                super(StormConfig,self).__init__(__APPNAME__,config_file) 
     63 
    6264                self.__states          = [] 
    6365                self.devices           = [] 
    64                 self.__history_file    = '' 
     66                self.__history_file  = self.config_dir + '/' + __APPNAME__ + '.history' 
    6567                self.log               = logging.getLogger('StormConfig') 
    6668                self.__max_history     = History.DEFAULT_MAX_HISTORICAL_EVENTS 
    6769                self.__proxy           = '' 
    6870 
    69                 super(StormConfig,self).__init__(__APPNAME__,config_file, log_config_file) 
    70  
    71                 self.__history_file  = self.config_dir + '/' + __APPNAME__ + '.history' 
     71                self.log.setLevel(logging.DEBUG) 
     72                self._load() 
    7273 
    7374        def _load(self): 
     
    121122 
    122123                for i in range(1,int(num_watchers)+1): 
    123                                 dev = self.getRequired(str(i),"device") 
    124                                 alerts = self.getRequired(str(i),"alert") 
    125                                 areas = self.getRequired(str(i),"areas") 
    126  
    127                                 if(dev == "email"): 
    128                                         to = self.getRequired(str(i),"to") 
    129                                         textwidth = int(self.get(str(i),"textwidth",-1)) 
    130                                         self.devices.append(EmailAlertDevice(to,textwidth,smtpInfo,alerts,areas)) 
    131                                 if(dev == "sms"): 
    132                                         to = self.getRequired(str(i),"to") 
    133                                         textwidth = int(self.get(str(i),"textwidth",-1)) 
    134                                         self.devices.append(SmsAlertDevice(to,textwidth,smtpInfo,alerts,areas)) 
    135                                 if(dev == "jabber"): 
    136                                         if(not jabberLoadAttempted): 
    137                                                 jabber_available = self.__loadXmpp() 
    138                                                 jabberLoadAttempted = True 
    139  
    140                                         if(jabber_available): 
    141                                                 to = self.getRequired(str(i),"to") 
    142                                                 self.devices.append(JabberAlertDevice(to,jabberInfo,alerts,areas)) 
    143                                         else: 
    144                                                 self.log.error("Jabber Support Not Enabled, but Jabber Device Requested!") 
    145                                 if(dev == "osd"): 
    146                                         if(not osdLoadAttempted): 
    147                                                 osd_available = self.__loadOsd() 
    148                                                 osdLoadAttempted = True 
    149  
    150                                         if(osd_available): 
    151                                                 position = self.get(str(i),"position", DEFAULT_OSD_POSITION) 
    152                                                 alignment = self.get(str(i),"alignment", DEFAULT_OSD_ALIGNMENT) 
    153                                                 offset = int(self.get(str(i),"offset", DEFAULT_OSD_OFFSET)) 
    154                                                 timeout = int(self.get(str(i),"timeout", DEFAULT_OSD_TIMEOUT)) 
    155                                                 color = self.get(str(i),"color", DEFAULT_OSD_COLOR) 
    156                                                 font = self.get(str(i),"font", DEFAULT_OSD_FONT) 
    157                                                 self.devices.append(OsdAlertDevice(OsdAlertDeviceInfo(position, 
    158                                                                                                                                                                 alignment, 
    159                                                                                                                                                                 offset, 
    160                                                                                                                                                                 timeout, 
    161                                                                                                                                                                 color, 
    162                                                                                                                                                                 font), 
    163                                                                                                                         alerts,areas)) 
    164                                         else: 
    165                                                 self.log.error("OSD Support Not Enabled, but OSD Device Requested!") 
    166                                 if(dev == "mythtv"): 
     124                        dev = self.getRequired(str(i),"device") 
     125                        alerts = self.getRequired(str(i),"alert") 
     126                        areas = self.getRequired(str(i),"areas") 
     127                        self.log.debug("AlertDevice(%s) Areas(%s) Alerts(%s)" % (dev, alerts,areas)) 
     128 
     129                        if(dev == "email"): 
     130                                to = self.getRequired(str(i),"to") 
     131                                textwidth = int(self.get(str(i),"textwidth",-1)) 
     132                                self.devices.append(EmailAlertDevice(to,textwidth,smtpInfo,alerts,areas)) 
     133                                self.log.debug("Adding email device") 
     134                        if(dev == "sms"): 
     135                                to = self.getRequired(str(i),"to") 
     136                                textwidth = int(self.get(str(i),"textwidth",-1)) 
     137                                self.devices.append(SmsAlertDevice(to,textwidth,smtpInfo,alerts,areas)) 
     138                                self.log.debug("Adding sms device") 
     139                        if(dev == "jabber"): 
     140                                if(not jabberLoadAttempted): 
     141                                        jabber_available = self.__loadXmpp() 
     142                                        jabberLoadAttempted = True 
     143 
     144                                if(jabber_available): 
    167145                                        to = self.getRequired(str(i),"to") 
    168146                                        wait_time = int(self.getRequired(str(i),"wait_time")) 
    169147                                        self.devices.append(MythtvAlertDevice(MythtvAlertDeviceInfo(to,wait_time),alerts,areas)) 
    170                                 if(dev == "media"): 
    171                                         self.devices.append(MediaAlertDevice(mediaInfo,alerts,areas)) 
    172                                 if(dev == "execution"): 
    173                                         self.devices.append(ExecutionAlertDevice(exeInfo,alerts,areas)) 
    174                 print self.__str__() 
     148                                        self.log.debug("Adding jabber device") 
     149                                else: 
     150                                        self.log.error("Jabber Support Not Enabled, but Jabber Device Requested!") 
     151                        if(dev == "media"): 
     152                                self.devices.append(MediaAlertDevice(mediaInfo,alerts,areas)) 
     153                                self.log.debug("Adding media device") 
     154                        if(dev == "execution"): 
     155                                self.devices.append(ExecutionAlertDevice(exeInfo,alerts,areas)) 
     156                                self.log.debug("Adding execution device") 
     157                        if(dev == "osd"): 
     158                                if(not osdLoadAttempted): 
     159                                        osd_available = self.__loadOsd() 
     160                                        osdLoadAttempted = True 
     161 
     162                                if(osd_available): 
     163                                        position = self.get(str(i),"position", DEFAULT_OSD_POSITION) 
     164                                        alignment = self.get(str(i),"alignment", DEFAULT_OSD_ALIGNMENT) 
     165                                        offset = int(self.get(str(i),"offset", DEFAULT_OSD_OFFSET)) 
     166                                        timeout = int(self.get(str(i),"timeout", DEFAULT_OSD_TIMEOUT)) 
     167                                        color = self.get(str(i),"color", DEFAULT_OSD_COLOR) 
     168                                        font = self.get(str(i),"font", DEFAULT_OSD_FONT) 
     169                                        self.devices.append(OsdAlertDevice(OsdAlertDeviceInfo(position, 
     170                                                                                                                                                        alignment, 
     171                                                                                                                                                        offset, 
     172                                                                                                                                                        timeout, 
     173                                                                                                                                                        color, 
     174                                                                                                                                                        font), 
     175                                                                                                                alerts,areas)) 
     176                                        self.log.debug("Adding jabber device") 
     177                                else: 
     178                                        self.log.error("OSD Support Not Enabled, but OSD Device Requested!") 
     179                        if(dev == "mythtv"): 
     180                                to = self.getRequired(str(i),"to") 
     181                                wait_time = int(self.getRequired(str(i),"wait_time")) 
     182                                self.devices.append(MythtvAlertDevice(MythtvAlertDeviceInfo(to,wait_time),alerts,areas)) 
     183                                self.log.debug("Adding mythtv device") 
    175184 
    176185        def __str__(self): 
  • StormSiren/StormConfig.py

    r186 r187  
    6969                self.__proxy           = '' 
    7070 
    71                 self.log.setLevel(logging.INFO) 
     71                self.log.setLevel(logging.DEBUG) 
    7272                self._load() 
    73  
    7473 
    7574        def _load(self): 
     
    145144                                if(jabber_available): 
    146145                                        to = self.getRequired(str(i),"to") 
    147                                         self.devices.append(JabberAlertDevice(to,jabberInfo,alerts,areas)) 
     146                                        wait_time = int(self.getRequired(str(i),"wait_time")) 
     147                                        self.devices.append(MythtvAlertDevice(MythtvAlertDeviceInfo(to,wait_time),alerts,areas)) 
    148148                                        self.log.debug("Adding jabber device") 
    149149                                else: 
    150150                                        self.log.error("Jabber Support Not Enabled, but Jabber Device Requested!") 
     151                        if(dev == "media"): 
     152                                self.devices.append(MediaAlertDevice(mediaInfo,alerts,areas)) 
     153                                self.log.debug("Adding media device") 
     154                        if(dev == "execution"): 
     155                                self.devices.append(ExecutionAlertDevice(exeInfo,alerts,areas)) 
     156                                self.log.debug("Adding execution device") 
    151157                        if(dev == "osd"): 
    152158                                if(not osdLoadAttempted): 
     
    168174                                                                                                                                                        font), 
    169175                                                                                                                alerts,areas)) 
    170                                         self.log.debug("Adding OSD device") 
     176                                        self.log.debug("Adding jabber device") 
    171177                                else: 
    172178                                        self.log.error("OSD Support Not Enabled, but OSD Device Requested!") 
    173179                        if(dev == "mythtv"): 
    174                                 to = self.getRequired(str(i),"to") 
    175                                 wait_time = int(self.getRequired(str(i),"wait_time")) 
    176                                 self.devices.append(MythtvAlertDevice(MythtvAlertDeviceInfo(to,wait_time),alerts,areas)) 
    177                                 self.log.debug("Adding MythTv device") 
    178                         if(dev == "media"): 
    179                                 self.devices.append(MediaAlertDevice(mediaInfo,alerts,areas)) 
    180                                 self.log.debug("Adding media device") 
    181                         if(dev == "execution"): 
    182                                 self.devices.append(ExecutionAlertDevice(exeInfo,alerts,areas)) 
    183                                 self.log.debug("Adding execution device") 
     180                                to = self.getRequired(str(i),"to") 
     181                                wait_time = int(self.getRequired(str(i),"wait_time")) 
     182                                self.devices.append(MythtvAlertDevice(MythtvAlertDeviceInfo(to,wait_time),alerts,areas)) 
     183                                self.log.debug("Adding mythtv device") 
    184184 
    185185        def __str__(self): 
     
    187187                str += "\n\t".join(self.__states) 
    188188 
    189                 str += "\nProxy: %i\n" % self.__proxy 
    190                 str += "\nHistory: %i\n" % self.max_history 
     189                str += "\nProxy: %s" % self.proxy 
     190                str += "\nHistory: %i" % self.max_history 
    191191                str += "\nDevices: %i\n" % len(self.devices) 
    192192 
  • StormSiren/StormWeather.py

    r174 r187  
    5656                self.__simalert = simalert 
    5757                self.__history = history 
     58 
     59                self.log.setLevel(logging.INFO) 
    5860         
    5961        def __str__(self): 
     
    7173                self.__alert_devs.append(dev) 
    7274 
    73         def logAtom(self, cap_atom): 
     75        def logAtomShort(self, cap_atom): 
     76                self.log.info("---------CAP ATOM---------") 
     77                for l in (cap_atom.__str__().split('\n')): 
     78                        self.log.info(l) 
     79                self.log.info("---------CAP ATOM---------") 
     80 
     81        def logAtomFull(self, cap_atom): 
     82                self.log.info("---------CAP ATOM---------") 
    7483                for l in (cap_atom.__str__().split('\n')): 
    7584                        self.log.info(l) 
     
    7988                                self.log.info(l) 
    8089                self.log.info("========DESCRIPTION=======") 
     90                self.log.info("---------CAP ATOM---------") 
    8191 
    8292        def handleAtom(self, cap_atom): 
    83                 self.logAtom(cap_atom) 
     93                self.logAtomShort(cap_atom) 
    8494                if(not self.__history.exists(cap_atom.id)): 
    8595                        for dev in self.__alert_devs: 
     
    8797                                        if(not self.__simalert): 
    8898                                                cap_atom.expand(self.simfetch,self.proxy) 
    89                                                 self.logAtom(cap_atom) 
     99                                                self.logAtomFull(cap_atom) 
    90100                                                dev.send(cap_atom) 
    91101                                                self.__history.add(cap_atom.id) 
  • StormSiren/StormWeather.py

    r186 r187  
    4848from WeatherAlert import * 
    4949from XmlWeather import * 
    50 from CAP import CAP 
    5150 
    5251class StormWeather(XmlWeather): 
    5352        def __init__(self, state, history, simfetch = False, simalert = False, proxy = None): 
    54                 super(StormWeather,self).__init__(state,history,simfetch,proxy) 
     53                super(StormWeather,self).__init__(state,simfetch,proxy) 
    5554                self.log = logging.getLogger("StormWeather") 
    5655                self.__alert_devs = [] 
    5756                self.__simalert = simalert 
     57                self.__history = history 
    5858 
    5959                self.log.setLevel(logging.INFO) 
    6060         
    61         def display(self): 
    62                 return self.__str__() 
    63  
    6461        def __str__(self): 
    6562                str  = "StormWeather: " + "\n" 
     
    7269                return str 
    7370 
    74         def display(self): 
    75                 print self.__str__() 
    76  
    7771        def registerDevice(self, dev): 
    7872                self.log.debug("Registering Device") 
    7973                self.__alert_devs.append(dev) 
    8074 
    81         def handleAlert(self, cap_item): 
    82                 alerted = False 
     75        def logAtomShort(self, cap_atom): 
     76                self.log.info("---------CAP ATOM---------") 
     77                for l in (cap_atom.__str__().split('\n')): 
     78                        self.log.info(l) 
     79                self.log.info("---------CAP ATOM---------") 
    8380 
    84                 for dev in self.__alert_devs: 
    85                         if(dev.isAlertWanted(cap_item)): 
    86                                 if(not self.__simalert): 
    87                                         dev.send(WeatherAlert(cap_item)) 
    88                                         alerted = True 
    89                                 else: 
    90                                         self.log.info("Simulated Alert on: %s" % cap_item.id) 
     81        def logAtomFull(self, cap_atom): 
     82                self.log.info("---------CAP ATOM---------") 
     83                for l in (cap_atom.__str__().split('\n')): 
     84                        self.log.info(l) 
     85                self.log.info("========DESCRIPTION=======") 
     86                if(cap_atom.description): 
     87                        for l in (cap_atom.description.split('\n')): 
     88                                self.log.info(l) 
     89                self.log.info("========DESCRIPTION=======") 
     90                self.log.info("---------CAP ATOM---------") 
    9191 
    92                 return alerted 
     92        def handleAtom(self, cap_atom): 
     93                self.logAtomShort(cap_atom) 
     94                if(not self.__history.exists(cap_atom.id)): 
     95                        for dev in self.__alert_devs: 
     96                                if(dev.isAlertWanted(cap_atom)): 
     97                                        if(not self.__simalert): 
     98                                                cap_atom.expand(self.simfetch,self.proxy) 
     99                                                self.logAtomFull(cap_atom) 
     100                                                dev.send(cap_atom) 
     101                                                self.__history.add(cap_atom.id) 
     102                                        else: 
     103                                                self.log.info("Simulated Alert on: %s" % cap_atom.id) 
     104                else: 
     105                        self.log.debug("Ignoring %s: Already alerted on" % cap_atom.id) 
  • StormSiren/TestAlert.py

    r164 r187  
    5959                self.log          = logging.getLogger("TestAlert") 
    6060 
     61                self.log.setLevel(logging.INFO) 
     62 
    6163        def fetch(self): 
    6264                self.__fetch() 
  • StormSiren/TestAlert.py

    r184 r187  
    4949from WeatherTypes import * 
    5050from WeatherAlert import * 
    51 from CAP import CAP 
    5251 
    5352class TestAlert(object): 
  • StormSiren/XmlWeather.py

    r174 r187  
    6262                self.log          = logging.getLogger("XmlWeather") 
    6363 
     64                self.log.setLevel(logging.DEBUG) 
     65 
    6466        def fetch(self): 
    6567                self.__fetch() 
  • StormSiren/XmlWeather.py

    r186 r187  
    4242""" 
    4343 
    44 import urllib2 
    4544import logging 
    46 import sys 
    47 from xml.dom import minidom 
    4845 
    4946from WeatherTypes import * 
    50 from CAP import CAP 
     47from XmlFetcher import * 
     48from WeatherAlert import WeatherAlert 
    5149 
    5250class XmlWeather(object): 
    53         def __init__(self, state, history, simfetch = False, proxy = None): 
     51        def __init__(self, state, simfetch = False, proxy = None): 
    5452                super(XmlWeather,self).__init__() 
    5553                self.__data       = '' 
    5654                self.__state      = state 
    5755                self.__dom        = [] 
    58                 self.__baseurl    = 'http://www.weather.gov/alerts/' 
    59                 self.__namespace  = 'http://purl.org/dc/elements/1.1/' 
    60                 self.__url        = self.__baseurl + self.__state.lower() + ".cap"  
    61                 self.__tag_item   = 'cap:info' 
    62                 self.__history    = history 
     56                self.__baseurl    = 'http://www.weather.gov/wwarss-tst/' 
     57                self.__url        = self.__baseurl + self.__state.lower() + ".php?x=0"  
     58                self.__tag_item   = 'entry' 
    6359                self.__simfetch   = simfetch 
    6460                self.__proxy      = proxy 
    65                 self.log = logging.getLogger("XmlWeather") 
     61                self.__atoms      = XmlFetcher(self.__url, self.__simfetch, self.__proxy) 
     62                self.log          = logging.getLogger("XmlWeather") 
    6663 
    6764                self.log.setLevel(logging.DEBUG) 
     
    7572 
    7673        def __fetch(self): 
    77                 self.log.info("Fetching: " + self.__url) 
    78                 try: 
    79                         if(self.__simfetch): 
    80                                 self.log.info("Simulating fetch using examples directory") 
    81                                 self.__dom = minidom.parse("examples/" + self.__state.lower() + ".cap") 
    82                         else: 
    83                                 if(self.__proxy): 
    84                                         self.log.info("Using proxy: %s" % self.__proxy) 
    85                                         proxy_support = urllib2.ProxyHandler({"http" : self.__proxy}) 
    86                                         opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) 
    87                                         urllib2.install_opener(opener) 
    88                                 self.__dom = minidom.parse(urllib2.urlopen(self.__url)) 
    89                 except IOError,e: 
    90                         # No net connection available, exit. 
    91                         self.log.error("Internet connection not available?, exiting: %s" % e) 
    92                         sys.exit() 
     74                self.__dom = self.__atoms.fetch() 
    9375 
    9476        def __str__(self): 
    9577                str  = "XmlWeather:\n" + \ 
     78                                "SimFetch: " + self.__simfetch + "\n" + \ 
     79                                "Proxy: " + self.__proxy + "\n" + \ 
    9680                                "State: " + self.__state + "\n" + \ 
    9781                                "URL: " + self.__url + "\n" 
    98  
    99                 if(self.__simfetch): 
    100                         str += "Sim Fetch: yes\n" 
    101                 else: 
    102                         str += "Sim Fetch: no\n" 
    10382                return str 
    10483 
     
    10887        def __parse(self): 
    10988                for capXmlText in self.__dom.getElementsByTagName(self.__tag_item): 
    110                         cap_item = CAP(capXmlText, self.__state) 
    111                         #cap_item.display() 
    112                         if(not self.__history.exists(cap_item.id)): 
    113                                 alerted = self.handleAlert(cap_item) 
    114                                 if(alerted): 
    115                                         self.__history.add(cap_item.id) 
    116                         else: 
    117                                 self.log.debug("Ignoring %s: Already alerted on" % cap_item.id) 
     89                        self.handleAtom(WeatherAlert(capXmlText, self.__state)) 
    11890 
     91        def getSimFetch(self): 
     92                return self.__simfetch 
    11993 
    120         def handleAlert(self,cap_item): 
    121                 self.log.debug("handleAlert(%s) - %s/%s" % (cap_item.id, cap_item.county, cap_item.state)) 
    122                 return True 
     94        simfetch = property(getSimFetch,None,None) 
     95 
     96        def getProxy(self): 
     97                return self.__proxy 
     98 
     99        proxy = property(getProxy,None,None) 
  • siren

    r155 r187  
    4343 
    4444import logging 
     45import sys 
    4546from optparse import OptionParser 
    4647 
     
    5354__RELEASE_VERSION = "2.0 RC4" 
    5455__RELEASE_MONTH   = "12" 
    55 __RELEASE_DAY     = "08" 
     56__RELEASE_DAY     = "01" 
    5657__RELEASE_YEAR    = "2008" 
     58 
     59logging.basicConfig(level=logging.INFO, 
     60                        format='%(asctime)s - %(name)s:%(lineno)d - %(levelname)s - %(message)s') 
    5761 
    5862def main(): 
     
    6064        log = logging.getLogger() 
    6165 
     66        log.setLevel(logging.DEBUG) 
    6267 
    6368        parser.add_option("-c", "--conf", dest="conf", 
     
    8287                                        help="Print only important messages to the console") 
    8388 
    84         parser.add_option("-l", "--logconf", dest="logconf", 
    85                                         help="Override log configuration file", metavar="file_name", default=None) 
    86  
    8789        parser.add_option("-t", "--testpage",  
    8890                                        action="store_true", dest="testpage", default=False, 
     
    9698                logging.disable(logging.info) 
    9799 
    98         conf = StormConfig(options.conf, options.logconf) 
     100        conf = StormConfig(options.conf) 
    99101 
    100102        log.info("StormSiren: v%s (%s/%s/%s)" % (__RELEASE_VERSION,  
     
    111113        #conf.display() 
    112114        #history.display() 
     115 
     116        if(len(conf.devices) == 0): 
     117                log.error("No valid devices found, exiting..") 
     118                sys.exit(1) 
    113119 
    114120        if(not options.testpage):