##// END OF EJS Templates
restore interactive/shell doc with warning...
MinRK -
Show More
@@ -1,14 +1,14 b''
1 ==================================
1 ==================================
2 Using IPython for interactive work
2 Using IPython for interactive work
3 ==================================
3 ==================================
4
4
5 .. toctree::
5 .. toctree::
6 :maxdepth: 2
6 :maxdepth: 2
7
7
8 tutorial.txt
8 tutorial.txt
9 tips.txt
9 tips.txt
10 reference.txt
10 reference.txt
11 .. shell.txt
11 shell.txt
12 qtconsole.txt
12 qtconsole.txt
13
13
14
14
@@ -1,293 +1,294 b''
1 .. _ipython_as_shell:
1 .. _ipython_as_shell:
2
2
3 =========================
3 =========================
4 IPython as a system shell
4 IPython as a system shell
5 =========================
5 =========================
6
6
7 .. warning::
7 .. warning::
8
8
9 As of the 0.11 version of IPython, some of the features and APIs
9 As of the 0.11 version of IPython, most of the APIs used by the shell
10 described in this section have been deprecated or are broken. Our plan
10 profile have been changed, so the profile currently does very little
11 is to continue to support these features, but they need to be updated
11 beyond changing the IPython prompt. To help restore the shell
12 to take advantage of recent API changes. Furthermore, this section
12 profile to past functionality described here, the old code is found in
13 of the documentation need to be updated to reflect all of these changes.
13 :file:`IPython/deathrow`, which needs to be updated to use the
14 APIs in 0.11.
14
15
15 Overview
16 Overview
16 ========
17 ========
17
18
18 The 'sh' profile optimizes IPython for system shell usage. Apart from
19 The 'sh' profile optimizes IPython for system shell usage. Apart from
19 certain job control functionality that is present in unix (ctrl+z does
20 certain job control functionality that is present in unix (ctrl+z does
20 "suspend"), the sh profile should provide you with most of the
21 "suspend"), the sh profile should provide you with most of the
21 functionality you use daily in system shell, and more. Invoke IPython
22 functionality you use daily in system shell, and more. Invoke IPython
22 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
23 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
23 the "pysh" shortcut in start menu.
24 the "pysh" shortcut in start menu.
24
25
25 If you want to use the features of sh profile as your defaults (which
26 If you want to use the features of sh profile as your defaults (which
26 might be a good idea if you use other profiles a lot of the time but
27 might be a good idea if you use other profiles a lot of the time but
27 still want the convenience of sh profile), add ``import ipy_profile_sh``
28 still want the convenience of sh profile), add ``import ipy_profile_sh``
28 to your $IPYTHON_DIR/ipy_user_conf.py.
29 to your $IPYTHON_DIR/ipy_user_conf.py.
29
30
30 The 'sh' profile is different from the default profile in that:
31 The 'sh' profile is different from the default profile in that:
31
32
32 * Prompt shows the current directory
33 * Prompt shows the current directory
33 * Spacing between prompts and input is more compact (no padding with
34 * Spacing between prompts and input is more compact (no padding with
34 empty lines). The startup banner is more compact as well.
35 empty lines). The startup banner is more compact as well.
35 * System commands are directly available (in alias table) without
36 * System commands are directly available (in alias table) without
36 requesting %rehashx - however, if you install new programs along
37 requesting %rehashx - however, if you install new programs along
37 your PATH, you might want to run %rehashx to update the persistent
38 your PATH, you might want to run %rehashx to update the persistent
38 alias table
39 alias table
39 * Macros are stored in raw format by default. That is, instead of
40 * Macros are stored in raw format by default. That is, instead of
40 '_ip.system("cat foo"), the macro will contain text 'cat foo')
41 '_ip.system("cat foo"), the macro will contain text 'cat foo')
41 * Autocall is in full mode
42 * Autocall is in full mode
42 * Calling "up" does "cd .."
43 * Calling "up" does "cd .."
43
44
44 The 'sh' profile is different from the now-obsolete (and unavailable)
45 The 'sh' profile is different from the now-obsolete (and unavailable)
45 'pysh' profile in that:
46 'pysh' profile in that:
46
47
47 * '$$var = command' and '$var = command' syntax is not supported
48 * '$$var = command' and '$var = command' syntax is not supported
48 * anymore. Use 'var = !command' instead (incidentally, this is
49 * anymore. Use 'var = !command' instead (incidentally, this is
49 * available in all IPython profiles). Note that !!command *will*
50 * available in all IPython profiles). Note that !!command *will*
50 * work.
51 * work.
51
52
52 Aliases
53 Aliases
53 =======
54 =======
54
55
55 All of your $PATH has been loaded as IPython aliases, so you should be
56 All of your $PATH has been loaded as IPython aliases, so you should be
56 able to type any normal system command and have it executed. See
57 able to type any normal system command and have it executed. See
57 %alias? and %unalias? for details on the alias facilities. See also
58 %alias? and %unalias? for details on the alias facilities. See also
58 %rehashx? for details on the mechanism used to load $PATH.
59 %rehashx? for details on the mechanism used to load $PATH.
59
60
60
61
61 Directory management
62 Directory management
62 ====================
63 ====================
63
64
64 Since each command passed by ipython to the underlying system is executed
65 Since each command passed by ipython to the underlying system is executed
65 in a subshell which exits immediately, you can NOT use !cd to navigate
66 in a subshell which exits immediately, you can NOT use !cd to navigate
66 the filesystem.
67 the filesystem.
67
68
68 IPython provides its own builtin '%cd' magic command to move in the
69 IPython provides its own builtin '%cd' magic command to move in the
69 filesystem (the % is not required with automagic on). It also maintains
70 filesystem (the % is not required with automagic on). It also maintains
70 a list of visited directories (use %dhist to see it) and allows direct
71 a list of visited directories (use %dhist to see it) and allows direct
71 switching to any of them. Type 'cd?' for more details.
72 switching to any of them. Type 'cd?' for more details.
72
73
73 %pushd, %popd and %dirs are provided for directory stack handling.
74 %pushd, %popd and %dirs are provided for directory stack handling.
74
75
75
76
76 Enabled extensions
77 Enabled extensions
77 ==================
78 ==================
78
79
79 Some extensions, listed below, are enabled as default in this profile.
80 Some extensions, listed below, are enabled as default in this profile.
80
81
81 envpersist
82 envpersist
82 ----------
83 ----------
83
84
84 %env can be used to "remember" environment variable manipulations. Examples::
85 %env can be used to "remember" environment variable manipulations. Examples::
85
86
86 %env - Show all environment variables
87 %env - Show all environment variables
87 %env VISUAL=jed - set VISUAL to jed
88 %env VISUAL=jed - set VISUAL to jed
88 %env PATH+=;/foo - append ;foo to PATH
89 %env PATH+=;/foo - append ;foo to PATH
89 %env PATH+=;/bar - also append ;bar to PATH
90 %env PATH+=;/bar - also append ;bar to PATH
90 %env PATH-=/wbin; - prepend /wbin; to PATH
91 %env PATH-=/wbin; - prepend /wbin; to PATH
91 %env -d VISUAL - forget VISUAL persistent val
92 %env -d VISUAL - forget VISUAL persistent val
92 %env -p - print all persistent env modifications
93 %env -p - print all persistent env modifications
93
94
94 ipy_which
95 ipy_which
95 ---------
96 ---------
96
97
97 %which magic command. Like 'which' in unix, but knows about ipython aliases.
98 %which magic command. Like 'which' in unix, but knows about ipython aliases.
98
99
99 Example::
100 Example::
100
101
101 [C:/ipython]|14> %which st
102 [C:/ipython]|14> %which st
102 st -> start .
103 st -> start .
103 [C:/ipython]|15> %which d
104 [C:/ipython]|15> %which d
104 d -> dir /w /og /on
105 d -> dir /w /og /on
105 [C:/ipython]|16> %which cp
106 [C:/ipython]|16> %which cp
106 cp -> cp
107 cp -> cp
107 == c:\bin\cp.exe
108 == c:\bin\cp.exe
108 c:\bin\cp.exe
109 c:\bin\cp.exe
109
110
110 ipy_app_completers
111 ipy_app_completers
111 ------------------
112 ------------------
112
113
113 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
114 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
114
115
115 ipy_rehashdir
116 ipy_rehashdir
116 -------------
117 -------------
117
118
118 Allows you to add system command aliases for commands that are not along your path. Let's say that you just installed Putty and want to be able to invoke it without adding it to path, you can create the alias for it with rehashdir::
119 Allows you to add system command aliases for commands that are not along your path. Let's say that you just installed Putty and want to be able to invoke it without adding it to path, you can create the alias for it with rehashdir::
119
120
120 [~]|22> cd c:/opt/PuTTY/
121 [~]|22> cd c:/opt/PuTTY/
121 [c:opt/PuTTY]|23> rehashdir .
122 [c:opt/PuTTY]|23> rehashdir .
122 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
123 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
123
124
124 Now, you can execute any of those commams directly::
125 Now, you can execute any of those commams directly::
125
126
126 [c:opt/PuTTY]|24> cd
127 [c:opt/PuTTY]|24> cd
127 [~]|25> putty
128 [~]|25> putty
128
129
129 (the putty window opens).
130 (the putty window opens).
130
131
131 If you want to store the alias so that it will always be available, do '%store putty'. If you want to %store all these aliases persistently, just do it in a for loop::
132 If you want to store the alias so that it will always be available, do '%store putty'. If you want to %store all these aliases persistently, just do it in a for loop::
132
133
133 [~]|27> for a in _23:
134 [~]|27> for a in _23:
134 |..> %store $a
135 |..> %store $a
135 |..>
136 |..>
136 |..>
137 |..>
137 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
138 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
138 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
139 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
139 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
140 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
140 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
141 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
141 ...
142 ...
142
143
143 mglob
144 mglob
144 -----
145 -----
145
146
146 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
147 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
147
148
148 [c:/ipython]|9> mglob *.py
149 [c:/ipython]|9> mglob *.py
149 [c:/ipython]|10> mglob *.py rec:*.txt
150 [c:/ipython]|10> mglob *.py rec:*.txt
150 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
151 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
151
152
152 Note that the first 2 calls will put the file list in result history (_, _9, _10), and the last one will assign it to 'workfiles'.
153 Note that the first 2 calls will put the file list in result history (_, _9, _10), and the last one will assign it to 'workfiles'.
153
154
154
155
155 Prompt customization
156 Prompt customization
156 ====================
157 ====================
157
158
158 The sh profile uses the following prompt configurations::
159 The sh profile uses the following prompt configurations::
159
160
160 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
161 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
161 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
162 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
162
163
163 You can change the prompt configuration to your liking by editing
164 You can change the prompt configuration to your liking by editing
164 ipy_user_conf.py.
165 ipy_user_conf.py.
165
166
166 String lists
167 String lists
167 ============
168 ============
168
169
169 String lists (IPython.utils.text.SList) are handy way to process output
170 String lists (IPython.utils.text.SList) are handy way to process output
170 from system commands. They are produced by ``var = !cmd`` syntax.
171 from system commands. They are produced by ``var = !cmd`` syntax.
171
172
172 First, we acquire the output of 'ls -l'::
173 First, we acquire the output of 'ls -l'::
173
174
174 [Q:doc/examples]|2> lines = !ls -l
175 [Q:doc/examples]|2> lines = !ls -l
175 ==
176 ==
176 ['total 23',
177 ['total 23',
177 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
178 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
178 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
179 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
179 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
180 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
180 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
181 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
181 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
182 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
182 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
183 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
183 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
184 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
184
185
185 Now, let's take a look at the contents of 'lines' (the first number is
186 Now, let's take a look at the contents of 'lines' (the first number is
186 the list element number)::
187 the list element number)::
187
188
188 [Q:doc/examples]|3> lines
189 [Q:doc/examples]|3> lines
189 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
190 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
190
191
191 0: total 23
192 0: total 23
192 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
193 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
193 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
194 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
194 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
195 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
195 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
196 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
196 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
197 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
197 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
198 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
198 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
199 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
199
200
200 Now, let's filter out the 'embed' lines::
201 Now, let's filter out the 'embed' lines::
201
202
202 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
203 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
203 [Q:doc/examples]|5> l2
204 [Q:doc/examples]|5> l2
204 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
205 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
205
206
206 0: total 23
207 0: total 23
207 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
208 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
208 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
209 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
209 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
210 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
210 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
211 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
211 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
212 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
212
213
213 Now, we want strings having just file names and permissions::
214 Now, we want strings having just file names and permissions::
214
215
215 [Q:doc/examples]|6> l2.fields(8,0)
216 [Q:doc/examples]|6> l2.fields(8,0)
216 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
217 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
217
218
218 0: total
219 0: total
219 1: example-demo.py -rw-rw-rw-
220 1: example-demo.py -rw-rw-rw-
220 2: example-gnuplot.py -rwxrwxrwx
221 2: example-gnuplot.py -rwxrwxrwx
221 3: extension.py -rwxrwxrwx
222 3: extension.py -rwxrwxrwx
222 4: seteditor.py -rwxrwxrwx
223 4: seteditor.py -rwxrwxrwx
223 5: seteditor.pyc -rwxrwxrwx
224 5: seteditor.pyc -rwxrwxrwx
224
225
225 Note how the line with 'total' does not raise IndexError.
226 Note how the line with 'total' does not raise IndexError.
226
227
227 If you want to split these (yielding lists), call fields() without
228 If you want to split these (yielding lists), call fields() without
228 arguments::
229 arguments::
229
230
230 [Q:doc/examples]|7> _.fields()
231 [Q:doc/examples]|7> _.fields()
231 <7>
232 <7>
232 [['total'],
233 [['total'],
233 ['example-demo.py', '-rw-rw-rw-'],
234 ['example-demo.py', '-rw-rw-rw-'],
234 ['example-gnuplot.py', '-rwxrwxrwx'],
235 ['example-gnuplot.py', '-rwxrwxrwx'],
235 ['extension.py', '-rwxrwxrwx'],
236 ['extension.py', '-rwxrwxrwx'],
236 ['seteditor.py', '-rwxrwxrwx'],
237 ['seteditor.py', '-rwxrwxrwx'],
237 ['seteditor.pyc', '-rwxrwxrwx']]
238 ['seteditor.pyc', '-rwxrwxrwx']]
238
239
239 If you want to pass these separated with spaces to a command (typical
240 If you want to pass these separated with spaces to a command (typical
240 for lists if files), use the .s property::
241 for lists if files), use the .s property::
241
242
242
243
243 [Q:doc/examples]|13> files = l2.fields(8).s
244 [Q:doc/examples]|13> files = l2.fields(8).s
244 [Q:doc/examples]|14> files
245 [Q:doc/examples]|14> files
245 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
246 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
246 [Q:doc/examples]|15> ls $files
247 [Q:doc/examples]|15> ls $files
247 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
248 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
248
249
249 SLists are inherited from normal python lists, so every list method is
250 SLists are inherited from normal python lists, so every list method is
250 available::
251 available::
251
252
252 [Q:doc/examples]|21> lines.append('hey')
253 [Q:doc/examples]|21> lines.append('hey')
253
254
254
255
255 Real world example: remove all files outside version control
256 Real world example: remove all files outside version control
256 ============================================================
257 ============================================================
257
258
258 First, capture output of "hg status"::
259 First, capture output of "hg status"::
259
260
260 [Q:/ipython]|28> out = !hg status
261 [Q:/ipython]|28> out = !hg status
261 ==
262 ==
262 ['M IPython\\extensions\\ipy_kitcfg.py',
263 ['M IPython\\extensions\\ipy_kitcfg.py',
263 'M IPython\\extensions\\ipy_rehashdir.py',
264 'M IPython\\extensions\\ipy_rehashdir.py',
264 ...
265 ...
265 '? build\\lib\\IPython\\Debugger.py',
266 '? build\\lib\\IPython\\Debugger.py',
266 '? build\\lib\\IPython\\extensions\\InterpreterExec.py',
267 '? build\\lib\\IPython\\extensions\\InterpreterExec.py',
267 '? build\\lib\\IPython\\extensions\\InterpreterPasteInput.py',
268 '? build\\lib\\IPython\\extensions\\InterpreterPasteInput.py',
268 ...
269 ...
269
270
270 (lines starting with ? are not under version control).
271 (lines starting with ? are not under version control).
271
272
272 ::
273 ::
273
274
274 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
275 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
275 [Q:/ipython]|36> junk
276 [Q:/ipython]|36> junk
276 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
277 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
277 ...
278 ...
278 10: build\bdist.win32\winexe\temp\_ctypes.py
279 10: build\bdist.win32\winexe\temp\_ctypes.py
279 11: build\bdist.win32\winexe\temp\_hashlib.py
280 11: build\bdist.win32\winexe\temp\_hashlib.py
280 12: build\bdist.win32\winexe\temp\_socket.py
281 12: build\bdist.win32\winexe\temp\_socket.py
281
282
282 Now we can just remove these files by doing 'rm $junk.s'.
283 Now we can just remove these files by doing 'rm $junk.s'.
283
284
284 The .s, .n, .p properties
285 The .s, .n, .p properties
285 =========================
286 =========================
286
287
287 The '.s' property returns one string where lines are separated by
288 The '.s' property returns one string where lines are separated by
288 single space (for convenient passing to system commands). The '.n'
289 single space (for convenient passing to system commands). The '.n'
289 property return one string where the lines are separated by '\n'
290 property return one string where the lines are separated by '\n'
290 (i.e. the original output of the function). If the items in string
291 (i.e. the original output of the function). If the items in string
291 list are file names, '.p' can be used to get a list of "path" objects
292 list are file names, '.p' can be used to get a list of "path" objects
292 for convenient file manipulation.
293 for convenient file manipulation.
293
294
@@ -1,127 +1,131 b''
1 #!python
1 #!python
2 """Windows-specific part of the installation"""
2 """Windows-specific part of the installation"""
3
3
4 import os, sys, shutil
4 import os, sys, shutil
5 pjoin = os.path.join
5 pjoin = os.path.join
6
6
7 # import setuptools if we can
7 # import setuptools if we can
8 try:
8 try:
9 import setuptools
9 import setuptools
10 except ImportError:
10 except ImportError:
11 pass
11 pass
12
12
13 def mkshortcut(target,description,link_file,*args,**kw):
13 def mkshortcut(target,description,link_file,*args,**kw):
14 """make a shortcut if it doesn't exist, and register its creation"""
14 """make a shortcut if it doesn't exist, and register its creation"""
15
15
16 create_shortcut(target, description, link_file,*args,**kw)
16 create_shortcut(target, description, link_file,*args,**kw)
17 file_created(link_file)
17 file_created(link_file)
18
18
19 def install():
19 def install():
20 """Routine to be run by the win32 installer with the -install switch."""
20 """Routine to be run by the win32 installer with the -install switch."""
21
21
22 from IPython.core.release import version
22 from IPython.core.release import version
23
23
24 # Get some system constants
24 # Get some system constants
25 prefix = sys.prefix
25 prefix = sys.prefix
26 python = pjoin(prefix, 'python.exe')
26 python = pjoin(prefix, 'python.exe')
27 pythonw = pjoin(prefix, 'pythonw.exe')
27 pythonw = pjoin(prefix, 'pythonw.exe')
28 have_setuptools = 'setuptools' in sys.modules
28 have_setuptools = 'setuptools' in sys.modules
29
29
30 if not have_setuptools:
30 if not have_setuptools:
31 # This currently doesn't work without setuptools,
31 # This currently doesn't work without setuptools,
32 # so don't bother making broken links
32 # so don't bother making broken links
33 return
33 return
34
34
35 # Lookup path to common startmenu ...
35 # Lookup path to common startmenu ...
36 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'), 'IPython')
36 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'), 'IPython')
37 # Create IPython entry ...
37 # Create IPython entry ...
38 if not os.path.isdir(ip_start_menu):
38 if not os.path.isdir(ip_start_menu):
39 os.mkdir(ip_start_menu)
39 os.mkdir(ip_start_menu)
40 directory_created(ip_start_menu)
40 directory_created(ip_start_menu)
41
41
42 # Create .py and .bat files to make things available from
42 # Create .py and .bat files to make things available from
43 # the Windows command line. Thanks to the Twisted project
43 # the Windows command line. Thanks to the Twisted project
44 # for this logic!
44 # for this logic!
45 programs = [
45 programs = [
46 'ipython',
46 'ipython',
47 'iptest',
47 'iptest',
48 'ipcontroller',
48 'ipcontroller',
49 'ipengine',
49 'ipengine',
50 'ipcluster',
50 'ipcluster',
51 'irunner'
51 'irunner'
52 ]
52 ]
53 scripts = pjoin(prefix,'scripts')
53 scripts = pjoin(prefix,'scripts')
54 if not have_setuptools:
54 if not have_setuptools:
55 # only create .bat files if we don't have setuptools
55 # only create .bat files if we don't have setuptools
56 for program in programs:
56 for program in programs:
57 raw = pjoin(scripts, program)
57 raw = pjoin(scripts, program)
58 bat = raw + '.bat'
58 bat = raw + '.bat'
59 py = raw + '.py'
59 py = raw + '.py'
60 # Create .py versions of the scripts
60 # Create .py versions of the scripts
61 shutil.copy(raw, py)
61 shutil.copy(raw, py)
62 # Create .bat files for each of the scripts
62 # Create .bat files for each of the scripts
63 bat_file = file(bat,'w')
63 bat_file = file(bat,'w')
64 bat_file.write("@%s %s %%*" % (python, py))
64 bat_file.write("@%s %s %%*" % (python, py))
65 bat_file.close()
65 bat_file.close()
66
66
67 # Now move onto setting the Start Menu up
67 # Now move onto setting the Start Menu up
68 ipybase = pjoin(scripts, 'ipython')
68 ipybase = pjoin(scripts, 'ipython')
69 if have_setuptools:
69 if have_setuptools:
70 # let setuptools take care of the scripts:
70 # let setuptools take care of the scripts:
71 ipybase = ipybase + '-script.py'
71 ipybase = ipybase + '-script.py'
72 workdir = "%HOMEDRIVE%%HOMEPATH%"
72 workdir = "%HOMEDRIVE%%HOMEPATH%"
73
73
74 link = pjoin(ip_start_menu, 'IPython.lnk')
74 link = pjoin(ip_start_menu, 'IPython.lnk')
75 cmd = '"%s"' % ipybase
75 cmd = '"%s"' % ipybase
76 mkshortcut(python, 'IPython', link, cmd, workdir)
76 mkshortcut(python, 'IPython', link, cmd, workdir)
77
77
78 link = pjoin(ip_start_menu, 'pysh.lnk')
78 # Disable pysh Start item until the profile restores functionality
79 cmd = '"%s" profile=pysh --init' % ipybase
79 # Most of this code is in IPython/deathrow, and needs to be updated
80 mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir)
80 # to 0.11 APIs
81
82 # link = pjoin(ip_start_menu, 'pysh.lnk')
83 # cmd = '"%s" profile=pysh --init' % ipybase
84 # mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir)
81
85
82 link = pjoin(ip_start_menu, 'pylab.lnk')
86 link = pjoin(ip_start_menu, 'pylab.lnk')
83 cmd = '"%s" profile=pylab --init' % ipybase
87 cmd = '"%s" profile=pylab --init' % ipybase
84 mkshortcut(python, 'IPython (pylab profile)', link, cmd, workdir)
88 mkshortcut(python, 'IPython (pylab profile)', link, cmd, workdir)
85
89
86 link = pjoin(ip_start_menu, 'ipcontroller.lnk')
90 link = pjoin(ip_start_menu, 'ipcontroller.lnk')
87 cmdbase = pjoin(scripts, 'ipcontroller')
91 cmdbase = pjoin(scripts, 'ipcontroller')
88 if have_setuptools:
92 if have_setuptools:
89 cmdbase += '-script.py'
93 cmdbase += '-script.py'
90 cmd = '"%s"' % cmdbase
94 cmd = '"%s"' % cmdbase
91 mkshortcut(python, 'IPython controller', link, cmd, workdir)
95 mkshortcut(python, 'IPython controller', link, cmd, workdir)
92
96
93 link = pjoin(ip_start_menu, 'ipengine.lnk')
97 link = pjoin(ip_start_menu, 'ipengine.lnk')
94 cmdbase = pjoin(scripts, 'ipengine')
98 cmdbase = pjoin(scripts, 'ipengine')
95 if have_setuptools:
99 if have_setuptools:
96 cmdbase += '-script.py'
100 cmdbase += '-script.py'
97 cmd = '"%s"' % cmdbase
101 cmd = '"%s"' % cmdbase
98 mkshortcut(python, 'IPython engine', link, cmd, workdir)
102 mkshortcut(python, 'IPython engine', link, cmd, workdir)
99
103
100 link = pjoin(ip_start_menu, 'ipythonqt.lnk')
104 link = pjoin(ip_start_menu, 'ipythonqt.lnk')
101 cmdbase = pjoin(scripts, 'ipython-qtconsole')
105 cmdbase = pjoin(scripts, 'ipython-qtconsole')
102 if have_setuptools:
106 if have_setuptools:
103 cmdbase += '-script.pyw'
107 cmdbase += '-script.pyw'
104 cmd = '"%s"' % cmdbase
108 cmd = '"%s"' % cmdbase
105 mkshortcut(pythonw, 'IPython Qt Console', link, cmd, workdir)
109 mkshortcut(pythonw, 'IPython Qt Console', link, cmd, workdir)
106 # Create documentation shortcuts ...
110 # Create documentation shortcuts ...
107 t = prefix + r'\share\doc\ipython\manual\ipython.pdf'
111 t = prefix + r'\share\doc\ipython\manual\ipython.pdf'
108 f = ip_start_menu + r'\Manual in PDF.lnk'
112 f = ip_start_menu + r'\Manual in PDF.lnk'
109 mkshortcut(t,r'IPython Manual - PDF-Format',f)
113 mkshortcut(t,r'IPython Manual - PDF-Format',f)
110
114
111 t = prefix + r'\share\doc\ipython\manual\html\index.html'
115 t = prefix + r'\share\doc\ipython\manual\html\index.html'
112 f = ip_start_menu + r'\Manual in HTML.lnk'
116 f = ip_start_menu + r'\Manual in HTML.lnk'
113 mkshortcut(t,'IPython Manual - HTML-Format',f)
117 mkshortcut(t,'IPython Manual - HTML-Format',f)
114
118
115
119
116 def remove():
120 def remove():
117 """Routine to be run by the win32 installer with the -remove switch."""
121 """Routine to be run by the win32 installer with the -remove switch."""
118 pass
122 pass
119
123
120 # main()
124 # main()
121 if len(sys.argv) > 1:
125 if len(sys.argv) > 1:
122 if sys.argv[1] == '-install':
126 if sys.argv[1] == '-install':
123 install()
127 install()
124 elif sys.argv[1] == '-remove':
128 elif sys.argv[1] == '-remove':
125 remove()
129 remove()
126 else:
130 else:
127 print "Script was called with option %s" % sys.argv[1]
131 print "Script was called with option %s" % sys.argv[1]
General Comments 0
You need to be logged in to leave comments. Login now