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