[nanny] Chrono session control Consolekit based
- From: Roberto Majadas <telemaco src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nanny] Chrono session control Consolekit based
- Date: Fri, 14 May 2010 20:47:44 +0000 (UTC)
commit 2a0eb1ac19c6b810b292784911d8ea6c893f9896
Author: Roberto Majadas <roberto majadas openshine com>
Date: Wed May 12 12:42:29 2010 +0200
Chrono session control Consolekit based
daemon/src/Chrono.py | 33 ++++++++++++++++++++++++++-------
daemon/src/QuarterBack.py | 2 ++
2 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/daemon/src/Chrono.py b/daemon/src/Chrono.py
index f25ef33..df84841 100644
--- a/daemon/src/Chrono.py
+++ b/daemon/src/Chrono.py
@@ -30,6 +30,8 @@ import gtop
import pickle
import datetime
+import dbus
+
(
SESSION_APPID,
WEB_APPID,
@@ -65,15 +67,32 @@ class Chrono(gobject.GObject) :
if block_status == False:
app_list = self.__get_application_list(self.categories)
proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(user_id))
-
- category = self.categories[app_id]
- found = False
- for proc in proclist:
- if len(gtop.proc_args(proc)) > 0:
- process = gtop.proc_args(proc)[0]
- if self.is_a_controlled_app(process, category, app_list):
+
+ if app_id == SESSION_APPID :
+ try:
+ d = dbus.SystemBus()
+ manager = dbus.Interface(d.get_object("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager"),
+ "org.freedesktop.ConsoleKit.Manager")
+ sessions = manager.GetSessionsForUnixUser(int(user_id))
+ for session_name in sessions :
+ session = dbus.Interface(d.get_object("org.freedesktop.ConsoleKit", session_name),
+ "org.freedesktop.ConsoleKit.Session")
+ x11_display = session.GetX11Display()
+ if x11_display == "":
+ continue
self.quarterback.subtract_time(user_id, app_id)
break
+ except:
+ print "Crash Chrono __update_cb"
+ else:
+ category = self.categories[app_id]
+ found = False
+ for proc in proclist:
+ if len(gtop.proc_args(proc)) > 0:
+ process = gtop.proc_args(proc)[0]
+ if self.is_a_controlled_app(process, category, app_list):
+ self.quarterback.subtract_time(user_id, app_id)
+ break
def is_a_controlled_app(self, process, category, app_list):
found = False
diff --git a/daemon/src/QuarterBack.py b/daemon/src/QuarterBack.py
index 4f7eb75..29ec76c 100644
--- a/daemon/src/QuarterBack.py
+++ b/daemon/src/QuarterBack.py
@@ -372,6 +372,8 @@ class QuarterBack(gobject.GObject) :
if self.chrono_times[userid].has_key(appid):
if self.get_available_time(userid, appid) > 0:
self.chrono_times[userid][appid]["used_time"] += time
+ print "Substract time (%s, %s) = %s" % (userid, appid,
+ self.chrono_times[userid][appid]["used_time"])
self.__save()
def new_chrono_day(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]