##// END OF EJS Templates
Clean up after comments by Tom from his branch review.
Fernando Perez -
Show More
@@ -1,109 +1,103 b''
1 1 # -*- coding: utf-8 -*-
2 2 """ Proxy module for accessing platform specific utility functions.
3 3
4 4 Importing this module should give you the implementations that are correct
5 5 for your operation system, from platutils_PLATFORMNAME module.
6 6 """
7 7
8 8 #*****************************************************************************
9 9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
10 10 #
11 11 # Distributed under the terms of the BSD License. The full license is in
12 12 # the file COPYING, distributed as part of this software.
13 13 #*****************************************************************************
14 14
15 15 import os
16 16 import sys
17 17 import warnings
18 18
19 19 # Import the platform-specific implementations
20 20 if os.name == 'posix':
21 21 import platutils_posix as _platutils
22 22 elif sys.platform == 'win32':
23 23 import platutils_win32 as _platutils
24 24 else:
25 25 import platutils_dummy as _platutils
26 import warnings
27 warnings.warn("Platutils not available for platform '%s', some features may be missing" %
28 os.name)
29 del warnings
30
31 26
32 27 # Functionality that's logically common to all platforms goes here, each
33 28 # platform-specific module only provides the bits that are OS-dependent.
34 29
35 30 # XXX - I'm still not happy with a module global for this, but at least now
36 31 # there is a public, cross-platform way of toggling the term title control on
37 32 # and off. We should make this a stateful object later on so that each user
38 33 # can have its own instance if needed.
39 34 def term_clear():
40 35 _platutils.term_clear()
41 36
42 37 def toggle_set_term_title(val):
43 38 """Control whether set_term_title is active or not.
44 39
45 40 set_term_title() allows writing to the console titlebar. In embedded
46 41 widgets this can cause problems, so this call can be used to toggle it on
47 42 or off as needed.
48 43
49 44 The default state of the module is for the function to be disabled.
50 45
51 46 Parameters
52 47 ----------
53 48 val : bool
54 49 If True, set_term_title() actually writes to the terminal (using the
55 50 appropriate platform-specific module). If False, it is a no-op.
56 51 """
57 52 _platutils.ignore_termtitle = not(val)
58 53
59 54
60 55 def set_term_title(title):
61 56 """Set terminal title using the necessary platform-dependent calls."""
62 57
63 58 if _platutils.ignore_termtitle:
64 59 return
65 60 _platutils.set_term_title(title)
66 61
67 62
68 63 class FindCmdError(Exception):
69 64 pass
70 65
71 66 def find_cmd(cmd):
72 67 """Find full path to executable cmd in a cross platform manner.
73 68
74 69 This function tries to determine the full path to a command line program
75 70 using `which` on Unix/Linux/OS X and `win32api` on Windows. Most of the
76 71 time it will use the version that is first on the users `PATH`. If
77 72 cmd is `python` return `sys.executable`.
78 73
79 74 Parameters
80 75 ----------
81 76 cmd : str
82 77 The command line program to look for.
83 78 """
84 79 if cmd == 'python':
85 80 return sys.executable
86 81 try:
87 82 path = _platutils.find_cmd(cmd)
88 83 except:
89 84 raise FindCmdError('command could not be found: %s' % cmd)
90 85 # which returns empty if not found
91 86 if path == '':
92 87 raise FindCmdError('command could not be found: %s' % cmd)
93 88 return path
94 89
95 90 def get_long_path_name(path):
96 91 """Expand a path into its long form.
97 92
98 93 On Windows this expands any ~ in the paths. On other platforms, it is
99 94 a null operation.
100 95 """
101 96 return _platutils.get_long_path_name(path)
102 97
103 98 #-----------------------------------------------------------------------------
104 99 # Deprecated functions
105 100 #-----------------------------------------------------------------------------
106 101 def freeze_term_title():
107 import warnings
108 102 warnings.warn("This function is deprecated, use toggle_set_term_title()")
109 103 _platutils.ignore_termtitle = True
General Comments 0
You need to be logged in to leave comments. Login now