~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/win32/bzr_postinstall.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-30 23:05:35 UTC
  • mto: This revision was merged to the branch mainline in revision 2259.
  • Revision ID: bialix@ukr.net-20070130230535-kx1rd478rtigyc3v
standalone installer: win98 support

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""
20
20
 
21
21
import os
 
22
import shutil
22
23
import sys
23
24
 
24
25
 
25
26
##
26
27
# CONSTANTS
27
28
 
28
 
VERSION = "1.3.20060513"
 
29
VERSION = "1.4.20070130"
29
30
 
30
31
USAGE = """Bzr postinstall helper for win32 installation
31
32
Usage: %s [options]
45
46
    --check-mfc71               - check if MFC71.DLL present in system
46
47
""" % os.path.basename(sys.argv[0])
47
48
 
 
49
# Windows version
 
50
_major,_minor,_build,_platform,_text = sys.getwindowsversion()
 
51
if _platform == 0:
 
52
    raise Exception('This platform does not supported!')
 
53
elif _platform == 1:
 
54
    winver = 'Windows 98'
 
55
else:
 
56
    winver = 'Windows NT'
 
57
 
 
58
 
48
59
##
49
60
# INTERNAL VARIABLES
50
61
 
155
166
            f.write(''.join(content))
156
167
            f.close()
157
168
 
158
 
    if add_path or delete_path:
 
169
    if (add_path or delete_path) and winver == 'Windows NT':
159
170
        # find appropriate registry key:
160
171
        # 1. HKLM\System\CurrentControlSet\Control\SessionManager\Environment
161
172
        # 2. HKCU\Environment
213
224
        if not hkey is None:
214
225
            _winreg.CloseKey(hkey)
215
226
 
 
227
    if (add_path or delete_path) and winver == 'Windows 98':
 
228
        # mutating autoexec.bat
 
229
        # adding or delete string:
 
230
        # SET PATH=%PATH%;C:\PROGRA~1\Bazaar
 
231
        cur_path = os.environ.get('PATH')
 
232
        if cur_path.find(bzr_dir) != -1:
 
233
            bzr_dir_in_path = True
 
234
        else:
 
235
            bzr_dir_in_path = False
 
236
 
 
237
        abat = 'C:\\autoexec.bat'
 
238
        abak = 'C:\\autoexec.bak'
 
239
 
 
240
        def backup_autoexec_bat(name, backupname, dry_run):
 
241
            # backup autoexec.bat
 
242
            if os.path.isfile(name):
 
243
                if not dry_run:
 
244
                    shutil.copyfile(name, backupname)
 
245
                else:
 
246
                    print '*** backup copy of autoexec.bat created'
 
247
 
 
248
        if delete_path and bzr_dir_in_path:
 
249
            backup_autoexec_bat(abat, abak, dry_run)
 
250
            f = file(abat, 'r')
 
251
            lines = f.readlines()
 
252
            f.close()
 
253
 
 
254
            pattern = 'SET PATH=%PATH%;' + bzr_dir
 
255
            if not dry_run:
 
256
                f = file(abat, 'w')
 
257
                for i in lines:
 
258
                    if i.rstrip('\r\n') != pattern:
 
259
                        f.write(i)
 
260
                f.close()
 
261
            else:
 
262
                print '*** Remove line <%s> from autoexec.bat' % pattern
 
263
                    
 
264
        elif add_path and not bzr_dir_in_path:
 
265
            backup_autoexec_bat(abat, abak, dry_run)
 
266
 
 
267
            pattern = 'SET PATH=%PATH%;' + bzr_dir
 
268
            if not dry_run:
 
269
                f = file(abat, 'a')
 
270
                f.write(pattern)
 
271
                f.write('\n')
 
272
                f.close()
 
273
            else:
 
274
                print '*** Add line <%s> to autoexec.bat' % pattern
 
275
 
216
276
    if add_shell_menu and not delete_shell_menu:
217
277
        hkey = None
218
278
        try:
229
289
            _winreg.SetValue(hkey, '', _winreg.REG_SZ, 'Bzr Here')
230
290
            hkey2 = _winreg.CreateKey(hkey, 'command')
231
291
            _winreg.SetValue(hkey2, '', _winreg.REG_SZ,
232
 
                             'cmd /K "%s"' % os.path.join(bzr_dir,
233
 
                                                          'start_bzr.bat'))
 
292
                             '%s /K "%s"' % (
 
293
                                    os.environ.get('COMSPEC', '%COMSPEC%'),
 
294
                                    os.path.join(bzr_dir, 'start_bzr.bat'))
234
295
            _winreg.CloseKey(hkey2)
235
296
            _winreg.CloseKey(hkey)
236
297