src/eric7/SystemUtilities/OSUtilities.py

branch
eric7
changeset 10431
64157aeb0312
parent 10339
446d22fa1aea
child 10439
21c28b0f9e41
equal deleted inserted replaced
10430:e440aaf179ce 10431:64157aeb0312
69 69
70 def getUserName(): 70 def getUserName():
71 """ 71 """
72 Function to get the user name. 72 Function to get the user name.
73 73
74 @return user name (string) 74 @return user name
75 @rtype str
75 """ 76 """
76 user = getpass.getuser() 77 user = getpass.getuser()
77 78
78 if isWindowsPlatform() and not user: 79 if isWindowsPlatform() and not user:
79 return win32_GetUserName() 80 return win32_GetUserName()
83 84
84 def getRealName(): 85 def getRealName():
85 """ 86 """
86 Function to get the real name of the user. 87 Function to get the real name of the user.
87 88
88 @return real name of the user (string) 89 @return real name of the user
90 @rtype str
89 """ 91 """
90 if isWindowsPlatform(): 92 if isWindowsPlatform():
91 return win32_getRealName() 93 return win32_getRealName()
92 else: 94 else:
93 user = getpass.getuser() 95 user = getpass.getuser()
96 98
97 def getHomeDir(): 99 def getHomeDir():
98 """ 100 """
99 Function to get a users home directory. 101 Function to get a users home directory.
100 102
101 @return home directory (string) 103 @return home directory
104 @rtype str
102 """ 105 """
103 return os.path.expanduser("~") 106 return os.path.expanduser("~")
104 107
105 108
106 ############################################################################### 109 ###############################################################################
110 113
111 def getEnvironmentEntry(key, default=None): 114 def getEnvironmentEntry(key, default=None):
112 """ 115 """
113 Module function to get an environment entry. 116 Module function to get an environment entry.
114 117
115 @param key key of the requested environment entry (string) 118 @param key key of the requested environment entry
116 @param default value to be returned, if the environment doesn't contain 119 @type str
117 the requested entry (string) 120 @param default value to be returned, if the environment doesn't contain the
118 @return the requested entry or the default value, if the entry wasn't 121 requested entry
119 found (string or None) 122 @type str
123 @return the requested entry or the default value, if the entry wasn't found
124 @rtype str
120 """ 125 """
121 if key in os.environ: 126 if key in os.environ:
122 entryKey = key 127 entryKey = key
123 elif isWindowsPlatform() and key.lower() in os.environ: 128 elif isWindowsPlatform() and key.lower() in os.environ:
124 entryKey = key.lower() 129 entryKey = key.lower()
153 158
154 def win32_Kill(pid): 159 def win32_Kill(pid):
155 """ 160 """
156 Function to provide an os.kill equivalent for Win32. 161 Function to provide an os.kill equivalent for Win32.
157 162
158 @param pid process id (integer) 163 @param pid process id
159 @return result of the kill (boolean) 164 @type int
165 @return result of the kill
166 @rtype bool
160 """ 167 """
161 import win32api # __IGNORE_WARNING_I102__ 168 import win32api # __IGNORE_WARNING_I102__
162 169
163 handle = win32api.OpenProcess(1, 0, pid) 170 handle = win32api.OpenProcess(1, 0, pid)
164 return 0 != win32api.TerminateProcess(handle, 0) 171 return 0 != win32api.TerminateProcess(handle, 0)
166 173
167 def win32_GetUserName(): 174 def win32_GetUserName():
168 """ 175 """
169 Function to get the user name under Win32. 176 Function to get the user name under Win32.
170 177
171 @return user name (string) 178 @return user name
179 @rtype str
172 """ 180 """
173 try: 181 try:
174 import win32api # __IGNORE_WARNING_I10__ 182 import win32api # __IGNORE_WARNING_I10__
175 183
176 return win32api.GetUserName() 184 return win32api.GetUserName()
184 192
185 def win32_getRealName(): 193 def win32_getRealName():
186 """ 194 """
187 Function to get the user's real name (aka. display name) under Win32. 195 Function to get the user's real name (aka. display name) under Win32.
188 196
189 @return real name of the current user (string) 197 @return real name of the current user
198 @rtype str
190 """ 199 """
191 GetUserNameEx = ctypes.windll.secur32.GetUserNameExW 200 GetUserNameEx = ctypes.windll.secur32.GetUserNameExW
192 NameDisplay = 3 201 NameDisplay = 3
193 202
194 size = ctypes.pointer(ctypes.c_ulong(0)) 203 size = ctypes.pointer(ctypes.c_ulong(0))

eric ide

mercurial