123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- # -*- coding: utf-8 -*-
- from __future__ import print_function
- import willie
- def setup(bot):
- pass
- @willie.module.commands('status')
- def ffpb_status(bot, trigger):
- """Status des FFPB-Netzes: Anzahl (aktiver) Knoten + Clients"""
- stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None
- if stats is None:
- bot.say('Uff, kein Plan wo der Zettel ist. Fragst du später nochmal?')
- return
- bot.say('Es sind {0} Knoten und ca. {1} Clients online.'.format(stats["nodes_active"], stats["clients"]))
- @willie.module.commands('highscore')
- def ffpb_highscore(bot, trigger):
- highscores = bot.memory['highscores'] if 'highscores' in bot.memory else None
- if highscores is None:
- bot.reply('Sorry, ich habe gerade keine Highscore-Daten parat. Und würfeln ist auch eher uncool.')
- return
- bot.say('Highscore: {0} Knoten ({1}), {2} Clients ({3})'.format(
- highscores['nodes'], pretty_date(int(highscores['nodes_ts'])),
- highscores['clients'], pretty_date(int(highscores['clients_ts']))))
- @willie.module.commands('rollout-status')
- def ffpb_rolloutstatus(bot, trigger):
- """Zeigt eine Statistik über alle Knoten an die die gegebene
- Firmware-Version installiert haben."""
- # initialize result dictionary
- result = { }
- for branch in [ 'stable', 'testing' ]:
- result[branch] = None
- skipped = 0
- # command is restricted to bot-admins via PM or OPs in the channel
- if (not (trigger.admin and trigger.is_privmsg)) and (not trigger.nick in bot.ops[trigger.sender]):
- bot.say('Geh zur dunklen Seite, die haben Kekse - ohne Keks kein Rollout-Status.')
- return
- # get expected firmware version from command arguments
- expected_release = trigger.group(2)
- if expected_release is None or len(expected_release) == 0:
- bot.say('Von welcher Firmware denn?')
- return
- # check each node in ALFRED data
- for nodeid in alfred_data:
- item = alfred_data[nodeid]
- if (not 'software' in item) or (not 'firmware' in item['software']) or (not 'autoupdater' in item['software']):
- skipped+=1
- continue
- release = item['software']['firmware']['release']
- branch = item['software']['autoupdater']['branch']
- enabled = item['software']['autoupdater']['enabled']
- if not branch in result or result[branch] is None:
- result[branch] = { 'auto_count': 0, 'auto_not': 0, 'manual_count': 0, 'manual_not': 0, 'total': 0 }
- result[branch]['total'] += 1
- match = 'count' if release == expected_release else 'not'
- mode = 'auto' if enabled else 'manual'
- result[branch][mode+'_ '+match] += 1
- # respond to user
- output = "Rollout von '{0}':".format(expected_release)
- for branch in result:
- auto_count = result[branch]['auto_count']
- auto_total = auto_count + result[branch]['auto_not']
- manual_count = result[branch]['manual_count']
- manual_total = manual_count + result[branch]['manual_not']
- bot.say("Rollout von '{0}': {1} = {2}/{3} per Auto-Update, {4}/{5} manuell".format(expected_release, branch, auto_count, auto_total, manual_count, manual_total))
- # output count of nodes for which the autoupdater-branch and/or firmware version could not be retrieved
- if skipped > 0:
- bot.say("Rollout von '{0}': {1} Knoten unklar".format(expected_release, skipped))
|