[tuxdroid-svn] r5101 - in software_suite_v3/smart-core/smart-server/trunk: . util util/misc util/s
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-07-10 10:45:40
|
Author: remi
Date: 2009-07-10 12:45:26 +0200 (Fri, 10 Jul 2009)
New Revision: 5101
Added:
software_suite_v3/smart-core/smart-server/trunk/util/smartcore/
software_suite_v3/smart-core/smart-server/trunk/util/smartcore/OldProcessKiller.py
software_suite_v3/smart-core/smart-server/trunk/util/smartcore/__init__.py
software_suite_v3/smart-core/smart-server/trunk/util/system/TaskBar.py
Modified:
software_suite_v3/smart-core/smart-server/trunk/tuxhttpserver.py
software_suite_v3/smart-core/smart-server/trunk/util/misc/URLTools.py
Log:
* Refresh task bar at server start/stop
* Improved server kill on Windows
Modified: software_suite_v3/smart-core/smart-server/trunk/tuxhttpserver.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/tuxhttpserver.py 2009-07-10 07:15:50 UTC (rev 5100)
+++ software_suite_v3/smart-core/smart-server/trunk/tuxhttpserver.py 2009-07-10 10:45:26 UTC (rev 5101)
@@ -16,86 +16,33 @@
import os
import getopt
+from util.smartcore.OldProcessKiller import killOldSmartCoreChildren
+from util.smartcore.OldProcessKiller import killPreviousSmartServer
+from util.system.TaskBar import refreshTaskBar
+from util.misc.URLTools import URLTestRequestGet
from TDSConfiguration import *
-def killOldChildrenWin32():
- import win32api
- from win32com.client import GetObject
- WMI = GetObject('winmgmts:')
- processes = WMI.InstancesOf('Win32_Process')
- pidToKill = []
- for process in processes:
- name = process.Properties_('Name').Value
- cmdLine = process.Properties_('CommandLine').Value
- if name == "python.exe":
- if cmdLine.find('executables') != -1:
- pidToKill.append(process.Properties_('ProcessId').Value)
- continue
- if cmdLine != None:
- if cmdLine.lower().find('workforplugins') != -1:
- pidToKill.append(process.Properties_('ProcessId').Value)
- continue
- if (cmdLine.lower().find('smart-server') != -1) and \
- (cmdLine.lower().find('util') != -1):
- pidToKill.append(process.Properties_('ProcessId').Value)
- continue
- for pid in pidToKill:
- try:
- handle = win32api.OpenProcess(1, False, pid)
- win32api.TerminateProcess(handle, -1)
- win32api.CloseHandle(handle)
- except:
- pass
-
-def killOldChildrenUnix():
- pass
-
def checkServerRun():
- import httplib
- h = httplib.HTTP("127.0.0.1:%d" % TDS_HTTP_PORT)
- try:
- h.connect()
- h.putrequest("GET", "/")
- h.endheaders()
- code, st, msg = h.getreply()
- if code != 200:
- return False
- else:
- return True
- except:
- return False
+ return URLTestRequestGet("127.0.0.1", TDS_HTTP_PORT, "/", 200, 5.0)
def killServer():
- if os.name == "nt":
- killOldChildrenWin32()
- else:
- killOldChildrenUnix()
- import httplib
- h = httplib.HTTP("127.0.0.1:%d" % TDS_HTTP_PORT)
- try:
- h.connect()
- h.putrequest("GET", "/server/stop?")
- h.endheaders()
- h.getreply()
- h.putrequest("GET", "/server/stop?")
- h.endheaders()
- h.getreply()
- except:
- return
+ killOldSmartCoreChildren()
+ URLTestRequestGet("127.0.0.1", TDS_HTTP_PORT, "/server/stop?", 200, 0.5)
+ URLTestRequestGet("127.0.0.1", TDS_HTTP_PORT, "/server/stop?", 200, 0.5)
+ killPreviousSmartServer()
+ refreshTaskBar()
def killServerAndWait():
import time
killServer()
- time.sleep(1.0)
+ time.sleep(0.5)
while checkServerRun():
- time.sleep(1.0)
+ time.sleep(0.5)
def runServer():
- if os.name == "nt":
- killOldChildrenWin32()
- else:
- killOldChildrenUnix()
- import TuxDroidServer
+ killOldSmartCoreChildren()
+ killPreviousSmartServer()
+ refreshTaskBar()
from TuxDroidServer import initializeServer
from TuxDroidServer import httpServer
from TuxDroidServer import finalizeServer
Modified: software_suite_v3/smart-core/smart-server/trunk/util/misc/URLTools.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/util/misc/URLTools.py 2009-07-10 07:15:50 UTC (rev 5100)
+++ software_suite_v3/smart-core/smart-server/trunk/util/misc/URLTools.py 2009-07-10 10:45:26 UTC (rev 5101)
@@ -14,6 +14,7 @@
import socket
import urllib2
+import httplib
import os
# ==============================================================================
@@ -123,6 +124,44 @@
return result
# ------------------------------------------------------------------------------
+# Send a request to a http server and check the result.
+# ------------------------------------------------------------------------------
+def URLTestRequestGet(host, port, request, expectedCode = 200, timeout = 5.0):
+ """Send a request to a http server and check the result.
+ @host: Server host.
+ @port: Server port.
+ @request: Request.
+ @expectedCode: Expected server code.
+ @timeout: Connection timeout.
+ @return: A boolean.
+ """
+ # Save the old default connection timeout
+ old_timeout = socket.getdefaulttimeout()
+ # Set the default connection timeout
+ socket.setdefaulttimeout(timeout)
+ # Create requester
+ h = httplib.HTTP("%s:%d" % (host, port))
+ # Initialize the result
+ result = False
+ try:
+ # Connect the host
+ h.connect()
+ # Configure request
+ h.putrequest("GET", request)
+ h.endheaders()
+ # Execute the request
+ code, st, msg = h.getreply()
+ # Check the resulting code
+ if code == expectedCode:
+ result = True
+ except:
+ pass
+ # Restore the old default connection timeout
+ socket.setdefaulttimeout(old_timeout)
+ # Return the result
+ return result
+
+# ------------------------------------------------------------------------------
# Download a file from an URL.
# ------------------------------------------------------------------------------
def URLDownloadToFile(url, filePath, timeout = 5.0):
Added: software_suite_v3/smart-core/smart-server/trunk/util/smartcore/OldProcessKiller.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/util/smartcore/OldProcessKiller.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/util/smartcore/OldProcessKiller.py 2009-07-10 10:45:26 UTC (rev 5101)
@@ -0,0 +1,105 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <rem...@c2...>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+import os
+
+# ------------------------------------------------------------------------------
+# Kill all process alive from a previous instance of smart-core. Window.
+# ------------------------------------------------------------------------------
+def __killOldSmartCoreChildrenWin32():
+ """Kill all process alive from a previous instance of smart-core. Window.
+ """
+ import win32api
+ from win32com.client import GetObject
+ WMI = GetObject('winmgmts:')
+ processes = WMI.InstancesOf('Win32_Process')
+ pidToKill = []
+ for process in processes:
+ name = process.Properties_('Name').Value
+ cmdLine = process.Properties_('CommandLine').Value
+ if name == "python.exe":
+ if cmdLine.find('executables') != -1:
+ pidToKill.append(process.Properties_('ProcessId').Value)
+ continue
+ if cmdLine != None:
+ if cmdLine.lower().find('workforplugins') != -1:
+ pidToKill.append(process.Properties_('ProcessId').Value)
+ continue
+ if (cmdLine.lower().find('smart-server') != -1) and \
+ (cmdLine.lower().find('util') != -1):
+ pidToKill.append(process.Properties_('ProcessId').Value)
+ continue
+ for pid in pidToKill:
+ try:
+ handle = win32api.OpenProcess(1, False, pid)
+ win32api.TerminateProcess(handle, -1)
+ win32api.CloseHandle(handle)
+ except:
+ pass
+
+# ------------------------------------------------------------------------------
+# Kill previous smart-server. Window.
+# ------------------------------------------------------------------------------
+def __killPreviousSmartServerWin32():
+ """Kill previous smart-server. Window.
+ """
+ import win32api
+ from win32com.client import GetObject
+ WMI = GetObject('winmgmts:')
+ processes = WMI.InstancesOf('Win32_Process')
+ pidToKill = []
+ for process in processes:
+ name = process.Properties_('Name').Value
+ cmdLine = process.Properties_('CommandLine').Value
+ pid = process.Properties_('ProcessId').Value
+ if name.lower() == "pythonfortuxdroid.exe":
+ if cmdLine.find("tuxhttpserver") != -1:
+ if pid != os.getpid():
+ pidToKill.append(pid)
+ for pid in pidToKill:
+ try:
+ handle = win32api.OpenProcess(1, False, pid)
+ win32api.TerminateProcess(handle, -1)
+ win32api.CloseHandle(handle)
+ except:
+ pass
+
+# ------------------------------------------------------------------------------
+# Kill all process alive from a previous instance of smart-core. Unix.
+# ------------------------------------------------------------------------------
+def __killOldSmartCoreChildrenUnix():
+ """Kill all process alive from a previous instance of smart-core. Unix.
+ """
+ pass
+
+# ------------------------------------------------------------------------------
+# Kill previous smart-server. Unix.
+# ------------------------------------------------------------------------------
+def __killPreviousSmartServerUnix():
+ """Kill previous smart-server. Unix.
+ """
+ pass
+
+# ------------------------------------------------------------------------------
+# Kill all process alive from a previous instance of smart-core.
+# ------------------------------------------------------------------------------
+def killOldSmartCoreChildren():
+ """Kill all process alive from a previous instance of smart-core.
+ """
+ if os.name == "nt":
+ __killOldSmartCoreChildrenWin32()
+ else:
+ __killOldSmartCoreChildrenUnix()
+
+# ------------------------------------------------------------------------------
+# Kill previous smart-server.
+# ------------------------------------------------------------------------------
+def killPreviousSmartServer():
+ """Kill previous smart-server.
+ """
+ if os.name == "nt":
+ __killPreviousSmartServerWin32()
+ else:
+ __killPreviousSmartServerUnix()
Added: software_suite_v3/smart-core/smart-server/trunk/util/smartcore/__init__.py
===================================================================
Added: software_suite_v3/smart-core/smart-server/trunk/util/system/TaskBar.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/util/system/TaskBar.py (rev 0)
+++ software_suite_v3/smart-core/smart-server/trunk/util/system/TaskBar.py 2009-07-10 10:45:26 UTC (rev 5101)
@@ -0,0 +1,58 @@
+# Copyright (C) 2009 C2ME Sa
+# Remi Jocaille <rem...@c2...>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+import os
+
+# ------------------------------------------------------------------------------
+# Refresh the task bar. Window.
+# ------------------------------------------------------------------------------
+def __refreshTaskBarWin32():
+ """Refresh the task bar. Window.
+ """
+ import win32api
+ import win32gui
+ import win32con
+ def FW(x, y):
+ return win32gui.FindWindowEx(x, 0, y, "")
+ # Get TaskBar handle
+ hWnd = win32gui.FindWindowEx(
+ FW(FW(FW(0, "Shell_TrayWnd"), "TrayNotifyWnd"), "SysPager"),
+ 0,
+ "ToolbarWindow32",
+ "Notification Area")
+ # Get TaskBar area
+ rect = win32gui.GetClientRect(hWnd)
+ width = rect[2]
+ height = rect[3]
+ # Refresh TaskBar with a simulation of the mouse moving
+ for x in range(width / 4):
+ for y in range(height / 4):
+ xx = x * 4
+ yy = y * 4
+ win32api.SendMessage(
+ hWnd,
+ win32con.WM_MOUSEMOVE,
+ 0,
+ yy * 65536 + xx)
+
+# ------------------------------------------------------------------------------
+# Refresh the task bar. Unix.
+# ------------------------------------------------------------------------------
+def __refreshTaskBarUnix():
+ """Refresh the task bar. Unix.
+ """
+ pass
+
+# ------------------------------------------------------------------------------
+# Refresh the task bar.
+# ------------------------------------------------------------------------------
+def refreshTaskBar():
+ """Refresh the task bar.
+ """
+ if os.name == "nt":
+ __refreshTaskBarWin32()
+ else:
+ __refreshTaskBarUnix()
+
|