3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

stats: add an --all option to 'uptime', and check for disconnected networks

This commit is contained in:
James Lu 2017-01-30 00:18:50 -08:00
parent efded33f4a
commit b5cf2e8a4e

View File

@ -28,9 +28,10 @@ DEFAULT_TIME_FORMAT = "%a, %d %b %Y %H:%M:%S +0000"
@utils.add_cmd
def uptime(irc, source, args):
"""[<network>]
"""[<network> / --all]
Returns the uptime for PyLink and the given network's connection (or the current network if not specified)."""
Returns the uptime for PyLink and the given network's connection (or the current network if not specified).
The --all argument can also be given to show the uptime for all networks."""
permissions.checkPermissions(irc, source, ['stats.uptime'])
try:
@ -38,14 +39,20 @@ def uptime(irc, source, args):
except IndexError:
network = irc.name
if network == '--all': # XXX: we really need smart argument parsing some time
# Filter by all connected networks.
ircobjs = {k:v for k,v in world.networkobjects.items() if v.connected.is_set()}
else:
try:
ircobj = world.networkobjects[network]
ircobjs = {network: world.networkobjects[network]}
except KeyError:
irc.error("No such network %r." % network)
return
if not world.networkobjects[network].connected.is_set():
irc.error("Network %s is not connected." % network)
return
current_time = int(time.time())
time_format = conf.conf.get('stats', {}).get('time_format', DEFAULT_TIME_FORMAT)
irc.reply("PyLink uptime: \x02%s\x02 (started on %s)" %
@ -53,6 +60,8 @@ def uptime(irc, source, args):
time.strftime(time_format, time.gmtime(world.start_ts))
)
)
for network, ircobj in sorted(ircobjs.items()):
irc.reply("Connected to %s: \x02%s\x02 (connected on %s)" %
(network,
timediff(ircobj.start_ts, current_time),