def __update_cb(self, quarterback, block_status, user_id, app_id, next_change, available_time, active): '''Callback that updates the used times of the categories.''' if block_status == False: app_list = self.__get_application_list(self.categories) proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(user_id)) 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] 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 __logout_session_if_is_running(self, user_id): proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(user_id)) for proc in proclist: if gtop.proc_args(proc)[0] == "x-session-manager" or gtop.proc_args(proc)[0] == "gnome-session": users = self.quarterback.usersmanager.get_users() for uid, uname, ufname in users : if str(uid) == user_id : if not self.logout_petitions.has_key(user_id): self.logout_petitions[user_id] = 3 if self.logout_petitions[user_id] != 0 : print "Sending logout petition to '%s'" % uname cmd='su %s -c "`grep -z DBUS_SESSION_BUS_ADDRESS /proc/%s/environ | sed -e "s:\\r::g"` dbus-send --dest=\'org.gnome.SessionManager\' /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:0"' % (uname, proc) os.system(cmd) self.logout_petitions[user_id] = self.logout_petitions[user_id] - 1 return else: print "Sending Force logout petition to '%s'" % uname cmd='su %s -c "`grep -z DBUS_SESSION_BUS_ADDRESS /proc/%s/environ | sed -e "s:\\r::g"` dbus-send --dest=\'org.gnome.SessionManager\' /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1"' % (uname, proc) os.system(cmd) self.logout_petitions.pop(user_id) return if self.logout_petitions.has_key(user_id) : self.logout_petitions.pop(user_id)
def __logout_session_if_is_running(self, user_id): proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(user_id)) for proc in proclist: if gtop.proc_args(proc)[0] == "x-session-manager" or gtop.proc_args(proc)[0] == "gnome-session": users = self.quarterback.usersmanager.get_users() for uid, uname, ufname in users: if str(uid) == user_id: if not self.logout_petitions.has_key(user_id): self.logout_petitions[user_id] = 3 if self.logout_petitions[user_id] != 0: print "Sending logout petition to '%s'" % uname cmd = ( 'su %s -c "`grep -z DBUS_SESSION_BUS_ADDRESS /proc/%s/environ | sed -e "s:\\r::g"` dbus-send --dest=\'org.gnome.SessionManager\' /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:0"' % (uname, proc) ) os.system(cmd) self.logout_petitions[user_id] = self.logout_petitions[user_id] - 1 return else: print "Sending Force logout petition to '%s'" % uname cmd = ( 'su %s -c "`grep -z DBUS_SESSION_BUS_ADDRESS /proc/%s/environ | sed -e "s:\\r::g"` dbus-send --dest=\'org.gnome.SessionManager\' /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1"' % (uname, proc) ) os.system(cmd) self.logout_petitions.pop(user_id) return if self.logout_petitions.has_key(user_id): self.logout_petitions.pop(user_id)
def __close_session_fallback(self): """Fallback for the moments org.gnome.SessionManager doesn't connect""" proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(self.uid)) for proc in proclist: if len(gtop.proc_args(proc))==0: continue if gtop.proc_args(proc)[0] == "x-session-manager" or gtop.proc_args(proc)[0] == "/usr/bin/x-session-manager" or gtop.proc_args(proc)[0] == "/usr/bin/gnome-session" or gtop.proc_args(proc)[0] == "gnome-session" or gtop.proc_args(proc)[0] == "/usr/bin/lxsession" or gtop.proc_args(proc)[0] == "lxsession": cmd = "kill -9 %s" % (proc) print "Executing fallback:", cmd Popen(cmd, shell=True, stdout=PIPE)
def __remote_close_session(self, user_id): proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(user_id)) for proc in proclist: if gtop.proc_args(proc)[0] == "x-session-manager" or gtop.proc_args(proc)[0] == "gnome-session": users = self.quarterback.usersmanager.get_users() for uid, uname, ufname in users : if str(uid) == user_id : print "Sending Force logout petition to '%s'" % uname cmd='su %s -c "`grep -z DBUS_SESSION_BUS_ADDRESS /proc/%s/environ | sed -e "s:\\r::g"` dbus-send --dest=\'org.gnome.SessionManager\' /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1"' % (uname, proc) os.system(cmd) return
def __remote_close_session(self, user_id): proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(user_id)) for proc in proclist: if gtop.proc_args( proc)[0] == "x-session-manager" or gtop.proc_args( proc)[0] == "gnome-session": users = self.quarterback.usersmanager.get_users() for uid, uname, ufname in users: if str(uid) == user_id: print "Sending Force logout petition to '%s'" % uname cmd = 'su %s -c "`grep -z DBUS_SESSION_BUS_ADDRESS /proc/%s/environ | sed -e "s:\\r::g"` dbus-send --dest=\'org.gnome.SessionManager\' /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1"' % ( uname, proc) os.system(cmd) return
def get_proc_name(pid): if pid == 0: return "unknown" try: return os.path.basename(gtop.proc_args(pid)[0]) except IndexError: return "none"
def _do_reload_menu(self): if not self.active: return this_items = {} if self._mode == "applications": if self.bamf_matcher != None: for window in self.bamf_matcher.RunningApplications(): try: item = self._get_item_for_bamf_application(window) this_items[item.id] = item except Exception as e: logger.debug("Could not get info from BAMF", exc_info = e) pass else: import wnck screen = wnck.screen_get_default() for window in screen.get_windows(): pid = window.get_pid() if pid > 0: item = self._get_menu_item(pid) item.process_name = window.get_name() this_items[item.id] = item pixbuf = window.get_icon() if pixbuf: item.icon = g15cairo.pixbuf_to_surface(pixbuf) else: for process_id in gtop.proclist(): process_id = "%d" % process_id try : pid = int(process_id) proc_state = gtop.proc_state(pid) proc_args = gtop.proc_args(pid) if self._mode == "all" or ( self._mode != "all" and proc_state.uid == os.getuid()): item = self._get_menu_item(pid) item.icon = None item.process_name = self._get_process_name(proc_args, proc_state.cmd) this_items[item.id] = item except Exception as e: logger.debug("Process may have disappeared", exc_info = e) # In case the process disappears pass # Remove any missing items for item in self.menu.get_children(): if not item.id in this_items: self.menu.remove_child(item) # Make sure selected still exists if self.menu.selected != None and self.menu.get_child_by_id(self.menu.selected.id) is None: if len(self.menu.get_child_count()) > 0: self.menu.selected = self.menu.get_children()[0] else: self.menu.selected = None self.page.mark_dirty() self.screen.redraw(self.page)
def __update_cb(self, quarterback, block_status, user_id, app_id, next_change, available_time): '''Callback that updates the used times of the categories.''' if block_status == False: app_list = self.__get_application_list(self.categories) proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(user_id)) 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 __close_session_fallback(self): """Fallback for the moments org.gnome.SessionManager doesn't connect""" proclist = gtop.proclist(gtop.PROCLIST_KERN_PROC_UID, int(self.uid)) for proc in proclist: if len(gtop.proc_args(proc)) == 0: continue if gtop.proc_args(proc)[0] == "x-session-manager" or gtop.proc_args( proc)[0] == "/usr/bin/x-session-manager" or gtop.proc_args( proc)[0] == "/usr/bin/gnome-session" or gtop.proc_args( proc)[0] == "gnome-session" or gtop.proc_args( proc )[0] == "/usr/bin/lxsession" or gtop.proc_args( proc)[0] == "lxsession": cmd = "kill -9 %s" % (proc) print "Executing fallback:", cmd Popen(cmd, shell=True, stdout=PIPE)
def is_flash(pid): for arg in gtop.proc_args(pid): if arg.endswith("/libflashplayer.so"): return True return False
def _do_reload_menu(self): if not self.active: return this_items = {} if self._mode == "applications": if self.bamf_matcher != None: for window in self.bamf_matcher.RunningApplications(): try: item = self._get_item_for_bamf_application(window) this_items[item.id] = item except Exception as e: logger.debug("Could not get info from BAMF", exc_info=e) pass else: import wnck screen = wnck.screen_get_default() for window in screen.get_windows(): pid = window.get_pid() if pid > 0: item = self._get_menu_item(pid) item.process_name = window.get_name() this_items[item.id] = item pixbuf = window.get_icon() if pixbuf: item.icon = g15cairo.pixbuf_to_surface(pixbuf) else: for process_id in gtop.proclist(): process_id = "%d" % process_id try: pid = int(process_id) proc_state = gtop.proc_state(pid) proc_args = gtop.proc_args(pid) if self._mode == "all" or (self._mode != "all" and proc_state.uid == os.getuid()): item = self._get_menu_item(pid) item.icon = None item.process_name = self._get_process_name( proc_args, proc_state.cmd) this_items[item.id] = item except Exception as e: logger.debug("Process may have disappeared", exc_info=e) # In case the process disappears pass # Remove any missing items for item in self.menu.get_children(): if not item.id in this_items: self.menu.remove_child(item) # Make sure selected still exists if self.menu.selected != None and self.menu.get_child_by_id( self.menu.selected.id) is None: if len(self.menu.get_child_count()) > 0: self.menu.selected = self.menu.get_children()[0] else: self.menu.selected = None self.page.mark_dirty() self.screen.redraw(self.page)