From 16b36f99a327b5cdfa180e8b0a2ecae54e12ac45 Mon Sep 17 00:00:00 2001 From: "adrian.sampson" Date: Tue, 24 Mar 2009 02:47:34 +0000 Subject: [PATCH] first implementation of stats --HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40147 --- beets/library.py | 11 ----------- beets/player/bpd.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/beets/library.py b/beets/library.py index d14c3a2a8..c6b9a2bba 100644 --- a/beets/library.py +++ b/beets/library.py @@ -527,17 +527,6 @@ class ResultIterator(object): def __iter__(self): return self - def count(self): - """Returns the number of matched rows and invalidates the - iterator. - """ - # Apparently, there is no good way to get the number of rows - # returned by an sqlite SELECT. - num = 0 - for i in self: - num += 1 - return num - def next(self): try: row = self.cursor.next() diff --git a/beets/player/bpd.py b/beets/player/bpd.py index d47973602..4f8f255c5 100755 --- a/beets/player/bpd.py +++ b/beets/player/bpd.py @@ -11,6 +11,7 @@ from string import Template import beets import traceback import logging +import time DEFAULT_PORT = 6600 @@ -178,6 +179,7 @@ class Server(object): """Block and start listening for connections from clients. An interrupt (^C) closes the server. """ + self.startup_time = time.time() try: self.listener = eventlet.api.tcp_listener((self.host, self.port)) while True: @@ -831,6 +833,19 @@ class BGServer(Server): ] return response + def cmd_stats(self): + # The first three items need to be done more efficiently. The + # last three need to be implemented. + out = ['artists: ' + str(len(self.lib.artists())), + 'albums: ' + str(len(self.lib.albums())), + 'songs: ' + str(len(list(self.lib.items()))), + 'uptime: ' + str(int(time.time() - self.startup_time)), + 'playtime: ' + '0', + 'db_playtime: ' + '0', + 'db_update: ' + '0', + ] + return SuccessResponse(out) + # The functions below hook into the half-implementations provided # by the base class. Together, they're enough to implement all # normal playback functionality.