forked from sopel-irc/sopel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[find_updates] Add a module to check for updates
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |