Translation update done using Pootle.
[wammu.git] / Wammu / OSUtils.py
blob360453bf62e7bc28b8afd67dde0605d18ec56049
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 OS dependant helper functions.
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import sys
27 import os
28 if sys.platform == 'win32':
29 from win32com.shell import shellcon, shell
30 import win32api
31 import pywintypes
33 def GetUserFullName():
34 '''
35 Detects full user name from system information.
36 '''
37 if sys.platform == 'win32':
38 try:
39 return win32api.GetUserNameEx(win32api.NameDisplay)
40 except pywintypes.error:
41 return ''
42 else:
43 import pwd
45 name = pwd.getpwuid(os.getuid())[4]
46 if ',' in name:
47 name = name[:name.index(',')]
48 return name
50 def ExpandPath(orig):
51 '''
52 Expands user path. This is replaced on Windows, because python
53 implementation has problems with encodings.
54 '''
55 if sys.platform == 'win32':
56 if orig.startswith('~'):
57 userhome = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
58 return orig.replace('~', userhome, 1)
59 return orig
60 else:
61 return os.path.expanduser(orig)