##// END OF EJS Templates
Remove stale HTML shortcuts in win32 installer.
Fernando Perez -
Show More
@@ -1,142 +1,138
1 #!python
1 #!python
2 """Windows-specific part of the installation"""
2 """Windows-specific part of the installation"""
3
3
4 from __future__ import print_function
4 from __future__ import print_function
5
5
6 import os, sys, shutil
6 import os, sys, shutil
7 pjoin = os.path.join
7 pjoin = os.path.join
8
8
9 # import setuptools if we can
9 # import setuptools if we can
10 try:
10 try:
11 import setuptools
11 import setuptools
12 except ImportError:
12 except ImportError:
13 pass
13 pass
14
14
15
15
16 def mkshortcut(target,description,link_file,*args,**kw):
16 def mkshortcut(target,description,link_file,*args,**kw):
17 """make a shortcut if it doesn't exist, and register its creation"""
17 """make a shortcut if it doesn't exist, and register its creation"""
18
18
19 create_shortcut(target, description, link_file,*args,**kw)
19 create_shortcut(target, description, link_file,*args,**kw)
20 file_created(link_file)
20 file_created(link_file)
21
21
22 def suffix(s):
22 def suffix(s):
23 """add '3' suffix to programs for Python 3"""
23 """add '3' suffix to programs for Python 3"""
24 if sys.version_info[0] == 3:
24 if sys.version_info[0] == 3:
25 s = s+'3'
25 s = s+'3'
26 return s
26 return s
27
27
28 def install():
28 def install():
29 """Routine to be run by the win32 installer with the -install switch."""
29 """Routine to be run by the win32 installer with the -install switch."""
30
30
31 # Get some system constants
31 # Get some system constants
32 prefix = sys.prefix
32 prefix = sys.prefix
33 python = pjoin(prefix, 'python.exe')
33 python = pjoin(prefix, 'python.exe')
34 pythonw = pjoin(prefix, 'pythonw.exe')
34 pythonw = pjoin(prefix, 'pythonw.exe')
35 have_setuptools = 'setuptools' in sys.modules
35 have_setuptools = 'setuptools' in sys.modules
36
36
37 if not have_setuptools:
37 if not have_setuptools:
38 # This currently doesn't work without setuptools,
38 # This currently doesn't work without setuptools,
39 # so don't bother making broken links
39 # so don't bother making broken links
40 return
40 return
41
41
42 # Lookup path to common startmenu ...
42 # Lookup path to common startmenu ...
43 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'),
43 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'),
44 'IPython (Py%i.%i %i bit)' % (sys.version_info[0],
44 'IPython (Py%i.%i %i bit)' % (sys.version_info[0],
45 sys.version_info[1],
45 sys.version_info[1],
46 8*tuple.__itemsize__))
46 8*tuple.__itemsize__))
47 # Create IPython entry ...
47 # Create IPython entry ...
48 if not os.path.isdir(ip_start_menu):
48 if not os.path.isdir(ip_start_menu):
49 os.mkdir(ip_start_menu)
49 os.mkdir(ip_start_menu)
50 directory_created(ip_start_menu)
50 directory_created(ip_start_menu)
51
51
52 # Create .py and .bat files to make things available from
52 # Create .py and .bat files to make things available from
53 # the Windows command line. Thanks to the Twisted project
53 # the Windows command line. Thanks to the Twisted project
54 # for this logic!
54 # for this logic!
55 programs = [
55 programs = [
56 'ipython',
56 'ipython',
57 'iptest',
57 'iptest',
58 'ipcontroller',
58 'ipcontroller',
59 'ipengine',
59 'ipengine',
60 'ipcluster',
60 'ipcluster',
61 'irunner'
61 'irunner'
62 ]
62 ]
63 programs = [ suffix(p) for p in programs ]
63 programs = [ suffix(p) for p in programs ]
64 scripts = pjoin(prefix,'scripts')
64 scripts = pjoin(prefix,'scripts')
65 if not have_setuptools:
65 if not have_setuptools:
66 # only create .bat files if we don't have setuptools
66 # only create .bat files if we don't have setuptools
67 for program in programs:
67 for program in programs:
68 raw = pjoin(scripts, program)
68 raw = pjoin(scripts, program)
69 bat = raw + '.bat'
69 bat = raw + '.bat'
70 py = raw + '.py'
70 py = raw + '.py'
71 # Create .py versions of the scripts
71 # Create .py versions of the scripts
72 shutil.copy(raw, py)
72 shutil.copy(raw, py)
73 # Create .bat files for each of the scripts
73 # Create .bat files for each of the scripts
74 bat_file = file(bat,'w')
74 bat_file = file(bat,'w')
75 bat_file.write("@%s %s %%*" % (python, py))
75 bat_file.write("@%s %s %%*" % (python, py))
76 bat_file.close()
76 bat_file.close()
77
77
78 # Now move onto setting the Start Menu up
78 # Now move onto setting the Start Menu up
79 ipybase = suffix(pjoin(scripts, 'ipython'))
79 ipybase = suffix(pjoin(scripts, 'ipython'))
80 if have_setuptools:
80 if have_setuptools:
81 # let setuptools take care of the scripts:
81 # let setuptools take care of the scripts:
82 ipybase = ipybase + '-script.py'
82 ipybase = ipybase + '-script.py'
83 workdir = "%HOMEDRIVE%%HOMEPATH%"
83 workdir = "%HOMEDRIVE%%HOMEPATH%"
84
84
85 link = pjoin(ip_start_menu, 'IPython.lnk')
85 link = pjoin(ip_start_menu, 'IPython.lnk')
86 cmd = '"%s"' % ipybase
86 cmd = '"%s"' % ipybase
87 mkshortcut(python, 'IPython', link, cmd, workdir)
87 mkshortcut(python, 'IPython', link, cmd, workdir)
88
88
89 # Disable pysh Start item until the profile restores functionality
89 # Disable pysh Start item until the profile restores functionality
90 # Most of this code is in IPython/deathrow, and needs to be updated
90 # Most of this code is in IPython/deathrow, and needs to be updated
91 # to 0.11 APIs
91 # to 0.11 APIs
92
92
93 # link = pjoin(ip_start_menu, 'pysh.lnk')
93 # link = pjoin(ip_start_menu, 'pysh.lnk')
94 # cmd = '"%s" profile=pysh --init' % ipybase
94 # cmd = '"%s" profile=pysh --init' % ipybase
95 # mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir)
95 # mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir)
96
96
97 link = pjoin(ip_start_menu, 'pylab.lnk')
97 link = pjoin(ip_start_menu, 'pylab.lnk')
98 cmd = '"%s" --pylab' % ipybase
98 cmd = '"%s" --pylab' % ipybase
99 mkshortcut(python, 'IPython (pylab mode)', link, cmd, workdir)
99 mkshortcut(python, 'IPython (pylab mode)', link, cmd, workdir)
100
100
101 link = pjoin(ip_start_menu, 'ipcontroller.lnk')
101 link = pjoin(ip_start_menu, 'ipcontroller.lnk')
102 cmdbase = suffix(pjoin(scripts, 'ipcontroller'))
102 cmdbase = suffix(pjoin(scripts, 'ipcontroller'))
103 if have_setuptools:
103 if have_setuptools:
104 cmdbase += '-script.py'
104 cmdbase += '-script.py'
105 cmd = '"%s"' % cmdbase
105 cmd = '"%s"' % cmdbase
106 mkshortcut(python, 'IPython controller', link, cmd, workdir)
106 mkshortcut(python, 'IPython controller', link, cmd, workdir)
107
107
108 link = pjoin(ip_start_menu, 'ipengine.lnk')
108 link = pjoin(ip_start_menu, 'ipengine.lnk')
109 cmdbase = suffix(pjoin(scripts, 'ipengine'))
109 cmdbase = suffix(pjoin(scripts, 'ipengine'))
110 if have_setuptools:
110 if have_setuptools:
111 cmdbase += '-script.py'
111 cmdbase += '-script.py'
112 cmd = '"%s"' % cmdbase
112 cmd = '"%s"' % cmdbase
113 mkshortcut(python, 'IPython engine', link, cmd, workdir)
113 mkshortcut(python, 'IPython engine', link, cmd, workdir)
114
114
115 link = pjoin(ip_start_menu, 'ipythonqt.lnk')
115 link = pjoin(ip_start_menu, 'ipythonqt.lnk')
116 cmdbase = suffix(pjoin(scripts, 'ipython')) + '-qtconsole'
116 cmdbase = suffix(pjoin(scripts, 'ipython')) + '-qtconsole'
117 if have_setuptools:
117 if have_setuptools:
118 cmdbase += '-script.pyw'
118 cmdbase += '-script.pyw'
119 cmd = '"%s"' % cmdbase
119 cmd = '"%s"' % cmdbase
120 mkshortcut(pythonw, 'IPython Qt Console', link, cmd, workdir)
120 mkshortcut(pythonw, 'IPython Qt Console', link, cmd, workdir)
121 # Create documentation shortcuts ...
122 t = prefix + r'\share\doc\ipython\manual\index.html'
123 f = ip_start_menu + r'\Manual in HTML.lnk'
124 mkshortcut(t,'IPython Manual - HTML-Format',f)
125
121
126
122
127 def remove():
123 def remove():
128 """Routine to be run by the win32 installer with the -remove switch."""
124 """Routine to be run by the win32 installer with the -remove switch."""
129 pass
125 pass
130
126
131
127
132 # main()
128 # main()
133 if len(sys.argv) > 1:
129 if len(sys.argv) > 1:
134 if sys.argv[1] == '-install':
130 if sys.argv[1] == '-install':
135 try:
131 try:
136 install()
132 install()
137 except OSError:
133 except OSError:
138 print("Failed to create Start Menu items, try running installer as administrator.", file=sys.stderr)
134 print("Failed to create Start Menu items, try running installer as administrator.", file=sys.stderr)
139 elif sys.argv[1] == '-remove':
135 elif sys.argv[1] == '-remove':
140 remove()
136 remove()
141 else:
137 else:
142 print("Script was called with option %s" % sys.argv[1], file=sys.stderr)
138 print("Script was called with option %s" % sys.argv[1], file=sys.stderr)
General Comments 0
You need to be logged in to leave comments. Login now