Misc: Use the GitHub API in @version.

* Works with the new automatic version.py
* Prevents us from loading and parsing a raw file.
This commit is contained in:
Valentin Lorentz 2012-05-11 19:00:40 +02:00
parent 90e511cad1
commit 0a4e99b6f2
1 changed files with 10 additions and 7 deletions

View File

@ -32,6 +32,7 @@ import re
import os import os
import imp import imp
import sys import sys
import json
import time import time
import supybot import supybot
@ -291,15 +292,17 @@ class Misc(callbacks.Plugin):
Returns the version of the current bot. Returns the version of the current bot.
""" """
try: try:
newestUrl = 'https://github.com/ProgVal/Limnoria/raw/%s/' + \ newestUrl = 'https://api.github.com/repos/ProgVal/Limnoria/' + \
'src/version.py' 'commits/%s'
versions = {} versions = {}
for branch in ('master', 'testing'): for branch in ('master', 'testing'):
file = utils.web.getUrl(newestUrl % branch) data = json.load(utils.web.getUrlFd(newestUrl % branch))
match = re.search(r"^version = '([^']+)'$", file, re.M) version = data['commit']['committer']['date']
if match is None: # Strip the last ':':
continue version = ''.join(version.rsplit(':', 1))
versions[branch] = match.group(1) # Replace the last '-' by '+':
version = '+'.join(version.rsplit('-', 1))
versions[branch] = version
newest = _('The newest versions available online are %s.') % \ newest = _('The newest versions available online are %s.') % \
', '.join([_('%s (in %s)') % (y,x) ', '.join([_('%s (in %s)') % (y,x)
for x,y in versions.items()]) for x,y in versions.items()])