bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
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.
 | 
| 
1821.1.2
by Alexander Belchenko
 resurrected python's distutils based installer for win32  | 
19  | 
|
20  | 
import os  | 
|
21  | 
import sys  | 
|
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
22  | 
import _winreg  | 
23  | 
||
| 
1821.1.2
by Alexander Belchenko
 resurrected python's distutils based installer for win32  | 
24  | 
|
| 
1861.2.11
by Alexander Belchenko
 improved postinstall script for python installer; added minimal support of win98  | 
25  | 
def _quoted_path(path):  | 
26  | 
if ' ' in path:  | 
|
27  | 
return '"' + path + '"'  | 
|
28  | 
else:  | 
|
29  | 
return path  | 
|
30  | 
||
31  | 
def _win_batch_args():  | 
|
32  | 
if os.name == 'nt':  | 
|
33  | 
return '%*'  | 
|
34  | 
else:  | 
|
35  | 
return '%1 %2 %3 %4 %5 %6 %7 %8 %9'  | 
|
36  | 
||
37  | 
||
38  | 
if "-install" in sys.argv[1:]:  | 
|
| 
1821.1.2
by Alexander Belchenko
 resurrected python's distutils based installer for win32  | 
39  | 
    # try to detect version number automatically
 | 
40  | 
try:  | 
|
41  | 
import bzrlib  | 
|
42  | 
except ImportError:  | 
|
43  | 
ver = ''  | 
|
44  | 
else:  | 
|
45  | 
ver = bzrlib.__version__  | 
|
46  | 
||
47  | 
    ##
 | 
|
48  | 
    # XXX change message for something more appropriate
 | 
|
| 
1861.2.6
by Alexander Belchenko
 branding: change Bazaar-NG to Bazaar  | 
49  | 
print """Bazaar %s  | 
| 
1821.1.2
by Alexander Belchenko
 resurrected python's distutils based installer for win32  | 
50  | 
|
51  | 
Congratulation! Bzr successfully installed.
 | 
|
52  | 
||
53  | 
""" % ver  | 
|
54  | 
||
55  | 
batch_path = "bzr.bat"  | 
|
| 
1861.2.22
by Alexander Belchenko
 minor polishing after review  | 
56  | 
prefix = sys.exec_prefix  | 
| 
1821.1.2
by Alexander Belchenko
 resurrected python's distutils based installer for win32  | 
57  | 
try:  | 
58  | 
        ##
 | 
|
59  | 
        # try to create
 | 
|
60  | 
scripts_dir = os.path.join(prefix, "Scripts")  | 
|
| 
1861.2.11
by Alexander Belchenko
 improved postinstall script for python installer; added minimal support of win98  | 
61  | 
script_path = _quoted_path(os.path.join(scripts_dir, "bzr"))  | 
62  | 
python_path = _quoted_path(os.path.join(prefix, "python.exe"))  | 
|
63  | 
args = _win_batch_args()  | 
|
64  | 
batch_str = "@%s %s %s" % (python_path, script_path, args)  | 
|
65  | 
        # minimal support of win98
 | 
|
66  | 
        # if there is no HOME in system then set it for Bazaar manually
 | 
|
67  | 
homes = ('BZR_HOME', 'APPDATA', 'HOME')  | 
|
68  | 
for home in homes:  | 
|
69  | 
bzr_home = os.environ.get(home, None)  | 
|
70  | 
if bzr_home is not None:  | 
|
71  | 
                break
 | 
|
72  | 
else:  | 
|
73  | 
try:  | 
|
74  | 
bzr_home = get_special_folder('CSIDL_APPDATA')  | 
|
75  | 
except OSError:  | 
|
76  | 
                # no Application Data
 | 
|
77  | 
bzr_home = ''  | 
|
78  | 
||
79  | 
if not bzr_home:  | 
|
80  | 
bzr_home = os.path.splitdrive(sys.prefix)[0] + '\\'  | 
|
81  | 
||
82  | 
batch_str = ("@SET BZR_HOME=" + _quoted_path(bzr_home) + "\n" +  | 
|
83  | 
batch_str)  | 
|
84  | 
||
| 
1821.1.2
by Alexander Belchenko
 resurrected python's distutils based installer for win32  | 
85  | 
batch_path = script_path + ".bat"  | 
86  | 
f = file(batch_path, "w")  | 
|
87  | 
f.write(batch_str)  | 
|
88  | 
f.close()  | 
|
89  | 
file_created(batch_path) # registering manually created files for  | 
|
90  | 
                                        # auto-deinstallation procedure
 | 
|
91  | 
        ##
 | 
|
92  | 
        # inform user where batch launcher is.
 | 
|
93  | 
print "Created:", batch_path  | 
|
94  | 
print "Use this batch file to run bzr"  | 
|
95  | 
except Exception, e:  | 
|
96  | 
print "ERROR: Unable to create %s: %s" % (batch_path, e)  | 
|
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
97  | 
|
| 
1861.2.11
by Alexander Belchenko
 improved postinstall script for python installer; added minimal support of win98  | 
98  | 
    # make entry in bzr home directory
 | 
99  | 
dst = os.path.join(bzr_home, "bazaar", "2.0")  | 
|
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
100  | 
if not os.path.isdir(dst):  | 
101  | 
os.makedirs(dst)  | 
|
102  | 
import locale  | 
|
103  | 
print "Configuration files stored in %s" % \  | 
|
104  | 
dst.encode(locale.getpreferredencoding(), 'replace')  | 
|
105  | 
        # create dummy bazaar.conf
 | 
|
106  | 
f = file(os.path.join(dst,'bazaar.conf'), 'w')  | 
|
| 
1861.2.6
by Alexander Belchenko
 branding: change Bazaar-NG to Bazaar  | 
107  | 
f.write("# main configuration file of Bazaar\n"  | 
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
108  | 
"[DEFAULT]\n"  | 
109  | 
"#email=Your Name <you@domain.com>\n")  | 
|
110  | 
f.close()  | 
|
111  | 
||
112  | 
    ## this hunk borrowed from pywin32_postinstall.py
 | 
|
113  | 
    # use bdist_wininst builtins to create a shortcut.
 | 
|
114  | 
    # CSIDL_COMMON_PROGRAMS only available works on NT/2000/XP, and
 | 
|
115  | 
    # will fail there if the user has no admin rights.
 | 
|
116  | 
if get_root_hkey()==_winreg.HKEY_LOCAL_MACHINE:  | 
|
117  | 
try:  | 
|
118  | 
fldr = get_special_folder_path("CSIDL_COMMON_PROGRAMS")  | 
|
119  | 
except OSError:  | 
|
120  | 
            # No CSIDL_COMMON_PROGRAMS on this platform
 | 
|
121  | 
fldr = get_special_folder_path("CSIDL_PROGRAMS")  | 
|
122  | 
else:  | 
|
123  | 
        # non-admin install - always goes in this user's start menu.
 | 
|
124  | 
fldr = get_special_folder_path("CSIDL_PROGRAMS")  | 
|
125  | 
||
| 
1861.2.6
by Alexander Belchenko
 branding: change Bazaar-NG to Bazaar  | 
126  | 
    # make Bazaar entry
 | 
127  | 
fldr = os.path.join(fldr, 'Bazaar')  | 
|
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
128  | 
if not os.path.isdir(fldr):  | 
129  | 
os.mkdir(fldr)  | 
|
130  | 
directory_created(fldr)  | 
|
131  | 
||
132  | 
    # link to documentation
 | 
|
| 
1861.2.6
by Alexander Belchenko
 branding: change Bazaar-NG to Bazaar  | 
133  | 
docs = os.path.join(sys.exec_prefix, 'Doc', 'Bazaar', 'index.htm')  | 
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
134  | 
dst = os.path.join(fldr, 'Documentation.lnk')  | 
| 
1861.2.6
by Alexander Belchenko
 branding: change Bazaar-NG to Bazaar  | 
135  | 
create_shortcut(docs, 'Bazaar Documentation', dst)  | 
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
136  | 
file_created(dst)  | 
| 
1861.2.6
by Alexander Belchenko
 branding: change Bazaar-NG to Bazaar  | 
137  | 
print 'Documentation for Bazaar: Start => Programs => Bazaar'  | 
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
138  | 
|
139  | 
    # bzr in cmd shell
 | 
|
| 
1861.2.11
by Alexander Belchenko
 improved postinstall script for python installer; added minimal support of win98  | 
140  | 
if os.name == 'nt':  | 
141  | 
cmd = os.environ.get('COMSPEC', 'cmd.exe')  | 
|
142  | 
args = "/K bzr help"  | 
|
143  | 
else:  | 
|
144  | 
        # minimal support of win98
 | 
|
145  | 
cmd = os.environ.get('COMSPEC', 'command.com')  | 
|
146  | 
args = "bzr help"  | 
|
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
147  | 
dst = os.path.join(fldr, 'Start bzr.lnk')  | 
148  | 
create_shortcut(cmd,  | 
|
149  | 
'Start bzr in cmd shell',  | 
|
150  | 
dst,  | 
|
| 
1861.2.11
by Alexander Belchenko
 improved postinstall script for python installer; added minimal support of win98  | 
151  | 
args,  | 
| 
1860.1.3
by Alexander Belchenko
 python-installer:  | 
152  | 
os.path.join(sys.exec_prefix, 'Scripts'))  | 
153  | 
file_created(dst)  |