Skip to content

Commit

Permalink
[find_updates] Add a module to check for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
embolalia committed Aug 31, 2014
1 parent 0cad026 commit 6963397
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions find_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# coding=utf8
"""
find_updates.py - Update checking module for Willie.
This is separated from version.py, so that it can be easily overridden by
distribution packagers, and they can check their repositories rather than the
Willie website.
"""
# Copyright 2014, Edward D. Powell, embolalia.net
# Licensed under the Eiffel Forum License 2.
from __future__ import unicode_literals

import json
import re

import willie
import willie.module
import willie.web

wait_time = 24 * 60 * 60 # check once per day
startup_check_run = False
version_url = 'http://willie.dftba.net/latest.json'
message = (
'A new Willie version, {}, is available. I am running {}. Please update ' +
'me. Full release notes at {}.'
)


def parse_version(version):
return re.match('(\d+)\.(\d+)\.(\d+)(?:-\S+)?', version).groups()


@willie.module.event('001')
@willie.module.event('251')
@willie.module.rule('.*')
def startup_version_check(bot, trigger):
if not startup_check_run:
startup_check_run = True
check_version(bot)


@willie.module.interval(wait_time)
def check_version(bot):
version = parse_version(willie.__version__)

info = json.loads(willie.web.get(version_url))
latest = info['version']
notes = info['release_notes']
latest_version = parse_version(latest)

if version < latest_version:
bot.msg(bot.config.core.owner,
message.format(latest, willie.__version__, notes))

0 comments on commit 6963397

Please sign in to comment.