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