Trees | Indices | Help |
|
---|
|
1 # -*- coding: utf8 -*- 2 # 3 # Project: The EDNA Kernel 4 # http://www.edna-site.org 5 # 6 # File: "$Id: EDUtilsPath.py 1484 2010-05-05 07:08:21Z svensson $" 7 # 8 # Copyright (C) 2008-2010 European Synchrotron Radiation Facility 9 # Grenoble, France 10 # 11 # Principal authors: Jérôme Kieffer (jerome.kieffer@esrf.fr) 12 # 13 # 14 # This program is free software: you can redistribute it and/or modify 15 # it under the terms of the GNU Lesser General Public License as published 16 # by the Free Software Foundation, either version 3 of the License, or 17 # (at your option) any later version. 18 # 19 # This program is distributed in the hope that it will be useful, 20 # but WITHOUT ANY WARRANTY; without even the implied warranty of 21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 # GNU Lesser General Public License for more details. 23 # 24 # You should have received a copy of the GNU General Public License 25 # and the GNU Lesser General Public License along with this program. 26 # If not, see <http://www.gnu.org/licenses/>. 27 # 28 __authors__ = [ "Jérôme Kieffer" ] 29 __contact__ = "jerome.kieffer@esrf.fr" 30 __license__ = "LGPLv3+" 31 __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 32 33 34 import sys, os, math, distutils.util, signal, subprocess 35 from EDThreading import Semaphore 36 from EDVerbose import EDVerbose 4548 """ 49 Static class for guessing: platform specific stuff. 50 51 """ 52 __semaphore = Semaphore() 53 __semaphore.acquire() 54 __strCmdSep = None 55 __strCmdEnv = None 56 __strEscapedLineSep = None 57 __strLineSep = os.linesep 58 __strSep = os.sep 59 __strAltSep = os.altsep 60 __strExtSep = os.extsep 61 __strPathSep = os.pathsep 62 __strName = os.name 63 __strStartScript = None 64 __PythonPlatformSize = int(round(math.log(sys.maxint + 1) / math.log(2) + 1)) 65 66 __SystemPlatform = distutils.util.get_platform() 67 if __PythonPlatformSize == 32 and __SystemPlatform.endswith("x86_64"): 68 __PythonPlatform = __SystemPlatform[:-6] + "i386" 69 else: 70 __PythonPlatform = __SystemPlatform 71 __PythonArchitecture = "lib.%s-%i.%i" % (__PythonPlatform, sys.version_info[0], sys.version_info[1]) 72 if sys.maxunicode == 65535: 73 __PythonArchitecture += "-ucs2" 74 __SystemArchitecture = "lib.%s-%i.%i" % (__SystemPlatform, sys.version_info[0], sys.version_info[1]) 75 76 if os.name == "java": # Then we are running under Jython ! 77 from java.lang import System as javasystem 78 if javasystem.getProperty("os.name").startswith("Windows"): 79 __strName = "nt" 80 else: 81 __strName = "posix" 82 83 if __strName == "nt": 84 __strCmdSep = "&" 85 __strCmdEnv = "set" 86 __strEscapedSep = "/" 87 __strEscapedLineSep = "\\r\\n" 88 __strStartScript = "@ECHO OFF" 89 elif __strName == "posix": 90 __strCmdSep = ";" 91 __strCmdEnv = "env" 92 __strEscapedSep = "\\\\" 93 __strEscapedLineSep = "\\n" 94 __strStartScript = "#!%s" % sys.executable 95 __semaphore.release() 96 97 98 99 @classmethod292101 """ 102 Returns the name of the architecture including the CPU arch and the version of python for the actual running python 103 (i.e. can be i386 on a x86_64 computer) 104 @return: lib-$OS-$arch-$PyVersion 105 @rtype: python string 106 """ 107 return cls.__PythonArchitecture108 architecture = classproperty(getArchitecture) 109 110 111 @classmethod113 """ 114 Returns the name of the architecture including the CPU arch and the version of python for the actual operating system 115 @return: lib-$OS-$arch-$PyVersion 116 @rtype: python string 117 """ 118 return cls.__SystemArchitecture119 systemArchitecture = classproperty(getSystemArchitecture) 120 121 122 @classmethod124 """ 125 Returns the name of the architecture 126 @return: os.name like architecture (posix, nt, ... but never java even under jython) 127 @rtype: python string 128 """ 129 return cls.__strName130 name = classproperty(getName) 131 132 133 @classmethod135 """ 136 Returns the Command separator like 137 - Under Unix: cmd1;cmd2 138 - Under Windows cmd1 & cmd2 139 @return: "&" or ";" depending on the architecture 140 @rtype: python string 141 """ 142 return cls.__strCmdSep143 cmdSep = classproperty(getCmdSep) 144 145 146 @classmethod148 """ 149 @return: "env" or "set" to print the environment under the current operating system 150 """ 151 return cls.__strCmdEnv152 cmdEnv = classproperty(getCmdEnv) 153 154 155 @classmethod 161 escapedSep = classproperty(getEscapedSep) 162 163 164 @classmethod 170 escapedLinesep = classproperty(getEscapedLineSep) 171 172 173 @classmethod 179 linesep = classproperty(getLineSep) 180 181 182 @classmethod 188 sep = classproperty(getSep) 189 190 191 @classmethod193 """ 194 @return: header for writing scripts under the current the archtecture (#!/usr/bin/python under linux) 195 """ 196 return cls.__strStartScript197 startScript = classproperty(getStartScript) 198 199 200 @classmethod202 """ 203 @return: the size of the environment, probably 32 or 64 bits 204 """ 205 return cls.__PythonPlatformSize206 size = classproperty(getSize) 207 208 @classmethod210 """ 211 @return: linux-x86_64, if python 32bits is running under amd64 OS. 212 """ 213 return cls.__SystemPlatform214 systemPlatform = classproperty(getSystemPlatform) 215 216 217 @classmethod219 """ 220 @return: linux-i386, if python 32bits is running under amd64 OS. 221 """ 222 return cls.__PythonPlatform223 pythonPlatform = classproperty(getPythonPlatform) 224 225 226 @classmethod 232 altsep = classproperty(getAltSep) 233 234 235 @classmethod 241 extsep = classproperty(getExtSep) 242 243 244 @classmethod246 """ 247 same as os.pathsep 248 @return "/" under linux and "\" under windows. 249 """ 250 return cls.__strPathSep251 pathsep = classproperty(getPathSep) 252 253 @classmethod255 """ 256 escape \ (i.e. "\\") under windows as \\ (i.e. "\\\\") 257 @return escaped string suitable for metaprogramming 258 """ 259 return _string.replace("\\", "\\\\")260 261 262 @classmethod264 """ 265 implementation of a platform independent subprocess.Popen method 266 267 @return: subporcess.Popen instance. 268 """ 269 if os.name == "posix": #python under unix 270 kwargs["preexec_fn"] = os.setsid 271 return subprocess.Popen(*args, **kwargs)272 273 274 275 276 @classmethod278 """ 279 implementation of a platform independent kill method 280 281 @param _iPid: process ID 282 @type _iPid: integer 283 """ 284 EDVerbose.log("EDUtilsPlatorm.kill called on PID: %s" % _iPid) 285 if os.name == "posix": #python under unix 286 os.killpg(_iPid, signal.SIGKILL) 287 elif cls.architecture == "posix": #jython running under unix 288 os.kill(_iPid, signal.SIGKILL) 289 else: #windows, ... Nota: this only works from python2.7 under windows ! 290 EDVerbose.WARNING("Kill Called to PID= %s with signal %s" % (_iPid, signal.SIGTERM)) 291 os.kill(_iPid, signal.SIGTERM)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Fri Jun 20 03:53:33 2014 | http://epydoc.sourceforge.net |