Windows Installation

Fernando Pérez fperez528 at yahoo.com
Fri Mar 15 10:06:53 EST 2002


Jonathan Gardner wrote:

> I have a free software program (http://sf.net/projects/bttotalcontrol/) and
> I am having great difficulty writing an installation script for windows.
> 
> I don't want to use distutils because I am not writing a module - but an
> entire distribution with images, data files, and executable programs. I
> would like to put icons on the desktop and stuff in the start menu as well.
> 
> I am at a major disadvantage because I don't have access to a windows
> machine, and so I can't test anything directly. However, I do have a few
> people who actively test for the project at home.
> 
> Anyone have any suggestions on where I should go? Anyone can help me out
> here?
> 
> Jonathan

This was my rough solution. It may be a reasonable starting point for you.

If you want to test it (it won't work on its own), grab the IPython package 
from http://www-hep.colorado.edu/~fperez/ipython/ and install it on a Windows 
box (have one of your testers do it) to see how it works.

Let me warn you though that doing the development in linux and the debugging 
in windows will be tricky. IPython was all written in linux, but for writing 
this setup script I had to install PythonWin so I could actually do the 
testing.

Good luck,

f.


"""Use this script to install IPython in Windows platforms. 
 
Wrapper around setup.py which creates appropriate entries in 
the Start Menu. 
 
This is quick and dirty, but seems to work reasonably well.""" 
 
#***************************************************************************** 
#       Copyright (C) 2001 Fernando Pérez. 
# 
#  Distributed under the terms of the GNU Lesser General Public License 
(LGPL) 
# 
#  The full text of the LGPL is available at: 
# 
#                  http://www.gnu.org/copyleft/lesser.html 
#***************************************************************************** 
 
__author__ = 'Fernando Pérez. <fperez at pizero.colorado.edu>' 
__version__= '0.1.0' 
__license__ = 'LGPL' 
 
import sys,os,shutil 
from win32com.shell import shell 
import pythoncom 
import _winreg as wreg 
 
#-------------------------------------------------------------------------- 
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. 
    """ 
 
    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) 
 
#-------------------------------------------------------------------------- 
# 'Main' code 
 
# First run the distutils generic installer 
setup = os.path.join(os.getcwd(),'setup.py') 
sys.argv = [setup,'install'] 
try: 
    execfile(setup) 
except: 
    einfo = map(str,sys.exc_info()[:2]) 
    print '\n\nThere were problems with the installer:',' '.join(einfo) 
    raw_input('Press Enter to exit') 
    sys.exit() 
 
# Now make some windows-only niceties. 
 
# Find where the Start Menu and My Documents are on the filesystem 
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, 
                   "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell 
Folders") 
programs_dir = wreg.QueryValueEx(key,'Programs')[0] 
my_documents_dir = wreg.QueryValueEx(key,'Personal')[0] 
key.Close() 
 
# File and directory names 
ip_dir = 'C:\\Program Files\\IPython' 
ip_prog_dir = programs_dir + '\\IPython' 
doc_dir = ip_dir+'\\doc' 
ip_filename = ip_dir+'\\IPython_shell.py' 
pycon_icon = doc_dir+'\\pycon.ico' 
 
if not os.path.isdir(ip_dir): 
    os.mkdir(ip_dir) 
 
# Copy startup script and documentation 
shutil.copy(sys.prefix+'\\Scripts\\ipython',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 '\n\n\nMaking entries for IPython in Start Menu...', 
 
# Create shortcuts in Programs\IPython: 
if not os.path.isdir(ip_prog_dir): 
    os.mkdir(ip_prog_dir) 
os.chdir(ip_prog_dir) 
 
manual_dir = doc_dir + '\\manual' 
man_htm = manual_dir + '\\manual.html' 
man_pdf = manual_dir + '\\manual.pdf' 
 
make_shortcut('IPython.lnk',sys.executable, '"%s"' % ip_filename, 
              my_documents_dir, 
              'IPython - Enhanced python command line interpreter', 
              (pycon_icon,0)) 
make_shortcut('Manual in HTML format.lnk',man_htm,'','', 
              'IPython Manual - HTML format') 
make_shortcut('Manual in PDF format.lnk',man_pdf,'','', 
              'IPython Manual - PDF format') 
               
print """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 
 
Finished with IPython installation. Press Enter to exit this installer.""", 
raw_input() 




More information about the Python-list mailing list