~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-31 11:58:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2259.
  • Revision ID: bialix@ukr.net-20070131115836-lqp9u79n2t8xk3eg
bzr_postinstall.py: on win98 path added to autoexec.bat should have 8.3 form

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""bzr postinstall helper for win32 installation
18
18
Written by Alexander Belchenko
 
19
 
 
20
Dependency: ctypes
19
21
"""
20
22
 
21
23
import os
26
28
##
27
29
# CONSTANTS
28
30
 
29
 
VERSION = "1.4.20070130"
 
31
VERSION = "1.5.20070131"
30
32
 
31
33
USAGE = """Bzr postinstall helper for win32 installation
32
34
Usage: %s [options]
64
66
 
65
67
 
66
68
def main():
 
69
    import ctypes
67
70
    import getopt
68
71
    import re
69
72
    import _winreg
137
140
    MB_ICONERROR = 16
138
141
    MB_ICONEXCLAMATION = 48
139
142
 
140
 
    bzr_dir = os.path.dirname(sys.argv[0])
 
143
    bzr_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
141
144
 
142
145
    if start_bzr:
143
146
        fname = os.path.join(bzr_dir, "start_bzr.bat")
228
231
        # mutating autoexec.bat
229
232
        # adding or delete string:
230
233
        # 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
234
        abat = 'C:\\autoexec.bat'
238
235
        abak = 'C:\\autoexec.bak'
239
236
 
245
242
                else:
246
243
                    print '*** backup copy of autoexec.bat created'
247
244
 
248
 
        if delete_path and bzr_dir_in_path:
 
245
        GetShortPathName = ctypes.windll.kernel32.GetShortPathNameA
 
246
        buf = ctypes.create_string_buffer(260)
 
247
        if GetShortPathName(bzr_dir, buf, 260):
 
248
            bzr_dir_8_3 = buf.value
 
249
        else:
 
250
            bzr_dir_8_3 = bzr_dir
 
251
        pattern = 'SET PATH=%PATH%;' + bzr_dir_8_3
 
252
 
 
253
        # search pattern
 
254
        f = file(abat, 'r')
 
255
        lines = f.readlines()
 
256
        f.close()
 
257
        found = False
 
258
        for i in lines:
 
259
            if i.rstrip('\r\n') == pattern:
 
260
                found = True
 
261
                break
 
262
 
 
263
        if delete_path and found:
249
264
            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
265
            if not dry_run:
256
266
                f = file(abat, 'w')
257
267
                for i in lines:
261
271
            else:
262
272
                print '*** Remove line <%s> from autoexec.bat' % pattern
263
273
                    
264
 
        elif add_path and not bzr_dir_in_path:
 
274
        elif add_path and not found:
265
275
            backup_autoexec_bat(abat, abak, dry_run)
266
 
 
267
 
            pattern = 'SET PATH=%PATH%;' + bzr_dir
268
276
            if not dry_run:
269
277
                f = file(abat, 'a')
270
278
                f.write(pattern)
291
299
            _winreg.SetValue(hkey2, '', _winreg.REG_SZ,
292
300
                             '%s /K "%s"' % (
293
301
                                    os.environ.get('COMSPEC', '%COMSPEC%'),
294
 
                                    os.path.join(bzr_dir, 'start_bzr.bat'))
 
302
                                    os.path.join(bzr_dir, 'start_bzr.bat')))
295
303
            _winreg.CloseKey(hkey2)
296
304
            _winreg.CloseKey(hkey)
297
305