ipython_win_post_install.py
127 lines
| 4.0 KiB
| text/x-python
|
PythonLexer
/ scripts / ipython_win_post_install.py
Ville M. Vainio
|
r1032 | #!python | ||
"""Windows-specific part of the installation""" | ||||
import os, sys, shutil | ||||
Brian Granger
|
r1611 | pjoin = os.path.join | ||
Ville M. Vainio
|
r1032 | |||
Min RK
|
r4094 | # import setuptools if we can | ||
try: | ||||
import setuptools | ||||
except ImportError: | ||||
pass | ||||
Ville M. Vainio
|
r1032 | def mkshortcut(target,description,link_file,*args,**kw): | ||
"""make a shortcut if it doesn't exist, and register its creation""" | ||||
create_shortcut(target, description, link_file,*args,**kw) | ||||
file_created(link_file) | ||||
def install(): | ||||
"""Routine to be run by the win32 installer with the -install switch.""" | ||||
Brian Granger
|
r1611 | |||
Brian Granger
|
r2060 | from IPython.core.release import version | ||
Ville M. Vainio
|
r1032 | |||
Brian Granger
|
r1611 | # Get some system constants | ||
prefix = sys.prefix | ||||
python = pjoin(prefix, 'python.exe') | ||||
Min RK
|
r4094 | pythonw = pjoin(prefix, 'pythonw.exe') | ||
have_setuptools = 'setuptools' in sys.modules | ||||
if not have_setuptools: | ||||
# This currently doesn't work without setuptools, | ||||
# so don't bother making broken links | ||||
return | ||||
Brian Granger
|
r1611 | |||
# Lookup path to common startmenu ... | ||||
ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'), 'IPython') | ||||
Ville M. Vainio
|
r1032 | # Create IPython entry ... | ||
Brian Granger
|
r1611 | if not os.path.isdir(ip_start_menu): | ||
os.mkdir(ip_start_menu) | ||||
directory_created(ip_start_menu) | ||||
# Create .py and .bat files to make things available from | ||||
Brian Granger
|
r1613 | # the Windows command line. Thanks to the Twisted project | ||
# for this logic! | ||||
Brian Granger
|
r1612 | programs = [ | ||
'ipython', | ||||
'iptest', | ||||
'ipcontroller', | ||||
'ipengine', | ||||
'ipcluster', | ||||
'irunner' | ||||
] | ||||
Brian Granger
|
r1611 | scripts = pjoin(prefix,'scripts') | ||
Min RK
|
r4094 | if not have_setuptools: | ||
# only create .bat files if we don't have setuptools | ||||
for program in programs: | ||||
raw = pjoin(scripts, program) | ||||
bat = raw + '.bat' | ||||
py = raw + '.py' | ||||
# Create .py versions of the scripts | ||||
shutil.copy(raw, py) | ||||
# Create .bat files for each of the scripts | ||||
bat_file = file(bat,'w') | ||||
bat_file.write("@%s %s %%*" % (python, py)) | ||||
bat_file.close() | ||||
Brian Granger
|
r1611 | # Now move onto setting the Start Menu up | ||
Brian Granger
|
r1612 | ipybase = pjoin(scripts, 'ipython') | ||
Min RK
|
r4094 | if have_setuptools: | ||
Darren Dale
|
r3228 | # let setuptools take care of the scripts: | ||
ipybase = ipybase + '-script.py' | ||||
Darren Dale
|
r3227 | workdir = "%HOMEDRIVE%%HOMEPATH%" | ||
Ville M. Vainio
|
r1032 | |||
Brian Granger
|
r1612 | link = pjoin(ip_start_menu, 'IPython.lnk') | ||
cmd = '"%s"' % ipybase | ||||
Darren Dale
|
r3227 | mkshortcut(python, 'IPython', link, cmd, workdir) | ||
Brian Granger
|
r1612 | |||
link = pjoin(ip_start_menu, 'pysh.lnk') | ||||
Min RK
|
r4094 | cmd = '"%s" profile=pysh --init' % ipybase | ||
Darren Dale
|
r3227 | mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir) | ||
Brian Granger
|
r1612 | |||
Min RK
|
r4094 | link = pjoin(ip_start_menu, 'pylab.lnk') | ||
cmd = '"%s" profile=pylab --init' % ipybase | ||||
mkshortcut(python, 'IPython (pylab profile)', link, cmd, workdir) | ||||
Fernando Perez
|
r2114 | |||
Brian Granger
|
r1612 | link = pjoin(ip_start_menu, 'ipcontroller.lnk') | ||
Min RK
|
r4094 | cmdbase = pjoin(scripts, 'ipcontroller') | ||
if have_setuptools: | ||||
cmdbase += '-script.py' | ||||
cmd = '"%s"' % cmdbase | ||||
Darren Dale
|
r3227 | mkshortcut(python, 'IPython controller', link, cmd, workdir) | ||
Brian Granger
|
r1611 | |||
Brian Granger
|
r1612 | link = pjoin(ip_start_menu, 'ipengine.lnk') | ||
Min RK
|
r4094 | cmdbase = pjoin(scripts, 'ipengine') | ||
if have_setuptools: | ||||
cmdbase += '-script.py' | ||||
cmd = '"%s"' % cmdbase | ||||
Darren Dale
|
r3227 | mkshortcut(python, 'IPython engine', link, cmd, workdir) | ||
Min RK
|
r4094 | |||
link = pjoin(ip_start_menu, 'ipythonqt.lnk') | ||||
cmdbase = pjoin(scripts, 'ipython-qtconsole') | ||||
if have_setuptools: | ||||
cmdbase += '-script.pyw' | ||||
cmd = '"%s"' % cmdbase | ||||
mkshortcut(pythonw, 'IPython Qt Console', link, cmd, workdir) | ||||
Fernando Perez
|
r1589 | # Create documentation shortcuts ... | ||
vivainio2
|
r1194 | t = prefix + r'\share\doc\ipython\manual\ipython.pdf' | ||
Brian Granger
|
r1611 | f = ip_start_menu + r'\Manual in PDF.lnk' | ||
Ville M. Vainio
|
r1032 | mkshortcut(t,r'IPython Manual - PDF-Format',f) | ||
Brian Granger
|
r1611 | |||
Fernando Perez
|
r1589 | t = prefix + r'\share\doc\ipython\manual\html\index.html' | ||
Brian Granger
|
r1611 | f = ip_start_menu + r'\Manual in HTML.lnk' | ||
Ville M. Vainio
|
r1032 | mkshortcut(t,'IPython Manual - HTML-Format',f) | ||
Brian Granger
|
r1611 | |||
Ville M. Vainio
|
r1032 | |||
def remove(): | ||||
"""Routine to be run by the win32 installer with the -remove switch.""" | ||||
pass | ||||
# main() | ||||
if len(sys.argv) > 1: | ||||
if sys.argv[1] == '-install': | ||||
install() | ||||
elif sys.argv[1] == '-remove': | ||||
remove() | ||||
else: | ||||
print "Script was called with option %s" % sys.argv[1] | ||||