##// END OF EJS Templates
Use base documentation URL
Christoph Gohlke -
Show More
@@ -1,154 +1,148 b''
1 1 #!python
2 2 """Distutils post installation script for Windows.
3 3
4 4 http://docs.python.org/2/distutils/builtdist.html#the-postinstallation-script
5 5
6 6 """
7 7
8 8 from __future__ import print_function
9 9
10 10 import os
11 11 import sys
12 12 import shutil
13 import platform
14 13
15 14 try:
16 15 import setuptools
17 16 have_setuptools = True
18 17 except ImportError:
19 18 have_setuptools = False
20 19
21 20
22 21 pjoin = os.path.join
23 22
24 23 # suffix for start menu folder names
25 24 pyver = "(Py%i.%i %i bit)" % (sys.version_info[0], sys.version_info[1],
26 25 (32, 64)[sys.maxsize > 2**32])
27 26
28 27
29 28 def mkshortcut(target, description, linkdir, arguments="", iconpath='',
30 29 workdir="%HOMEDRIVE%%HOMEPATH%", iconindex=0):
31 30 """Make a shortcut if it doesn't exist and register its creation."""
32 31 filename = pjoin(linkdir, description + '.lnk')
33 32 description = "%s %s" % (description, pyver)
34 33 create_shortcut(target, description, filename, arguments, workdir,
35 34 iconpath, iconindex)
36 35 file_created(filename)
37 36
38 37
39 38 def arguments(scriptsdir, script, scriptargs=''):
40 39 """Return command line arguments to be passed to the python executable."""
41 40 cmdbase = suffix(pjoin(scriptsdir, script))
42 41 if have_setuptools:
43 42 cmdbase += '-script.py'
44 43 return '"%s" %s' % (cmdbase, scriptargs)
45 44
46 45
47 46 def suffix(s):
48 47 """Add '3' suffix to programs for Python 3."""
49 48 if sys.version_info[0] == 3:
50 49 s = s + '3'
51 50 return s
52 51
53 52
54 53 def install():
55 54 """Routine to be run by the win32 installer with the -install switch."""
56 55 # Get some system constants
57 56 python = pjoin(sys.prefix, 'python.exe')
58 57 pythonw = pjoin(sys.prefix, 'pythonw.exe')
59 58
60 59 if not have_setuptools:
61 60 # This currently doesn't work without setuptools,
62 61 # so don't bother making broken links
63 62 print("Distribute (setuptools) is required to"
64 63 " create Start Menu items.", file=sys.stderr)
65 64 print("Re-run this installer after installing"
66 65 " distribute to get Start Menu items.", file=sys.stderr)
67 66 return
68 67
69 68 # Lookup path to common startmenu ...
70 69 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'),
71 70 'IPython %s' % pyver)
72 71
73 72 # Create IPython entry ...
74 73 if not os.path.isdir(ip_start_menu):
75 74 os.mkdir(ip_start_menu)
76 75 directory_created(ip_start_menu)
77 76
78 77 # Create .py and .bat files to make things available from
79 78 # the Windows command line. Thanks to the Twisted project
80 79 # for this logic!
81 80 programs = [
82 81 'ipython',
83 82 'iptest',
84 83 'ipcontroller',
85 84 'ipengine',
86 85 'ipcluster',
87 86 'irunner',
88 87 ]
89 88 programs = [suffix(p) for p in programs]
90 89 scripts = pjoin(sys.prefix, 'scripts')
91 90 if not have_setuptools:
92 91 # only create .bat files if we don't have setuptools
93 92 for program in programs:
94 93 raw = pjoin(scripts, program)
95 94 bat = raw + '.bat'
96 95 py = raw + '.py'
97 96 # Create .py versions of the scripts
98 97 shutil.copy(raw, py)
99 98 # Create .bat files for each of the scripts
100 99 bat_file = file(bat, 'w')
101 100 bat_file.write("@%s %s %%*" % (python, py))
102 101 bat_file.close()
103 102
104 103 # Create Start Menu shortcuts
105 104 iconpath = pjoin(scripts, 'ipython.ico')
106 105 mkshortcut(python, 'IPython', ip_start_menu,
107 106 arguments(scripts, 'ipython'), iconpath)
108 107 mkshortcut(python, 'IPython (pylab mode)', ip_start_menu,
109 108 arguments(scripts, 'ipython', '--pylab'), iconpath)
110 109 mkshortcut(python, 'IPython Controller', ip_start_menu,
111 110 arguments(scripts, 'ipcontroller'), iconpath)
112 111 mkshortcut(python, 'IPython Engine', ip_start_menu,
113 112 arguments(scripts, 'ipengine'), iconpath)
114 113 mkshortcut(pythonw, 'IPython Qt Console', ip_start_menu,
115 114 arguments(scripts, 'ipython', 'qtconsole'), iconpath)
116 115
117 116 iconpath = pjoin(scripts, 'ipython_nb.ico')
118 117 mkshortcut(python, 'IPython Notebook', ip_start_menu,
119 118 arguments(scripts, 'ipython', 'notebook'), iconpath)
120 119
121 try:
122 import IPython
123 mkshortcut(pythonw, 'IPython Documentation', ip_start_menu,
124 '-m webbrowser -t "http://ipython.org/ipython-doc/'
125 'rel-%s/index.html"' % IPython.__version__,
126 iconpath='url.dll')
127 except Exception:
128 pass
120 mkshortcut(pythonw, 'IPython Documentation', ip_start_menu,
121 '-m webbrowser -t "http://ipython.org/documentation.html',
122 iconpath='url.dll')
129 123
130 124 # Disable pysh Start item until the profile restores functionality
131 125 # Most of this code is in IPython/deathrow, and needs to be updated
132 126 # to 0.11 APIs
133 127 #mkshortcut(python, 'IPython%s (command prompt mode)', ip_start_menu,
134 128 # arguments(scripts, 'ipython', 'profile=pysh --init'))
135 129
136 130
137 131 def remove():
138 132 """Routine to be run by the win32 installer with the -remove switch."""
139 133 pass
140 134
141 135
142 136 # main()
143 137 if len(sys.argv) > 1:
144 138 if sys.argv[1] == '-install':
145 139 try:
146 140 install()
147 141 except OSError:
148 142 print("Failed to create Start Menu items, try running the"
149 143 " installer as administrator.", file=sys.stderr)
150 144 elif sys.argv[1] == '-remove':
151 145 remove()
152 146 else:
153 147 print("Script was called with option %s" % sys.argv[1],
154 148 file=sys.stderr)
General Comments 0
You need to be logged in to leave comments. Login now