X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2Fsalome_utils.py;h=cf87ef39d3c055ee6bcacd2498865018456d44b3;hb=eb8bb67cf17a6cd12ef957ab2f60b98258af2279;hp=43ffaba7cb52bfc396bbfad5e0d461462979d4e0;hpb=cca750d0050e94eae9ea9ca05bee79a3ce454882;p=modules%2Fkernel.git diff --git a/bin/salome_utils.py b/bin/salome_utils.py index 43ffaba7c..cf87ef39d 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -127,13 +127,17 @@ def getUserName(): """ Get user name: 1. try USER environment variable (USERNAME on windows) - 2. if fails, return 'unknown' as default user name + 2. if fails, try LOGNAME (un*x) + 3. if fails return 'unknown' as default user name """ import os, sys if sys.platform == "win32": return os.getenv("USERNAME", "unknown") else: - return os.getenv("USER", "unknown") + user = os.getenv("USER") + if user: + return user + return os.getenv("LOGNAME", "unknown") # --- def getHostName(): @@ -479,4 +483,17 @@ def setVerbose(level): global _verbose _verbose = level return + +# -- + +def win32killpid(pid): + """ + Kill process by pid on windows platform. + """ + if verbose(): print "######## win32killpid pid = ", pid + import ctypes + handle = ctypes.windll.kernel32.OpenProcess(1, False, pid) + ret = ctypes.windll.kernel32.TerminateProcess(handle, -1) + ctypes.windll.kernel32.CloseHandle(handle) + return ret # --