Show More
@@ -88,6 +88,14 b' def find_cmd(cmd):' | |||||
88 | raise FindCmdError('command could not be found: %s' % cmd) |
|
88 | raise FindCmdError('command could not be found: %s' % cmd) | |
89 | return path |
|
89 | return path | |
90 |
|
90 | |||
|
91 | def get_long_path_name(path): | |||
|
92 | """Expand a path into its long form. | |||
|
93 | ||||
|
94 | On Windows this expands any ~ in the paths. On other platforms, it is | |||
|
95 | a null operation. | |||
|
96 | """ | |||
|
97 | return _platutils.get_long_path_name(path) | |||
|
98 | ||||
91 | #----------------------------------------------------------------------------- |
|
99 | #----------------------------------------------------------------------------- | |
92 | # Deprecated functions |
|
100 | # Deprecated functions | |
93 | #----------------------------------------------------------------------------- |
|
101 | #----------------------------------------------------------------------------- |
@@ -27,3 +27,7 b' def set_term_title(*args,**kw):' | |||||
27 | def find_cmd(cmd): |
|
27 | def find_cmd(cmd): | |
28 | """Find the full path to a command using which.""" |
|
28 | """Find the full path to a command using which.""" | |
29 | return os.popen('which %s' % cmd).read().strip() |
|
29 | return os.popen('which %s' % cmd).read().strip() | |
|
30 | ||||
|
31 | def get_long_path_name(path): | |||
|
32 | """Dummy no-op.""" | |||
|
33 | return path |
@@ -34,3 +34,7 b' else:' | |||||
34 | def find_cmd(cmd): |
|
34 | def find_cmd(cmd): | |
35 | """Find the full path to a command using which.""" |
|
35 | """Find the full path to a command using which.""" | |
36 | return os.popen('which %s' % cmd).read().strip() |
|
36 | return os.popen('which %s' % cmd).read().strip() | |
|
37 | ||||
|
38 | def get_long_path_name(path): | |||
|
39 | """Dummy no-op.""" | |||
|
40 | return path |
@@ -54,3 +54,29 b' def find_cmd(cmd):' | |||||
54 | except: |
|
54 | except: | |
55 | (path, offset) = win32api.SearchPath(os.environ['PATH'],cmd + '.bat') |
|
55 | (path, offset) = win32api.SearchPath(os.environ['PATH'],cmd + '.bat') | |
56 | return path |
|
56 | return path | |
|
57 | ||||
|
58 | ||||
|
59 | def get_long_path_name(path): | |||
|
60 | """Get a long path name (expand ~) on Windows using ctypes. | |||
|
61 | ||||
|
62 | Examples | |||
|
63 | -------- | |||
|
64 | ||||
|
65 | >>> get_long_path_name('c:\\docume~1') | |||
|
66 | u'c:\\\\Documents and Settings' | |||
|
67 | ||||
|
68 | """ | |||
|
69 | try: | |||
|
70 | import ctypes | |||
|
71 | except ImportError: | |||
|
72 | raise ImportError('you need to have ctypes installed for this to work') | |||
|
73 | _GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW | |||
|
74 | _GetLongPathName.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p, | |||
|
75 | ctypes.c_uint ] | |||
|
76 | ||||
|
77 | buf = ctypes.create_unicode_buffer(260) | |||
|
78 | rv = _GetLongPathName(path, buf, 260) | |||
|
79 | if rv == 0 or rv > 260: | |||
|
80 | return path | |||
|
81 | else: | |||
|
82 | return buf.value |
@@ -213,6 +213,13 b' def make_runners():' | |||||
213 | if have_pexpect: |
|
213 | if have_pexpect: | |
214 | top_mod.append('irunner.py') |
|
214 | top_mod.append('irunner.py') | |
215 |
|
215 | |||
|
216 | if sys.platform == 'win32': | |||
|
217 | top_mod.append('platutils_win32.py') | |||
|
218 | elif os.name == 'posix': | |||
|
219 | top_mod.append('platutils_posix.py') | |||
|
220 | else: | |||
|
221 | top_mod.append('platutils_dummy.py') | |||
|
222 | ||||
216 | # These are tested by nose, so skip IPython.kernel |
|
223 | # These are tested by nose, so skip IPython.kernel | |
217 | top_pack = ['config','Extensions','frontend', |
|
224 | top_pack = ['config','Extensions','frontend', | |
218 | 'testing','tests','tools','UserConfig'] |
|
225 | 'testing','tests','tools','UserConfig'] |
@@ -10,7 +10,7 b' import types' | |||||
10 |
|
10 | |||
11 | import nose.tools as nt |
|
11 | import nose.tools as nt | |
12 |
|
12 | |||
13 | from IPython.platutils import find_cmd |
|
13 | from IPython.platutils import find_cmd, get_long_path_name | |
14 | from IPython.testing import decorators as dec |
|
14 | from IPython.testing import decorators as dec | |
15 | from IPython.testing import tools as tt |
|
15 | from IPython.testing import tools as tt | |
16 |
|
16 | |||
@@ -206,14 +206,16 b' class TestMagicRun(object):' | |||||
206 | self.tmpfile = f |
|
206 | self.tmpfile = f | |
207 |
|
207 | |||
208 | def run_tmpfile(self): |
|
208 | def run_tmpfile(self): | |
|
209 | # This fails on Windows if self.tmpfile.name has spaces or "~" in it. | |||
|
210 | # See below and ticket https://bugs.launchpad.net/bugs/366353 | |||
209 | _ip.magic('run %s' % self.tmpfile.name) |
|
211 | _ip.magic('run %s' % self.tmpfile.name) | |
210 |
|
212 | |||
211 | # See https://bugs.launchpad.net/bugs/366353 |
|
213 | # See https://bugs.launchpad.net/bugs/366353 | |
212 | @dec.skip_if_not_win32 |
|
214 | @dec.skip_if_not_win32 | |
213 | def test_run_tempfile_path(self): |
|
215 | def test_run_tempfile_path(self): | |
214 | # self.run_tmpfile() # This is what triggers the error! |
|
|||
215 | tt.assert_equals(True,False,"%run doesn't work with tempfile paths on win32.") |
|
216 | tt.assert_equals(True,False,"%run doesn't work with tempfile paths on win32.") | |
216 |
|
217 | |||
|
218 | # See https://bugs.launchpad.net/bugs/366353 | |||
217 | @dec.skip_win32 |
|
219 | @dec.skip_win32 | |
218 | def test_builtins_id(self): |
|
220 | def test_builtins_id(self): | |
219 | """Check that %run doesn't damage __builtins__ """ |
|
221 | """Check that %run doesn't damage __builtins__ """ | |
@@ -224,6 +226,7 b' class TestMagicRun(object):' | |||||
224 | bid2 = id(_ip.user_ns['__builtins__']) |
|
226 | bid2 = id(_ip.user_ns['__builtins__']) | |
225 | tt.assert_equals(bid1, bid2) |
|
227 | tt.assert_equals(bid1, bid2) | |
226 |
|
228 | |||
|
229 | # See https://bugs.launchpad.net/bugs/366353 | |||
227 | @dec.skip_win32 |
|
230 | @dec.skip_win32 | |
228 | def test_builtins_type(self): |
|
231 | def test_builtins_type(self): | |
229 | """Check that the type of __builtins__ doesn't change with %run. |
|
232 | """Check that the type of __builtins__ doesn't change with %run. | |
@@ -235,6 +238,7 b' class TestMagicRun(object):' | |||||
235 | self.run_tmpfile() |
|
238 | self.run_tmpfile() | |
236 | tt.assert_equals(type(_ip.user_ns['__builtins__']),type(sys)) |
|
239 | tt.assert_equals(type(_ip.user_ns['__builtins__']),type(sys)) | |
237 |
|
240 | |||
|
241 | # See https://bugs.launchpad.net/bugs/366353 | |||
238 | @dec.skip_win32 |
|
242 | @dec.skip_win32 | |
239 | def test_prompts(self): |
|
243 | def test_prompts(self): | |
240 | """Test that prompts correctly generate after %run""" |
|
244 | """Test that prompts correctly generate after %run""" |
@@ -20,7 +20,7 b' import sys' | |||||
20 |
|
20 | |||
21 | import nose.tools as nt |
|
21 | import nose.tools as nt | |
22 |
|
22 | |||
23 | from IPython.platutils import find_cmd, FindCmdError |
|
23 | from IPython.platutils import find_cmd, FindCmdError, get_long_path_name | |
24 | from IPython.testing import decorators as dec |
|
24 | from IPython.testing import decorators as dec | |
25 |
|
25 | |||
26 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
@@ -46,3 +46,14 b' def test_find_cmd():' | |||||
46 | def test_find_cmd_fail(): |
|
46 | def test_find_cmd_fail(): | |
47 | """Make sure that FindCmdError is raised if we can't find the cmd.""" |
|
47 | """Make sure that FindCmdError is raised if we can't find the cmd.""" | |
48 | nt.assert_raises(FindCmdError,find_cmd,'asdfasdf') |
|
48 | nt.assert_raises(FindCmdError,find_cmd,'asdfasdf') | |
|
49 | ||||
|
50 | @dec.skip_if_not_win32 | |||
|
51 | def test_get_long_path_name_win32(): | |||
|
52 | p = get_long_path_name('c:\\docume~1') | |||
|
53 | nt.assert_equals(p,u'c:\\Documents and Settings') | |||
|
54 | ||||
|
55 | @dec.skip_win32 | |||
|
56 | def test_get_long_path_name(): | |||
|
57 | p = get_long_path_name('/usr/local') | |||
|
58 | nt.assert_equals(p,'/usr/local') | |||
|
59 |
General Comments 0
You need to be logged in to leave comments.
Login now