##// END OF EJS Templates
Add searching of .py files to find_cmd so Twisted's trial runner is found....
Fernando Perez -
Show More
@@ -1,87 +1,94 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """ Platform specific utility functions, win32 version
2 """ Platform specific utility functions, win32 version
3
3
4 Importing this module directly is not portable - rather, import platutils
4 Importing this module directly is not portable - rather, import platutils
5 to use these functions in platform agnostic fashion.
5 to use these functions in platform agnostic fashion.
6 """
6 """
7
7
8 #*****************************************************************************
8 #*****************************************************************************
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #*****************************************************************************
13 #*****************************************************************************
14
14
15 import os
15 import os
16
16
17 ignore_termtitle = True
17 ignore_termtitle = True
18
18
19 try:
19 try:
20 import ctypes
20 import ctypes
21
21
22 SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW
22 SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW
23 SetConsoleTitleW.argtypes = [ctypes.c_wchar_p]
23 SetConsoleTitleW.argtypes = [ctypes.c_wchar_p]
24
24
25 def set_term_title(title):
25 def set_term_title(title):
26 """Set terminal title using ctypes to access the Win32 APIs."""
26 """Set terminal title using ctypes to access the Win32 APIs."""
27 SetConsoleTitleW(title)
27 SetConsoleTitleW(title)
28
28
29 except ImportError:
29 except ImportError:
30 def set_term_title(title):
30 def set_term_title(title):
31 """Set terminal title using the 'title' command."""
31 """Set terminal title using the 'title' command."""
32 global ignore_termtitle
32 global ignore_termtitle
33
33
34 try:
34 try:
35 # Cannot be on network share when issuing system commands
35 # Cannot be on network share when issuing system commands
36 curr = os.getcwd()
36 curr = os.getcwd()
37 os.chdir("C:")
37 os.chdir("C:")
38 ret = os.system("title " + title)
38 ret = os.system("title " + title)
39 finally:
39 finally:
40 os.chdir(curr)
40 os.chdir(curr)
41 if ret:
41 if ret:
42 # non-zero return code signals error, don't try again
42 # non-zero return code signals error, don't try again
43 ignore_termtitle = True
43 ignore_termtitle = True
44
44
45
45
46 def find_cmd(cmd):
46 def find_cmd(cmd):
47 """Find the full path to a .bat or .exe using the win32api module."""
47 """Find the full path to a .bat or .exe using the win32api module."""
48 try:
48 try:
49 import win32api
49 from win32api import SearchPath
50 except ImportError:
50 except ImportError:
51 raise ImportError('you need to have pywin32 installed for this to work')
51 raise ImportError('you need to have pywin32 installed for this to work')
52 else:
52 else:
53 try:
53 PATH = os.environ['PATH']
54 (path, offest) = win32api.SearchPath(os.environ['PATH'],cmd + '.exe')
54 extensions = ['.exe', '.com', '.bat', '.py']
55 except:
55 path = None
56 (path, offset) = win32api.SearchPath(os.environ['PATH'],cmd + '.bat')
56 for ext in extensions:
57 return path
57 try:
58 path = SearchPath(PATH,cmd + ext)[0]
59 except:
60 pass
61 if path is None:
62 raise OSError("command %r not found" % cmd)
63 else:
64 return path
58
65
59
66
60 def get_long_path_name(path):
67 def get_long_path_name(path):
61 """Get a long path name (expand ~) on Windows using ctypes.
68 """Get a long path name (expand ~) on Windows using ctypes.
62
69
63 Examples
70 Examples
64 --------
71 --------
65
72
66 >>> get_long_path_name('c:\\docume~1')
73 >>> get_long_path_name('c:\\docume~1')
67 u'c:\\\\Documents and Settings'
74 u'c:\\\\Documents and Settings'
68
75
69 """
76 """
70 try:
77 try:
71 import ctypes
78 import ctypes
72 except ImportError:
79 except ImportError:
73 raise ImportError('you need to have ctypes installed for this to work')
80 raise ImportError('you need to have ctypes installed for this to work')
74 _GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
81 _GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
75 _GetLongPathName.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p,
82 _GetLongPathName.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p,
76 ctypes.c_uint ]
83 ctypes.c_uint ]
77
84
78 buf = ctypes.create_unicode_buffer(260)
85 buf = ctypes.create_unicode_buffer(260)
79 rv = _GetLongPathName(path, buf, 260)
86 rv = _GetLongPathName(path, buf, 260)
80 if rv == 0 or rv > 260:
87 if rv == 0 or rv > 260:
81 return path
88 return path
82 else:
89 else:
83 return buf.value
90 return buf.value
84
91
85
92
86 def term_clear():
93 def term_clear():
87 os.system('cls')
94 os.system('cls')
General Comments 0
You need to be logged in to leave comments. Login now