Exemplo n.º 1
0
def main(rfile, wfile, env):
    req = request.Request(rfile, env)
    path = env.get('PATH_INFO', '')
    errors = []

    # initialize current state
    state = upgrade_checker._getSystemState()
    form = {
        'feed_url': state.feed_url,
        'fetch_frequency': str(state.fetch_frequency),
        'current_version': state.current_version,
        'upgrade_info': state.upgrade_info,
    }

    log.debug('%s %s' % (path, str(state.upgrade_info)))

    if path == '/dismiss':
        upgrade_checker.set_config(dismiss=True)
        url = req.param('url','')
        if url:
            response.redirect(wfile, url)
        else:
            response.redirect(wfile, '/updateParent')
        return

    elif path == '/check':
        # 2006-04-02 23:50:26 DEBUG>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        #state.current_version = '0.1' # assume it is an older version
        # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        upgrade_checker.pollUpgradeInfo(force_check=True)
        form['upgrade_info'] = state.upgrade_info

        # hack, do not redirect to /setting
        # we want the /check in the URL so that we can tell user no new version
        #response.redirect(wfile, '/upgrade/setting')

    elif req.method == 'POST':
        _freq_str = req.param('fetch_frequency',str(upgrade_checker.DEFAULT_FETCH_FREQUENCY))
        if not _freq_str:
            _freq_str = '0'
        try:
            frequency = int(_freq_str)
            if frequency < 0:
                raise ValueError()
        except ValueError:
            form['fetch_frequency'] = _freq_str
            errors = ['Please enter a positive integer for check frequency.']
        else:
            upgrade_checker.set_config(frequency=int(_freq_str))
            form['fetch_frequency'] = str(state.fetch_frequency)

    renderer = UpgradeRenderer(wfile)
    renderer.setLayoutParam('MindRetrieve - Upgrade Notification Setting')
    renderer.output(errors, form, path)
    def test_checkUpgrade(self):
        st = self.state
        today = datetime.date(2005,1,1)

        # version 0.0
        st.current_version = '0.0'
        st.last_entry_date = ''
        st.feed_url = TEST_FEED0

        uc._checkUpgrade(st, today)             # got upgrade 0.4.2

        self.assertEqual(st.fetch_date, today)
        self.assertEqual(st.next_fetch, datetime.date(2005,1,11))
        self.assertEqual(st.last_entry_date, '2005-02-21T17:00:00Z')
        self.assert_(st.upgrade_info)

        uinfo = st.upgrade_info
        self.assertEqual(uinfo.version, '0.4.2')
        self.assertEqual(uinfo.title,   'Version 0.4.2')
        self.assertEqual(uinfo.summary, 'Maintenance release with minor enhancement (2005-02-21)')
        self.assertEqual(uinfo.url,     'https://developer.berlios.de/project/showfiles.php?group_id=2905&release_id=4867')

        uc.set_config(st, dismiss=True)         # reset upgrade_info

        # still version 0.0
        uc._checkUpgrade(st, today)             # got old news

        self.assertEqual(st.last_entry_date, '2005-02-21T17:00:00Z')
        self.assert_(not st.upgrade_info)

        # version 0.4.2
        st.current_version = '0.4.2'
        st.last_entry_date = ''
        st.feed_url = TEST_FEED0

        uc._checkUpgrade(st, today)             # no new version

        self.assertEqual(st.last_entry_date, '2005-02-21T17:00:00Z')
        self.assert_(not st.upgrade_info)

        # found latest 0.8.0
        st.current_version = '0.4.0'
        st.last_entry_date = ''
        st.feed_url = TEST_FEED1

        uc._checkUpgrade(st, today)             # new version 0.8.0 available!
        self.assertEqual(st.last_entry_date, '2006-01-18T17:00:00Z')
        self.assert_(st.upgrade_info)

        uinfo = st.upgrade_info
        self.assertEqual(uinfo.version, '0.8.0')
        self.assertEqual(uinfo.title,   'Version 0.8.0')
        self.assertEqual(uinfo.summary, 'New features added: web library, tag based categorization, etc (2006-01-18)')
        self.assertEqual(uinfo.url,     'https://developer.berlios.de/project/showfiles.php?group_id=2905&release_id=8737')
    def test_set_config(self):
        st = self.state
        st.upgrade_info = 'dummy'

        # set frequency
        uc.set_config(st, frequency=7)
        self.assertEqual(st.fetch_frequency, 7)
        self.assertEqual(st.next_fetch, datetime.date(2004,1,8))
        self.assert_(st.upgrade_info)

        # dismiss
        uc.set_config(st, dismiss=True)
        self.assertEqual(st.fetch_frequency, 7)
        self.assert_(not st.upgrade_info)
    def test_pollUpgradeInfo(self):

        def _date_func(y,m,d):
            # Helper to return a functional object
            # >>> date_func(2005,1,1)()
            # datetime.date(2005, 1, 1, 0, 0)
            return lambda: datetime.date(y,m,d)

        st = self.state
        st.current_version = '0.0'
        st.feed_url = TEST_FEED0

        self._test_poll(_date_func(2004,12,31), False, '')      # no fetch
        self._test_poll(_date_func(2005, 1, 1), True,  '0.4.2') # fetch 0.4.2
        self._test_poll(_date_func(2005, 1, 2), False, '0.4.2') # no fetch but still have upgrade 0.4.2

        uc.set_config(st, dismiss=True)                         # reset upgrade_info
        self._test_poll(_date_func(2005, 1, 3), False, '')      # dismissed, no fetch
        self._test_poll(_date_func(2005, 1,11), True,  '')      # fetch again, but nothing new

        st.feed_url = TEST_FEED1
        self._test_poll(_date_func(2005, 1,21), True,  '0.8.0') # fetch again, got 0.8.0

        uc.set_config(st, frequency=0)
        self._test_poll(_date_func(2005, 1,31), False, '')      # upgrade is off

        self._test_poll(_date_func(2005, 1,22), True,  '0.8.0', force_check=True)  # force_check

        uc.set_config(st, dismiss=True)                         # reset upgrade_info

        st.current_version = '9.9'
        self._test_poll(_date_func(2005, 1,23), True,  '', force_check=True)  # force_check but no new version

        self._test_poll(_date_func(2005, 2,10), False, '')      # regular feed after force feed (still disabled)

        uc.set_config(st, frequency=10)
        self._test_poll(_date_func(2005, 2,10), True, '')       # regular feed made after force feed