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