Ticket #337: otimed.diff

File otimed.diff, 1.6 KB (added by Nytowl, 3 years ago)

Added CTZV logic to otimed

  • otimed.py

    old new  
    149149            None, 
    150150            None 
    151151        ) 
     152        self.bus.add_signal_receiver( 
     153            self._handleTimeZoneReport, 
     154            "TimeZoneReport", 
     155            "org.freesmartphone.GSM.Network", 
     156            None, 
     157            None 
     158        ) 
    152159        proxy = bus.get_object( "org.freesmartphone.ogsmd", 
    153160                                "/org/freesmartphone/GSM/Server", 
    154161                                follow_name_owner_changes=True, 
    155162                                introspect=False ) 
    156163        self.gsmdata = dbus.Interface( proxy, "org.freesmartphone.GSM.Data",  ) 
     164 
     165    def _handleTimeZoneReport( self, report ): 
     166        # this can be improved - AA 
     167        # if we know the country, the offset and if this zone supports daylight savings 
     168        # the proper timezone can be derived. 
     169        # so opreferencesd needs to have a <this zone uses daylight savings> flag 
     170        # and we need a /usr/share/zoneinfo parser 
     171 
     172        # CTZV is offset * 4  
     173        offset = report / 4 
     174        # offset need to be inverted to get the correct TZ 
     175        zone = "Etc/GMT"  
     176        if offset <= 0 : 
     177                zone += "+" + str( offset * -1 ) 
     178        else : 
     179                zone += "-" + str( offset ) 
     180        logger.debug( "TimeZoneReport :" + str( report ) + " offset " + str( offset ) + " zone " + zone ) 
     181        if zone != self.zone : 
     182            try: 
     183                shutil.copyfile( "/usr/share/zoneinfo/"+zone, "/etc/localtime" ) 
     184                self.zone = zone 
     185            except: 
     186                logger.warning( "failed to install time zone file " + zone + " to /etc/localtime" ) 
    157187 
    158188    def _handleNetworkStatusChanged( self, status ): 
    159189        if "code" in status: