1 '''
2 ------------------------------------------------------------------------------
3 License
4 This file is part of blueCAPE's modifications to PyFoam for working on
5 Windows. For more information on these modifications, visit:
6 http://www.bluecape.com.pt/blueCFD
7
8 PyFoam is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2 of the License, or (at your
11 option) any later version. See the file COPYING in this directory,
12 for a description of the GNU General Public License terms under which
13 you can copy the files.
14
15 Script
16 winhacks.py
17
18 Description
19 This script file acts mostly as a dummy stub for several POSIX functions
20 that are not available on Windows and on Python for Windows.
21 Source code available on this file is a compilation of public domain
22 solutions.
23
24 ------------------------------------------------------------------------------
25 '''
26
27 import os
28
29 __CSL = None
31 '''symlink(source, link_name)
32 Creates a symbolic link pointing to source named link_name'''
33 global __CSL
34 if __CSL is None:
35 import ctypes
36 csl = ctypes.windll.kernel32.CreateSymbolicLinkW
37 csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
38 csl.restype = ctypes.c_ubyte
39 __CSL = csl
40 flags = 0
41 if source is not None and os.path.isdir(source):
42 flags = 1
43 if __CSL(link_name, source, flags) == 0:
44 raise ctypes.WinError()
45
47 '''getlogin()
48 Get login username from environment.'''
49 return os.getenv('USERNAME')
50
52 '''Dummy result, 1 to avoid division by zero'''
53 return 1
54
55 '''hack the three functions above into the os module'''
56 os.symlink = symlink
57 os.getlogin = getlogin
58 os.getloadavg = getloadavg
59
60 """These 3 can be improved if we use http://code.google.com/p/psutil/"""
61 """All return 1 to avoid divisions by zero"""
64
67
68 RUSAGE_CHILDREN = 1
69