class UpdateNotifierController(object):

    VERSION = version.VERSION
    SECONDS_IN_WEEK = 60*60*24*7

    def __init__(self, settings):
        self._settings = settings

    def notify_update_if_needed(self, update_notification_callback):
        if self._should_check() and self._is_new_version_available():
            update_notification_callback(self._newest_version, self._download_url, self._settings)

    def _should_check(self):
        if self._settings.get(_CHECK_FOR_UPDATES_SETTING, None) is None:
            self._settings[_CHECK_FOR_UPDATES_SETTING] = True
            return True
        return self._settings[_CHECK_FOR_UPDATES_SETTING] and \
               time.time() - self._settings.get(_LAST_UPDATE_CHECK_SETTING, 0) > self.SECONDS_IN_WEEK

    def _is_new_version_available(self):
        self._settings[_LAST_UPDATE_CHECK_SETTING] = time.time()
        try:
            self._newest_version = self._get_newest_version()
            self._download_url = self._get_download_url(self._newest_version)
        except Exception, e:
            print e
            #There are many possible errors:
            # - Timeout
            # - Corrupted data
            # - Server fault message
            # - Unexpected change in dataformat
            return False
        return cmp_versions(self.VERSION, self._newest_version) == -1
Exemple #2
0
 def __init__(self, version, url, settings):
     self._settings = settings
     wx.Dialog.__init__(self, None, -1, "Update available")
     # set Left to Right direction (while we don't have localization)
     self.SetLayoutDirection(wx.Layout_LeftToRight)
     sizer = wx.BoxSizer(orient=wx.VERTICAL)
     if PY2 and cmp_versions(UpdateNotifierController.VERSION,
                             '1.7.4') == -1:
         obsolete = '<br/><h1><b>You will need to upgrade your Python version!</b></h1>'
     else:
         obsolete = ''
     hwin = HtmlWindow(self, -1, size=(400, 200))
     hwin.SetPage('New version %s available from <a href="%s">%s</a>%s' %
                  (version, url, url, obsolete))
     irep = hwin.GetInternalRepresentation()
     hwin.SetSize((irep.GetWidth() + 25, irep.GetHeight() + 20))
     sizer.Add(hwin)
     checkbox = wx.CheckBox(
         self,
         -1,
         label=
         'I\'m using another method for RIDE updates\n and do not need automatic update checks'
     )
     checkbox.Bind(wx.EVT_CHECKBOX, handler=self.OnCheckboxChange)
     sizer.Add(checkbox)
     button = ButtonWithHandler(self,
                                label='remind me later',
                                handler=self.OnRemindMeLater)
     sizer.Add(button)
     self.SetSizer(sizer)
     self.CentreOnParent(wx.BOTH)
     self.Fit()
     self.SetFocus()
     self.ShowModal()
     self.Destroy()
Exemple #3
0
 def _is_new_version_available(self):
     self._settings[_LAST_UPDATE_CHECK_SETTING] = time.time()
     try:
         self._newest_version = self._get_newest_version()
         self._download_url = self._get_download_url(self._newest_version)
     except Exception as e:
         print(e)
         #There are many possible errors:
         # - Timeout
         # - Corrupted data
         # - Server fault message
         # - Unexpected change in dataformat
         return False
     return cmp_versions(self.VERSION, self._newest_version) == -1
 def test_versions(self):
     self.assertEqual(1, cmp_versions('1.0', '0.0'))
     self.assertEqual(-1, cmp_versions('0.0', '1.0'))
     self.assertEqual(0, cmp_versions('0.0', '0.0'))
 def test_release_candidate_is_smaller_than_released(self):
     self.assertEqual(1, cmp_versions('0.45', '0.45rc1'))
     self.assertEqual(-1, cmp_versions('1.4rc2', '1.4'))
 def test_alpha_less_than_beta_less_than_rc(self):
     self.assertEqual(1, cmp_versions('0b', '0a'))
     self.assertEqual(-1, cmp_versions('1.0b', '1.0rc1'))
 def test_trunk_is_smaller_than_released_version(self):
     self.assertEqual(1, cmp_versions('0.02', 'trunk'))
     self.assertEqual(1, cmp_versions('1.2.3', 'trunk'))
     self.assertEqual(1, cmp_versions('13.001', 'trunk'))
Exemple #8
0
 def test_none(self):
     self.assertEqual(1, cmp_versions("21", None))
     self.assertEqual(-1, cmp_versions(None, "3.21"))
     self.assertEqual(0, cmp_versions(None, None))
Exemple #9
0
 def test_alpha_less_than_beta_less_than_rc(self):
     self.assertEqual(1, cmp_versions("0b", "0a"))
     self.assertEqual(-1, cmp_versions("1.0b", "1.0rc1"))
 def test_none(self):
     self.assertEqual(1, cmp_versions('21', None))
     self.assertEqual(-1, cmp_versions(None, '3.21'))
     self.assertEqual(0, cmp_versions(None, None))
Exemple #11
0
 def test_release_candidate_is_smaller_than_released(self):
     self.assertEqual(1, cmp_versions("0.45", "0.45rc1"))
     self.assertEqual(-1, cmp_versions("1.4rc2", "1.4"))
Exemple #12
0
 def test_zero_and_empty_are_equal(self):
     self.assertEqual(0, cmp_versions("0", "0.0.0.0"))
     self.assertEqual(0, cmp_versions("2.0.1", "2.0.1.0"))
Exemple #13
0
 def test_trunk_is_smaller_than_released_version(self):
     self.assertEqual(1, cmp_versions("0.02", "trunk"))
     self.assertEqual(1, cmp_versions("1.2.3", "trunk"))
     self.assertEqual(1, cmp_versions("13.001", "trunk"))
 def _get_newest_xml_file(self, xml_file, current_xml_file):
     version1 = self._get_version(xml_file)
     version2 = self._get_version(current_xml_file)
     if cmp_versions(version1, version2) == 1:
         return xml_file
     return current_xml_file
 def test_zero_and_empty_are_equal(self):
     self.assertEqual(0, cmp_versions('0', '0.0.0.0'))
     self.assertEqual(0, cmp_versions('2.0.1', '2.0.1.0'))
Exemple #16
0
 def _get_newest_xml_file(self, xml_file, current_xml_file):
     version1 = self._get_version(xml_file)
     version2 = self._get_version(current_xml_file)
     if cmp_versions(version1, version2) == 1:
         return xml_file
     return current_xml_file
Exemple #17
0
 def test_versions(self):
     self.assertEqual(1, cmp_versions("1.0", "0.0"))
     self.assertEqual(-1, cmp_versions("0.0", "1.0"))
     self.assertEqual(0, cmp_versions("0.0", "0.0"))