forked from maxpowa/inumuta-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_updates.py
60 lines (50 loc) · 1.66 KB
/
find_updates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# coding=utf-8
"""
find_updates.py - Update checking module for Sopel.
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
Sopel website.
"""
# Copyright 2014, Edward D. Powell, embolalia.net
# Licensed under the Eiffel Forum License 2.
from __future__ import unicode_literals
import json
import sopel
import sopel.module
import sopel.web
startup_check_run = False
version_url = 'http://sopel.chat/latest.json'
message = (
'A new Sopel version, {}, is available. I am running {}. Please update '
'me. Full release notes at {}'
)
unstable_message = (
'A new pre-release version, {}, is available. I am running {}. Please '
'update me. {}'
)
@sopel.module.event('251')
@sopel.module.rule('.*')
def startup_version_check(bot, trigger):
global startup_check_run
if not startup_check_run:
startup_check_run = True
check_version(bot)
@sopel.module.require_admin
@sopel.module.commands('check_update')
def check_version(bot, trigger):
version = sopel.version_info
info = json.loads(sopel.web.get(version_url))
if version.releaselevel == 'final':
latest = info['version']
notes = info['release_notes']
else:
latest = info['unstable']
notes = info.get('unstable_notes', '')
if notes:
notes = 'Full release notes at ' + notes
latest_version = sopel._version_info(latest)
msg = message.format(latest, sopel.__version__, notes)
if version < latest_version:
bot.reply(msg)
else:
bot.reply('No new version available. I am running {}'.format(sopel.__version__))