Fix the windows installer .exe: delay replacement of bdist_wininst placeholders until installation.

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2142 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2005-01-12 14:37:15 +00:00
parent 135cdb42bb
commit 59a0f156f8
2 changed files with 89 additions and 49 deletions

View file

@ -9,55 +9,71 @@
# [bdist_wininst]
# install-script=install-linkchecker.py
# available functions:
# create_shortcut(target, description, filename[, arguments[,
# workdir[, iconpath[, iconindex]]]])
# - create shortcut
#
# file_created(path)
# - register 'path' so that the uninstaller removes it
#
# directory_created(path)
# - register 'path' so that the uninstaller removes it
#
# get_special_folder_location(csidl_string)
# - get windows specific paths
import sys
import os
from distutils.sysconfig import get_python_lib
if not sys.platform.startswith('win'):
# not for us
sys.exit()
try:
prg = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
except OSError:
# path retrieving functions
def get_prg_path ():
try:
prg = get_special_folder_path("CSIDL_PROGRAMS")
except OSError, reason:
# give up - cannot install shortcuts
print "cannot install shortcuts: %s" % reason
sys.exit()
return get_special_folder_path("CSIDL_COMMON_PROGRAMS")
except OSError:
try:
return get_special_folder_path("CSIDL_PROGRAMS")
except OSError, reason:
# give up - cannot install shortcuts
print "cannot install shortcuts: %s" % reason
sys.exit()
lib_dir = get_python_lib(plat_specific=1)
dest_dir = os.path.join(prg, "LinkChecker")
python_exe = os.path.join(sys.prefix, "python.exe")
import linkcheck
def get_dest_dir ():
return os.path.join(get_prg_path(), "LinkChecker")
def get_python_exe ():
return os.path.join(sys.prefix, "python.exe")
# install routines
def do_install ():
"""create_shortcut(target, description, filename[, arguments[, \
workdir[, iconpath[, iconindex]]]])
fix_configdata()
create_shortcuts()
file_created(path)
- register 'path' so that the uninstaller removes it
directory_created(path)
- register 'path' so that the uninstaller removes it
get_special_folder_location(csidl_string)
"""
def create_shortcuts ():
"""Create program shortcuts"""
dest_dir = get_dest_dir()
try:
os.mkdir(dest_dir)
directory_created(dest_dir)
except OSError:
pass
path = os.path.join(dest_dir, "Check URL.lnk")
script_dir = linkcheck.configdata.install_scripts
arguments = os.path.join(script_dir, "linkchecker")
arguments = os.path.join(sys.prefix, "Scripts", "linkchecker")
arguments += " --interactive"
create_shortcut(python_exe, "Check URL", path, arguments)
create_shortcut(get_python_exe(), "Check URL", path, arguments)
file_created(path)
data_dir = linkcheck.configdata.install_data
target = os.path.join(data_dir,
target = os.path.join(sys.prefix,
"share", "linkchecker", "doc", "documentation.html")
path = os.path.join(dest_dir, "Documentation.lnk")
create_shortcut(target, "Documentation", path)
@ -71,6 +87,49 @@ def do_install ():
print "See the shortcuts installed in the LinkChecker Programs Group"
def fix_configdata ():
"""fix install and config paths in the config file"""
name = "_linkchecker_configdata.py"
conffile = os.path.join(sys.prefix, "Lib", "site-packages", name)
lines = []
for line in file(conffile):
if line.startswith("install_") or line.startswith("config_"):
lines.append(fix_install_path(line))
else:
lines.append(line)
f = file(conffile, "w")
f.write("".join(lines))
f.close()
# windows install scheme for python >= 2.3
# snatched from PC/bdist_wininst/install.c
# this is used to fix install_* paths when cross compiling for windows
win_path_scheme = {
"purelib": ("PURELIB", "Lib\\site-packages\\"),
"platlib": ("PLATLIB", "Lib\\site-packages\\"),
# note: same as platlib because of C extensions, else it would be purelib
"lib": ("PLATLIB", "Lib\\site-packages\\"),
# 'Include/dist_name' part already in archive
"headers": ("HEADERS", "."),
"scripts": ("SCRIPTS", "Scripts\\"),
"data": ("DATA", "."),
}
def fix_install_path (line):
"""Replace placeholders written by bdist_wininst with those specified
in win_path_scheme."""
key, eq, val = line.split()
# unescape string (do not use eval())
val = val[1:-1].replace("\\\\", "\\")
for d in win_path_scheme.keys():
# look for placeholders to replace
oldpath, newpath = win_path_scheme[d]
oldpath = "%s%s" % (os.sep, oldpath)
if oldpath in val:
val = val.replace(oldpath, newpath)
val = os.path.join(sys.prefix, val)
return "%s = %r%s" % (key, val, os.linesep)
if __name__ == '__main__':
if "-install" == sys.argv[1]:
do_install()

View file

@ -65,20 +65,6 @@ def cnormpath (path):
return path
# windows install scheme for python >= 2.3
# snatched from PC/bdist_wininst/install.c
# this is used to fix install_* paths when cross compiling for windows
win_path_scheme = {
"purelib": ("PURELIB", "Lib\\site-packages\\"),
"platlib": ("PLATLIB", "Lib\\site-packages\\"),
# note: same as platlib because of C extensions, else it would be purelib
"lib": ("PLATLIB", "Lib\\site-packages\\"),
# 'Include/dist_name' part already in archive
"headers": ("HEADERS", ""),
"scripts": ("SCRIPTS", "Scripts\\"),
"data": ("DATA", ""),
}
class MyInstall (install, object):
def run (self):
@ -98,12 +84,6 @@ class MyInstall (install, object):
val = getattr(self, attr)[cutoff:]
else:
val = getattr(self, attr)
if win_compiling and d in win_path_scheme:
# look for placeholders to replace
oldpath, newpath = win_path_scheme[d]
oldpath = "%s%s" % (os.sep, oldpath)
if oldpath in val:
val = val.replace(oldpath, newpath)
if attr == 'install_data':
cdir = os.path.join(val, "share", "linkchecker")
data.append('config_dir = %r' % cnormpath(cdir))
@ -217,8 +197,9 @@ if os.name == 'nt':
# windows does not have unistd.h
define_macros.append(('YY_NO_UNISTD_H', None))
else:
# for gcc 3.x we could add -std=gnu99 to get rid of warnings, but
# that breaks other compilers
# For gcc 3.x we could add -std=gnu99 to get rid of warnings, but
# that breaks other compilers. And detecting GNU gcc 3.x is
# hard within this framework.
extra_compile_args.append("-pedantic")
if win_compiling:
# we are cross compiling with mingw