Browse Source

code formatting, no functional changes

Helge Jung 9 years ago
parent
commit
a23f3eb0d9
2 changed files with 30 additions and 21 deletions
  1. 6 7
      modules/ffpb_netstatus.py
  2. 24 14
      modules/ffpb_nodeinfo.py

+ 6 - 7
modules/ffpb_netstatus.py

@@ -118,7 +118,7 @@ def ffpb_highscore(bot, trigger):
 
 @willie.module.commands('rollout-status')
 def ffpb_rolloutstatus(bot, trigger):
-    """Display statistic on how many nodes have installed the given firmware version."""
+    """Display statistic on how many nodes have installed which firmware."""
 
     # initialize results dictionary
     result = {}
@@ -142,9 +142,9 @@ def ffpb_rolloutstatus(bot, trigger):
             continue
 
         if not release in result or result[release] is None:
-            result[release] = {'stable': None, 'testing': None,}
+            result[release] = {'stable': None, 'testing': None, }
         if not branch in result[release] or result[release][branch] is None:
-            result[release][branch] = {'auto': 0, 'manual': 0, 'total': 0,}
+            result[release][branch] = {'auto': 0, 'manual': 0, 'total': 0, }
 
         result[release][branch]['total'] += 1
         mode = 'auto' if enabled else 'manual'
@@ -165,20 +165,19 @@ def ffpb_rolloutstatus(bot, trigger):
                 output += ','
             first = False
 
-            total = item['total']
             auto_count = item['auto']
             manual_count = item['manual']
 
-            output += ' {2} {0}'.format(branch, total, auto_count, manual_count)
+            output += ' {1} {0}'.format(branch, auto_count)
             if manual_count > 0:
-                output += ' (+{3} manuell)'.format(branch, total, auto_count, manual_count)
+                output += ' (+{0} manuell)'.format(manual_count)
 
         bot.say(output)
 
     # output count of nodes for which the autoupdater's branch and/or
     # firmware version could not be retrieved
     if skipped > 0:
-        bot.say('plus {0} Knoten deren Status gerade nicht abfragbar war'.format(skipped))
+        bot.say('plus {0} Knoten mit unklarem Status'.format(skipped))
 
 
 @willie.module.commands('providers')

+ 24 - 14
modules/ffpb_nodeinfo.py

@@ -41,7 +41,9 @@ def ffpb_peerdata(bot, trigger):
         if key in ['hostname']:
             continue
 
-        bot.say("{0}.{1} = {2}".format(node['hostname'], key, node[key]))
+        bot.say("{0}.{1} = {2}".format(
+            node.get('hostname', '?-' + target_name),
+            key, node[key]))
 
 
 @willie.module.commands('info')
@@ -112,30 +114,37 @@ def ffpb_lastseen(bot, trigger):
     if node is None:
         return
 
+    node_name = node.get('hostname')
+
     last_seen = node.get('__UPDATED__')
-    a_value = int(last_seen['alfred']) if (not last_seen is None) and 'alfred' in last_seen else None
-    a_delta = time.time() - a_value if not a_value is None else None
-    b_value = int(last_seen['batadv']) if (not last_seen is None) and 'batadv' in last_seen else None
-    b_delta = time.time() - b_value if not b_value is None else None
+    if last_seen is not None:
+        a_value = int(last_seen.get('alfred'))
+        b_value = int(last_seen.get('batadv'))
+    else:
+        a_value = b_value = None
+
+    a_delta = time.time() - a_value if a_value is not None else None
+    b_delta = time.time() - b_value if b_value is not None else None
 
     if a_value is None and b_value is None:
-        bot.say('{0} wurde offenbar noch gar nicht gesehen?'.format(node['hostname']))
+        bot.say('{0} wurde offenbar noch gar nicht gesehen?'.format(node_name))
         return
 
     if a_delta < 30 and b_delta < 30:
-        bot.say('{0} wurde gerade eben gesehen.'.format(node['hostname']))
+        bot.say('{0} wurde gerade eben gesehen.'.format(node_name))
         return
 
-    if a_value is not None and b_value is not None and abs(a_value - b_value) < 60:
+    if a_value is not None and b_value is not None and \
+       abs(a_value - b_value) < 60:
         bot.say('{0} wurde zuletzt gesehen: {1}'.format(
-                node['hostname'],
+                node_name,
                 pretty_date((a_value + b_value) / 2)))
     else:
         bot.say('{0} wurde zuletzt gesehen: {1} (ALFRED,) bzw. {2} (BATMAN)'.format(
-            node['hostname'],
-            pretty_date(a_value) if not a_value is None else "nie",
-            pretty_date(b_value) if not b_value is None else "nie"
-        ))
+                node_name,
+                pretty_date(a_value) if not a_value is None else "nie",
+                pretty_date(b_value) if not b_value is None else "nie"
+                ))
 
 
 @willie.module.commands('uptime')
@@ -194,4 +203,5 @@ def ffpb_peerlink(bot, trigger):
     info_v6 = mac2ipv6(info_mac, 'fdca:ffee:ff12:132:')
 
     # reply to user
-    bot.say('[{1}] mac {0} -> http://[{2}]/'.format(info_mac, info_name, info_v6))
+    bot.say('[{1}] mac {0} -> http://[{2}]/'.format(
+            info_mac, info_name, info_v6))