#!python """Windows-specific part of the installation""" import os, sys # Try to write to a logfile so we can fish shome output later from the # autoinstaller. logname = 'C:\\ipython_install_log.txt' #logname = 'D:\\Fer\\iplog.txt' LOG = file(logname,'w') # dbg try: import shutil,pythoncom from win32com.shell import shell import _winreg as wreg except ImportError: print """ You seem to be missing the PythonWin extensions necessary for automatic installation. You can get them (free) from http://starship.python.net/crew/mhammond/ Please see the manual for details if you want to finish the installation by hand, or get PythonWin and repeat the procedure.""" try: # When this script is run from inside the bdist_wininst installer, # file_created() and directory_created() are additional builtin # functions which write lines to Python23\IPython-wininst.log. This is # a list of actions for the uninstaller, the format is inspired by what # the Wise installer also creates. file_created except NameError: def file_created(file): pass def directory_created(directory): pass def make_shortcut(fname,target,args='',start_in='',comment='',icon=None): """Make a Windows shortcut (.lnk) file. make_shortcut(fname,target,args='',start_in='',comment='',icon=None) Arguments: fname - name of the final shortcut file (include the .lnk) target - what the shortcut will point to args - additional arguments to pass to the target program start_in - directory where the target command will be called comment - for the popup tooltips icon - optional icon file. This must be a tuple of the type (icon_file,index), where index is the index of the icon you want in the file. For single .ico files, index=0, but for icon libraries contained in a single file it can be >0. """ print >>LOG,'make_shortcut(%(fname)s,%(target)s,%(args)s,%(start_in)s,'\ '%(comment)s,%(icon)s)' % locals() shortcut = pythoncom.CoCreateInstance( shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) shortcut.SetPath(target) shortcut.SetArguments(args) shortcut.SetWorkingDirectory(start_in) shortcut.SetDescription(comment) if icon: shortcut.SetIconLocation(*icon) shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(fname,0) def run(wait=0): print >>LOG,'Starting windows install...' # dbg print >>LOG,'sys.argv:',sys.argv print >>LOG,'Running from: <%s>' % os.getcwd() # Find where the Start Menu and My Documents are on the filesystem key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion' r'\Explorer\Shell Folders') startmenu_progs_dir = wreg.QueryValueEx(key,'Programs')[0] my_documents_dir = wreg.QueryValueEx(key,'Personal')[0] key.Close() # Find where the 'program files' directory is key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion') program_files_dir = wreg.QueryValueEx(key,'ProgramFilesDir')[0] key.Close() # File and directory names sys_prefix = sys.prefix ip_dir = program_files_dir + '\\IPython' startmenu_ip_dir = startmenu_progs_dir + '\\IPython' # doc_dir = ip_dir+'\\doc' doc_dir = sys_prefix+'\\share\\doc' ip_filename = sys_prefix+'\\Scripts\\ipython.py' #ip_filename = ip_dir+'\\IPython_shell.py' pycon_icon = doc_dir+'\\pycon.ico' # dbg print >> LOG, """Paths: sys_prefix : %(sys_prefix)s ip_dir : %(ip_dir)s startmenu_ip_dir : %(startmenu_ip_dir)s doc_dir : %(doc_dir)s ip_filename : %(ip_filename)s pycon_icon : %(pycon_icon)s """ % locals() ## if not os.path.isdir(ip_dir): ## os.mkdir(ip_dir) # Copy startup script and documentation shutil.copy(sys_prefix+'\\Scripts\\ipython',ip_filename) file_created(ip_filename) ## if os.path.isdir(doc_dir): ## shutil.rmtree(doc_dir) ## shutil.copytree('doc',doc_dir) # make shortcuts for IPython, html and pdf docs. print 'Making entries for IPython in Start Menu...', print >>LOG,'Making entries for IPython in Start Menu...' # Create shortcuts in Programs\IPython: if not os.path.isdir(startmenu_ip_dir): os.mkdir(startmenu_ip_dir) directory_created(startmenu_ip_dir) os.chdir(startmenu_ip_dir) man_pdf = doc_dir + '\\manual.pdf' man_htm = doc_dir + '\\manual\\manual.html' print >>LOG,'IPython.lnk' make_shortcut('IPython.lnk',sys.executable, '"%s"' % ip_filename, my_documents_dir, 'IPython - Enhanced python command line interpreter', (pycon_icon,0)) print >>LOG,'HTML manual' make_shortcut('Manual in HTML format.lnk',man_htm,'','', 'IPython Manual - HTML format') print >>LOG,'PDF manual' make_shortcut('Manual in PDF format.lnk',man_pdf,'','', 'IPython Manual - PDF format') msg = """Done. I created the directory C:\\Program Files\\IPython. There you will find the IPython startup script and manuals. An IPython menu was also created in your Start Menu, with entries for IPython itself and the manual in HTML and PDF formats. For reading PDF documents you need the freely available Adobe Acrobat Reader. If you don't have it, you can download it from: http://www.adobe.com/products/acrobat/readstep2.html """ print >>LOG,msg if wait: try: print ('Finished with IPython installation. ' 'Press Enter to exit this installer.'), raw_input() except: # in case it's being run by a scripted installer pass if __name__ == '__main__': run() print >>LOG,'FINISHED!' LOG.close()