[nanny/win32: 17/75] Add NannyPyroBus Support



commit 0c6350353cb4fa74cb6babc9c1fcaeee454ba8fd
Author: Roberto Majadas <roberto majadas openshine com>
Date:   Thu Sep 16 12:43:57 2010 +0200

    Add NannyPyroBus Support

 daemon/src/Daemon.py       |    7 ++-
 daemon/src/Makefile.am     |    3 +-
 daemon/src/NannyPyroBus.py |  192 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 200 insertions(+), 2 deletions(-)
---
diff --git a/daemon/src/Daemon.py b/daemon/src/Daemon.py
index 4fd184e..01b99d3 100644
--- a/daemon/src/Daemon.py
+++ b/daemon/src/Daemon.py
@@ -28,7 +28,8 @@ from QuarterBack import QuarterBack
 
 if os.name == "posix":
     from NannyDBus import NannyDBus
-
+elif os.name == "nt":
+    from NannyPyroBus import start_pyro_bus
 import nanny.daemon.proxy
 
 import signal
@@ -38,7 +39,11 @@ import os
 class Daemon :
     def __init__(self, app):
         self.quarterback = QuarterBack(app)
+
         if os.name == "posix" :
             self.bus = NannyDBus(self.quarterback)
+	elif os.name == "nt" :
+            from twisted.internet import reactor
+            start_pyro_bus(self.quarterback)
         
 
diff --git a/daemon/src/Makefile.am b/daemon/src/Makefile.am
index de04ab8..ea98bb8 100644
--- a/daemon/src/Makefile.am
+++ b/daemon/src/Makefile.am
@@ -17,7 +17,8 @@ corelib_PYTHON =	 __init__.py 			\
 			Win32WebContentFiltering.py	\
 			Win32UsersManager.py		\
 			Win32SessionFiltering.py	\
-			Win32Chrono.py
+			Win32Chrono.py			\
+			NannyPyroBus.py
 
 if HAS_HACHOIR_REGEX
 dgimporterdir = $(pythondir)/nanny/daemon
diff --git a/daemon/src/NannyPyroBus.py b/daemon/src/NannyPyroBus.py
new file mode 100644
index 0000000..25a09e2
--- /dev/null
+++ b/daemon/src/NannyPyroBus.py
@@ -0,0 +1,192 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2009,2010 Junta de Andalucia
+# 
+# Authors:
+#   Roberto Majadas <roberto.majadas at openshine.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+from twisted.internet import threads, reactor, defer
+import Pyro.core
+import threading
+import time
+
+
+class OrgGnomeNanny(Pyro.core.ObjBase):
+    def __init__(self, quarterback):
+        Pyro.core.ObjBase.__init__(self)
+        self.quarterback = quarterback
+        self.quarterback.connect('update-users-info', self.__UpdateUsersInfo_cb)
+        self.events = []
+
+    def IsUnLocked(self):
+        return False
+
+    def UnLock(self):
+        return True
+
+    def ListUsers(self):
+        return threads.blockingCallFromThread(reactor, self.quarterback.usersmanager.get_users)
+
+    def SetBlocks(self, user_id, app_id, blocks):
+        threads.blockingCallFromThread(reactor, self.quarterback.set_blocks, str(user_id), int(app_id), blocks)
+        return True
+
+    def GetBlocks(self, user_id, app_id) :
+        return threads.blockingCallFromThread(reactor, self.quarterback.get_blocks, user_id, app_id)
+
+    def SetActiveWCF(self, active, uid):
+        threads.blockingCallFromThread(reactor, self.quarterback.set_wcf, bool(active), str(uid))
+
+    def ListWCF(self):
+        return threads.blockingCallFromThread(reactor, self.quarterback.list_wcf_uids)
+
+    def SetMaxUseTime(self, user_id, app_id, mins):
+        threads.blockingCallFromThread(reactor, self.quarterback.set_max_use_time, str(user_id), int(app_id), int(mins))
+
+    def GetMaxUseTime(self, user_id, app_id):
+        return threads.blockingCallFromThread(reactor, self.quarterback.get_max_use_time , user_id, app_id)
+    
+    # FIXME : Singal
+    #def UpdateUsersInfo(self):
+    #    pass
+
+    def __UpdateUsersInfo_cb(self, quarterback):
+        #self.UpdateUsersInfo()
+        self.events.append((time.time(), "update-users-info", None))
+        self.__clear_old_events()
+
+    def __clear_old_events(self):
+        pass
+
+    def GetEventsFromTimeStamp(self, timestamp):
+        ret = []
+        for event in self.events :
+            if event[0] > timestamp :
+                ret.append(event)
+        return ret 
+
+
+class OrgGnomeNannyNotification(Pyro.core.ObjBase):
+    def __init__(self, quarterback):
+        Pyro.core.ObjBase.__init__(self)
+        self.quarterback = quarterback
+        self.quarterback.connect('block-status', self.__UserNotification_cb)
+        self.events = []
+
+    # FIXME : Singal
+    #def UserNotification(self, block_status, user_id, app_id, next_change, available_time):
+    #    pass
+
+    def __UserNotification_cb(self, quarterback, block_status, user_id, app_id, next_change, available_time):
+        #self.UserNotification(block_status, user_id, app_id, next_change, available_time)
+        self.events.append((time.time(), "user-notification", 
+                            (block_status, user_id, app_id, next_change, available_time)))
+        self.__clear_old_events()
+
+    def __clear_old_events(self):
+        pass
+
+    def GetEventsFromTimeStamp(self, timestamp):
+        ret = []
+        for event in self.events :
+            if event[0] > timestamp :
+                ret.append(event)
+        return ret 
+    
+class OrgGnomeNannyWebDatabase(Pyro.core.ObjBase):
+    def __init__(self, quarterback):
+        Pyro.core.ObjBase.__init__(self)
+        self.quarterback = quarterback
+        
+    def AddCustomFilter(self, uid, is_black, name, description, regex):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.add_custom_filter, str(uid), bool(is_black), unicode(name),
+                                              unicode(description), unicode(regex))
+
+    def ListCustomFilters(self, uid):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.list_custom_filters, int(uid))
+    
+    def RemoveCustomFilter(self, list_id):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.remove_custom_filter, int(list_id))
+
+    def UpdateCustomFilter(self, list_id, name, description, regex):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.update_custom_filter, int(list_id),
+                                              unicode(name),
+                                              unicode(description),
+                                              unicode(regex))
+    
+    def AddPkgFilter(self, path):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.add_pkg_filter, str(path))
+    
+    def RemovePkgFilter(self, pkg_id):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.remove_pkg_filter, str(pkg_id))
+
+    def UpdatePkgFilter(self, pkg_id, new_db_path):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.update_pkg_filter, str(pkg_id), str (new_db_path))
+
+    def ListPkgFilters(self):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.list_pkg_filter)
+
+    def GetPkgFilterMetadata(self, pkg_id):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.get_pkg_filter_metadata, str(pkg_id))
+
+    def SetPkgFilterMetadata(self, pkg_id, name, description):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.set_pkg_filter_metadata, str(pkg_id), unicode(name), unicode(description))
+
+    def GetPkgFilterUserCategories(self, pkg_id, uid):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.get_pkg_filter_user_categories, unicode(pkg_id),
+                                              str(uid)
+                                              )
+
+    def SetPkgFilterUserCategories(self, pkg_id, uid, list_categories):
+        list_c = []
+        for x in list_categories :
+            list_c.append(unicode(x))
+            
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.set_pkg_filter_user_categories, unicode(pkg_id),
+                                              str(uid),
+                                              list_c)
+
+    def CheckDomain(self, uid, domain):
+        return threads.blockingCallFromThread(reactor, self.quarterback.filter_manager.check_domain, uid, domain)
+
+    def AddDansGuardianList(self, uid, name, description, list_url):
+        return threads.blockingCallFromThread(reactor, self.quarterback.webcontent_filter.webdb.add_dans_guardian_list, str(uid),
+                                              unicode(name),
+                                              unicode(description),
+                                              unicode(list_url))
+    
+
+def inThread(quarterback):
+    Pyro.core.initServer()
+    daemon=Pyro.core.Daemon()
+
+    uries = []
+    uries.append(daemon.connect(OrgGnomeNanny(quarterback),"org.gnome.Nanny"))
+    uries.append(daemon.connect(OrgGnomeNannyNotification(quarterback),"org.gnome.Nanny.Notification"))
+    uries.append(daemon.connect(OrgGnomeNannyWebDatabase(quarterback),"org.gnome.Nanny.WebDatabase"))
+
+    print "The daemon runs on port:",daemon.port
+    for uri in uries :
+        print "   The object's uri is:",uri
+    reactor.addSystemEventTrigger("before", "shutdown", daemon.shutdown)
+    daemon.requestLoop()
+
+def start_pyro_bus(quarterback):
+    reactor.callInThread(inThread, quarterback)
+
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]