~osomon/moovida/upicek_release_scripts

« back to all changes in this revision

Viewing changes to elisa-core/elisa/core/application.py

  • Committer: Benjamin Kampmann
  • Date: 2008-10-06 10:03:41 UTC
  • mfrom: (747.2.14 auto_yesfm)
  • Revision ID: benjamin@fluendo.com-20081006100341-4zafyl5qvs6zzeuj
Merge geoip update checker
 - request for updates is outsource into its own class in core.utils
 - request is totally unittested
 - update script is more flexible and allows a dictionary like result
 - new URL (server side already up and running) with new results
 - a new field introduced: country_code is a Geo-IP lookup of the requesters IP
   on the server side
 - adapt yesfm to automatically de-activate itself if the country code is not
   'es' as yesfm only works in spain anyway.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
except ImportError:
53
53
    store = None
54
54
 
 
55
try:
 
56
    from elisa.core.utils.update_checker import UpdateChecker
 
57
except ImportError:
 
58
    # could happen if the elisa http client plugin is missing
 
59
    UpdateChecker = None
 
60
 
55
61
 
56
62
from distutils.version import LooseVersion
57
63
 
58
 
UPDATES_URL = "http://elisa.fluendo.com/updates/update.php?install_date=%(date)s&version=%(version)s&os=%(os)s&user_id=%(user_id)s"
59
64
CONFIG_DIR = os.path.join(os.path.expanduser('~'), ".elisa-0.5")
60
65
 
61
66
# We add to the configuration file name the version number in order to bypass
257
262
        self._splash = splash
258
263
 
259
264
        self.store = None
 
265
        self.update_checker = None
260
266
 
261
267
        self.bus = bus.Bus()
262
268
        self.service_manager = service_manager.ServiceManager()
266
272
        self.interface_controller = interface_controller.InterfaceController()
267
273
        self.options = options
268
274
 
269
 
    def _check_updates(self):
270
 
        distro = misc.get_os_name()
271
 
        url = UPDATES_URL % {'date': self._install_date, 'version': __version__,
272
 
                             'os': distro, 'user_id': self._user_id}
273
 
        dfr = client.getPage(url)
274
 
 
275
 
        def got_result(result):
276
 
            # epr_url = result
277
 
            splitted = result.splitlines()
278
 
            if len(splitted) == 1:
279
 
                # hey, looks like new elisaweb hasn't been deployed yet.
280
 
                user_id = ''
281
 
                version = ''
282
 
                installer_url = ''
283
 
            else:
284
 
                user_id, version, installer_url = splitted
285
 
 
286
 
            if version and LooseVersion(version) > LooseVersion(__version__):
287
 
                msg = NewElisaVersionMessage(version, installer_url)
288
 
                self.bus.send_message(msg)
289
 
 
290
 
            # store user_id in config
291
 
            self.config.set_option('user_id', user_id, section='general')
292
 
            self._user_id = user_id
293
 
 
294
 
            # re-check for updates one day later
295
 
            reactor.callLater(86400, threads.deferToThread, self._check_updates)
296
 
 
297
 
        dfr.addCallback(got_result)
 
275
    def _update_check_callback(self, results):
 
276
        try:
 
277
            version = results['version']
 
278
        except KeyError:
 
279
            version = None
 
280
 
 
281
        try:
 
282
            user_id = results['user_id']
 
283
        except KeyError:
 
284
            user_id = None
 
285
 
 
286
        try:
 
287
            installer_url = results['installer_url']
 
288
        except KeyError:
 
289
            installer_url = None
 
290
 
 
291
        if version and LooseVersion(version) > LooseVersion(__version__):
 
292
            msg = NewElisaVersionMessage(version, installer_url)
 
293
            self.bus.send_message(msg)
 
294
 
 
295
        # store user_id in config
 
296
        self.config.set_option('user_id', user_id, section='general')
 
297
        self._user_id = user_id
 
298
 
 
299
        # store the country code
 
300
        try:
 
301
            self.config.set_option('country_code', results['country_code'],
 
302
                    section='general')
 
303
        except KeyError:
 
304
            # country code not given in the response
 
305
            pass
298
306
 
299
307
    def _load_exception_hook(self):
300
308
        """ Override the default system exception hook with our own
453
461
        self.resource_manager.start()
454
462
        self.service_manager.start()
455
463
 
456
 
        # FIXME: use the http client for this
457
 
        threads.deferToThread(self._check_updates)
 
464
        if UpdateChecker:
 
465
            self.update_checker = UpdateChecker(self._install_date,
 
466
                    self._user_id,  __version__)
 
467
            self.update_checker.start(self._update_check_callback)
458
468
 
459
469
    def stop(self, stop_reactor=True):
460
470
        """Stop the application.
465
475
        """
466
476
        self._close_splash_screen()
467
477
 
 
478
        if self.update_checker is not None:
 
479
            self.update_checker.stop()
 
480
 
468
481
        def interface_controller_stopped(result):
469
482
            self.info("Stopping managers")
470
483