1 """Utilities relating to the system the software is running on.
2
3 """
4 """
5 ============================== License ========================================
6 Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding
7
8 This file is part of The Jazz Parser.
9
10 The Jazz Parser is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 The Jazz Parser is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with The Jazz Parser. If not, see <http://www.gnu.org/licenses/>.
22
23 ============================ End license ======================================
24
25 """
26 __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"
27
28 import platform
29 import subprocess
30
32 """
33 Tries to set the current process title. This is very system-dependent
34 and may fail in many cases.
35
36 @return: True if the process succeeds, False if there's an error
37
38 """
39 try:
40 import ctypes
41 libc = ctypes.CDLL('libc.so.6')
42 retcode = libc.prctl(15, '%s\0' % title, 0, 0, 0)
43 if retcode:
44 return False
45 except:
46 return False
47 else:
48 return True
49
51 """
52 Returns a string containing information to identify the system on which
53 you're currently running. This is useful to logging info. Don't try
54 matching against it - you'll be better off getting the components
55 separately.
56
57 """
58 import socket, os
59
60
61 hostname = socket.gethostname()
62
63
64 uname = ", ".join(os.uname())
65 return "%s (%s)" % (hostname, uname)
66
68 """
69 Tries to use a system-recommended application to open the given file.
70 Uses C{xdg-open} on Linux, C{start} on Windows and C{open}
71 on Mac.
72
73 """
74 if is_windows():
75 cmd = "start"
76 elif is_mac():
77 cmd = "open"
78 else:
79
80 cmd = "xdg-open"
81
82 subprocess.call([cmd, filename])
83
85 return platform.system().lower() == 'windows'
87 return platform.system().lower() == 'darwin'
89 return platform.system().lower() == 'linux'
90