[nanny/win32: 33/75] Add NannyService and build_py2exe stuff



commit c42a93f52e6100f5af9edcc11e55f3904ae33d5c
Author: Roberto Majadas <roberto majadas openshine com>
Date:   Thu Sep 23 20:14:04 2010 +0200

    Add NannyService and build_py2exe stuff

 daemon/Makefile.am         |    4 +-
 daemon/NannyService.py     |   94 ++++++++++++++++++++++++++++++++++++++++++++
 daemon/build_py2exe.py     |   87 ++++++++++++++++++++++++++++++++++++++++
 daemon/nanny-daemon-win.py |   48 ----------------------
 4 files changed, 183 insertions(+), 50 deletions(-)
---
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 3babaf1..7469932 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -4,8 +4,8 @@ tapdir = $(datadir)/nanny/daemon
 tap_DATA = nanny.tap
 
 if NANNY_WIN32_SUPPORT
-sbin_SCRIPTS = nanny-daemon-win.py
+sbin_SCRIPTS = NannyService.py build_py2exe.py
 endif
 
-EXTRA_DIST=$(tap_DATA) nanny-daemon-win.py
+EXTRA_DIST=$(tap_DATA) NannyService.py build_py2exe.py 
 
diff --git a/daemon/NannyService.py b/daemon/NannyService.py
new file mode 100644
index 0000000..be4366a
--- /dev/null
+++ b/daemon/NannyService.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+# Copyright (C) 2009 Roberto Majadas, Cesar Garcia, Luis de Bethencourt
+# <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
+
+import os
+import sys
+
+# Reactor stuff
+from twisted.application import app, service
+import twisted.internet.gtk2reactor
+twisted.internet.gtk2reactor.install()
+from twisted.internet import reactor
+reactor.suggestThreadPoolSize(30)
+
+# W32 service stuff
+import pythoncom
+import win32serviceutil
+import win32service
+import win32event
+import servicemanager
+
+#Add nanny module to python paths
+if not hasattr(sys, "frozen") :
+    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+    nanny_lib_path = os.path.join(root_path, "lib", "python2.6", "site-packages")
+    sys.path.append(nanny_lib_path)
+
+
+def main():
+    #Start UP application
+    import nanny.daemon
+    application = service.Application('nanny')
+    daemon = nanny.daemon.Daemon(application)
+
+    app_service = service.IService(application)
+    app_service.privilegedStartService()
+    app_service.startService()
+    reactor.addSystemEventTrigger('before', 'shutdown',
+                                  app_service.stopService)
+
+    #Reactor Run
+    reactor.run()
+
+class NannyService (win32serviceutil.ServiceFramework):
+    _svc_name_ = "NannyService"
+    _svc_display_name_ = "Nanny Daemon Service"
+
+    def __init__(self,args):
+        win32serviceutil.ServiceFramework.__init__(self,args)
+        self.hWaitStop = win32event.CreateEvent(None,0,0,None)
+
+    def SvcStop(self):
+        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
+        win32event.SetEvent(self.hWaitStop)
+
+    def SvcDoRun(self):
+        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
+                              servicemanager.PYS_SERVICE_STARTED,
+                              (self._svc_name_,''))
+        self.CheckForQuit()
+        self.main()
+
+    def CheckForQuit(self):
+            retval = win32event.WaitForSingleObject(self.hWaitStop, 10)
+            if not retval == win32event.WAIT_TIMEOUT:
+                # Received Quit from Win32
+                reactor.stop()
+                
+            reactor.callLater(1.0, self.CheckForQuit)
+
+    def main(self):
+        main()
+
+
+if __name__ == '__main__':
+    if len(sys.argv) == 1 :
+        main()
+    else:
+        win32serviceutil.HandleCommandLine(NannyService)
diff --git a/daemon/build_py2exe.py b/daemon/build_py2exe.py
new file mode 100644
index 0000000..6a53a94
--- /dev/null
+++ b/daemon/build_py2exe.py
@@ -0,0 +1,87 @@
+
+import sys, os, glob, stat
+
+nanny_top_dir = os.path.dirname(os.path.dirname(__file__))
+nanny_win32_dist_dir = os.path.join(nanny_top_dir, "NannyW32")
+nanny_python_dir = os.path.join(nanny_top_dir, "lib", "python2.6", "site-packages")
+
+sys.path.append(nanny_python_dir)
+
+if len(sys.argv) == 1:
+    sys.argv.append("py2exe")
+
+from distutils.core import setup
+import py2exe
+
+ver = "2.30"
+py2exe_options = dict (
+    packages = "encodings",
+    includes = ["sqlite3", "cairo", "pango", "pangocairo", "atk", "gobject"],
+    )
+
+#Share
+def walktree (top = ".", depthfirst = True):
+    names = os.listdir(top)
+    if not depthfirst:
+        yield top, names
+    for name in names:
+        try:
+            st = os.lstat(os.path.join(top, name))
+        except os.error:
+            continue
+        if stat.S_ISDIR(st.st_mode):
+            for (newtop, children) in walktree (os.path.join(top, name), depthfirst):
+                yield newtop, children
+    if depthfirst:
+        yield top, names
+
+share_files = []
+etc_files = []
+
+for (basepath, children) in walktree(os.path.join(nanny_top_dir, "share"),False):
+    for child in children:
+        if os.path.isfile(os.path.join(basepath, child)):
+            share_files.append(os.path.join(basepath, child))
+
+for (basepath, children) in walktree(os.path.join(nanny_top_dir, "etc"),False):
+    for child in children:
+        if os.path.isfile(os.path.join(basepath, child)):
+            etc_files.append(os.path.join(basepath, child))
+
+data_files = {}
+for file in share_files + etc_files:
+    path_dir = os.path.dirname(file).replace(nanny_top_dir, os.path.join("NannyW32\\"))
+    if path_dir not in data_files.keys():
+        data_files[path_dir] = []
+    data_files[path_dir].append(file)
+
+dist_files = []
+for key in data_files : 
+    dist_files.append([key, data_files[key]])
+
+dist_files
+
+#Setup of py2exe
+
+daemon_console = dict(
+    script = os.path.join(nanny_top_dir, "sbin", "NannyService.py"),
+    dest_base = os.path.join("NannyW32", "bin", "nanny-daemon-console"),
+)
+
+daemon_service = dict(
+    script = os.path.join(nanny_top_dir, "sbin", "NannyService.py"),
+    dest_base = os.path.join("NannyW32", "bin", "NannyService"),
+    modules=["NannyService"],
+    cmdline_style='pywin32',
+)
+
+setup(name="Nanny",
+      version=ver,
+      description="Nanny parental control",
+      #com_server=[outlook_addin],
+      console=[daemon_console],
+      service=[daemon_service],
+      data_files = dist_files,
+      options = {"py2exe" : py2exe_options},
+      zipfile = os.path.join("NannyW32", "lib", "nannylib.zip"),
+)



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