1821.1.2
by Alexander Belchenko
resurrected python's distutils based installer for win32 |
1 |
# (c) Canonical Ltd, 2006
|
2 |
# written by Alexander Belchenko for bzr project
|
|
3 |
#
|
|
4 |
# This script will be executed after installation of bzrlib package
|
|
5 |
# and before installer exits.
|
|
6 |
# All printed data will appear on the last screen of installation
|
|
7 |
# procedure.
|
|
8 |
# The main goal of this script is to create special batch file
|
|
9 |
# launcher for bzr. Typical content of this batch file is:
|
|
10 |
# @python bzr %*
|
|
11 |
#
|
|
12 |
# This file works only on Windows 2000/XP. For win98 there is
|
|
13 |
# should be "%1 %2 %3 %4 %5 %6 %7 %8 %9" instead of "%*".
|
|
14 |
# Or even more complex thing.
|
|
15 |
#
|
|
16 |
# [bialix]: bzr de-facto does not support win98.
|
|
17 |
# Although it seems to work on. Sometimes.
|
|
1861.2.11
by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98 |
18 |
# 2006/07/30 added minimal support of win98.
|
2245.4.5
by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support |
19 |
# 2007/01/30 added *real* support of win98.
|
1821.1.2
by Alexander Belchenko
resurrected python's distutils based installer for win32 |
20 |
|
21 |
import os |
|
22 |
import sys |
|
1860.1.3
by Alexander Belchenko
python-installer: |
23 |
import _winreg |
24 |
||
2245.4.5
by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support |
25 |
from bzrlib import win32utils |
26 |
||
1821.1.2
by Alexander Belchenko
resurrected python's distutils based installer for win32 |
27 |
|
1861.2.11
by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98 |
28 |
def _quoted_path(path): |
29 |
if ' ' in path: |
|
30 |
return '"' + path + '"' |
|
31 |
else: |
|
32 |
return path |
|
33 |
||
34 |
def _win_batch_args(): |
|
2245.4.5
by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support |
35 |
if win32utils.winver == 'Windows NT': |
1861.2.11
by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98 |
36 |
return '%*' |
37 |
else: |
|
38 |
return '%1 %2 %3 %4 %5 %6 %7 %8 %9' |
|
39 |
||
40 |
||
41 |
if "-install" in sys.argv[1:]: |
|
1821.1.2
by Alexander Belchenko
resurrected python's distutils based installer for win32 |
42 |
# try to detect version number automatically
|
43 |
try: |
|
44 |
import bzrlib |
|
45 |
except ImportError: |
|
46 |
ver = '' |
|
47 |
else: |
|
48 |
ver = bzrlib.__version__ |
|
49 |
||
50 |
##
|
|
51 |
# XXX change message for something more appropriate
|
|
1861.2.6
by Alexander Belchenko
branding: change Bazaar-NG to Bazaar |
52 |
print """Bazaar %s |
1821.1.2
by Alexander Belchenko
resurrected python's distutils based installer for win32 |
53 |
|
54 |
Congratulation! Bzr successfully installed.
|
|
55 |
||
56 |
""" % ver |
|
57 |
||
58 |
batch_path = "bzr.bat" |
|
1861.2.22
by Alexander Belchenko
minor polishing after review |
59 |
prefix = sys.exec_prefix |
1821.1.2
by Alexander Belchenko
resurrected python's distutils based installer for win32 |
60 |
try: |
61 |
##
|
|
62 |
# try to create
|
|
63 |
scripts_dir = os.path.join(prefix, "Scripts") |
|
1861.2.11
by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98 |
64 |
script_path = _quoted_path(os.path.join(scripts_dir, "bzr")) |
65 |
python_path = _quoted_path(os.path.join(prefix, "python.exe")) |
|
66 |
args = _win_batch_args() |
|
67 |
batch_str = "@%s %s %s" % (python_path, script_path, args) |
|
2245.4.5
by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support |
68 |
# support of win98
|
69 |
# if there is no HOME for bzr then set it for Bazaar manually
|
|
70 |
base = os.environ.get('BZR_HOME', None) |
|
71 |
if base is None: |
|
72 |
base = win32utils.get_appdata_location() |
|
73 |
if base is None: |
|
74 |
base = os.environ.get('HOME', None) |
|
75 |
if base is None: |
|
76 |
base = os.path.splitdrive(sys.prefix)[0] + '\\' |
|
77 |
batch_str = ("@SET BZR_HOME=" + _quoted_path(base) + "\n" + |
|
1861.2.11
by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98 |
78 |
batch_str) |
79 |
||
2184.1.1
by Alexander Belchenko
Bugfix #71681: python-based installer postinstall script: |
80 |
batch_path = os.path.join(scripts_dir, "bzr.bat") |
1821.1.2
by Alexander Belchenko
resurrected python's distutils based installer for win32 |
81 |
f = file(batch_path, "w") |
82 |
f.write(batch_str) |
|
83 |
f.close() |
|
84 |
file_created(batch_path) # registering manually created files for |
|
85 |
# auto-deinstallation procedure
|
|
86 |
##
|
|
87 |
# inform user where batch launcher is.
|
|
88 |
print "Created:", batch_path |
|
89 |
print "Use this batch file to run bzr" |
|
90 |
except Exception, e: |
|
91 |
print "ERROR: Unable to create %s: %s" % (batch_path, e) |
|
1860.1.3
by Alexander Belchenko
python-installer: |
92 |
|
93 |
## this hunk borrowed from pywin32_postinstall.py
|
|
94 |
# use bdist_wininst builtins to create a shortcut.
|
|
95 |
# CSIDL_COMMON_PROGRAMS only available works on NT/2000/XP, and
|
|
96 |
# will fail there if the user has no admin rights.
|
|
97 |
if get_root_hkey()==_winreg.HKEY_LOCAL_MACHINE: |
|
98 |
try: |
|
99 |
fldr = get_special_folder_path("CSIDL_COMMON_PROGRAMS") |
|
100 |
except OSError: |
|
101 |
# No CSIDL_COMMON_PROGRAMS on this platform
|
|
102 |
fldr = get_special_folder_path("CSIDL_PROGRAMS") |
|
103 |
else: |
|
104 |
# non-admin install - always goes in this user's start menu.
|
|
105 |
fldr = get_special_folder_path("CSIDL_PROGRAMS") |
|
106 |
||
1861.2.6
by Alexander Belchenko
branding: change Bazaar-NG to Bazaar |
107 |
# make Bazaar entry
|
108 |
fldr = os.path.join(fldr, 'Bazaar') |
|
1860.1.3
by Alexander Belchenko
python-installer: |
109 |
if not os.path.isdir(fldr): |
110 |
os.mkdir(fldr) |
|
111 |
directory_created(fldr) |
|
112 |
||
113 |
# link to documentation
|
|
1861.2.6
by Alexander Belchenko
branding: change Bazaar-NG to Bazaar |
114 |
docs = os.path.join(sys.exec_prefix, 'Doc', 'Bazaar', 'index.htm') |
1860.1.3
by Alexander Belchenko
python-installer: |
115 |
dst = os.path.join(fldr, 'Documentation.lnk') |
1861.2.6
by Alexander Belchenko
branding: change Bazaar-NG to Bazaar |
116 |
create_shortcut(docs, 'Bazaar Documentation', dst) |
1860.1.3
by Alexander Belchenko
python-installer: |
117 |
file_created(dst) |
1861.2.6
by Alexander Belchenko
branding: change Bazaar-NG to Bazaar |
118 |
print 'Documentation for Bazaar: Start => Programs => Bazaar' |
1860.1.3
by Alexander Belchenko
python-installer: |
119 |
|
120 |
# bzr in cmd shell
|
|
1861.2.11
by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98 |
121 |
if os.name == 'nt': |
122 |
cmd = os.environ.get('COMSPEC', 'cmd.exe') |
|
123 |
args = "/K bzr help" |
|
124 |
else: |
|
125 |
# minimal support of win98
|
|
126 |
cmd = os.environ.get('COMSPEC', 'command.com') |
|
127 |
args = "bzr help" |
|
1860.1.3
by Alexander Belchenko
python-installer: |
128 |
dst = os.path.join(fldr, 'Start bzr.lnk') |
129 |
create_shortcut(cmd, |
|
130 |
'Start bzr in cmd shell', |
|
131 |
dst, |
|
1861.2.11
by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98 |
132 |
args, |
1860.1.3
by Alexander Belchenko
python-installer: |
133 |
os.path.join(sys.exec_prefix, 'Scripts')) |
134 |
file_created(dst) |