~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:
16
16
 
17
17
"""bzr postinstall helper for win32 installation
18
18
Written by Alexander Belchenko
19
 
 
20
 
Dependency: ctypes
21
19
"""
22
20
 
23
21
import os
28
26
##
29
27
# CONSTANTS
30
28
 
31
 
VERSION = "1.5.20070131"
 
29
VERSION = "1.4.20070130"
32
30
 
33
31
USAGE = """Bzr postinstall helper for win32 installation
34
32
Usage: %s [options]
50
48
 
51
49
# Windows version
52
50
_major,_minor,_build,_platform,_text = sys.getwindowsversion()
53
 
# from MSDN:
54
 
# dwPlatformId
55
 
#   The operating system platform.
56
 
#   This member can be one of the following values.
57
 
#   ==========================  ======================================
58
 
#   Value                       Meaning
59
 
#   --------------------------  --------------------------------------
60
 
#   VER_PLATFORM_WIN32_NT       The operating system is Windows Vista,
61
 
#   2                           Windows Server "Longhorn",
62
 
#                               Windows Server 2003, Windows XP,
63
 
#                               Windows 2000, or Windows NT.
64
 
#
65
 
#   VER_PLATFORM_WIN32_WINDOWS  The operating system is Windows Me,
66
 
#   1                           Windows 98, or Windows 95.
67
 
#   ==========================  ======================================
68
 
if _platform == 2:
 
51
if _platform == 0:
 
52
    raise Exception('This platform does not supported!')
 
53
elif _platform == 1:
 
54
    winver = 'Windows 98'
 
55
else:
69
56
    winver = 'Windows NT'
70
 
else:
71
 
    # don't care about real Windows name, just to force safe operations
72
 
    winver = 'Windows 98'
73
57
 
74
58
 
75
59
##
80
64
 
81
65
 
82
66
def main():
83
 
    import ctypes
84
67
    import getopt
85
68
    import re
86
69
    import _winreg
154
137
    MB_ICONERROR = 16
155
138
    MB_ICONEXCLAMATION = 48
156
139
 
157
 
    bzr_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
 
140
    bzr_dir = os.path.dirname(sys.argv[0])
158
141
 
159
142
    if start_bzr:
160
143
        fname = os.path.join(bzr_dir, "start_bzr.bat")
245
228
        # mutating autoexec.bat
246
229
        # adding or delete string:
247
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
 
248
237
        abat = 'C:\\autoexec.bat'
249
238
        abak = 'C:\\autoexec.bak'
250
239
 
256
245
                else:
257
246
                    print '*** backup copy of autoexec.bat created'
258
247
 
259
 
        GetShortPathName = ctypes.windll.kernel32.GetShortPathNameA
260
 
        buf = ctypes.create_string_buffer(260)
261
 
        if GetShortPathName(bzr_dir, buf, 260):
262
 
            bzr_dir_8_3 = buf.value
263
 
        else:
264
 
            bzr_dir_8_3 = bzr_dir
265
 
        pattern = 'SET PATH=%PATH%;' + bzr_dir_8_3
266
 
 
267
 
        # search pattern
268
 
        f = file(abat, 'r')
269
 
        lines = f.readlines()
270
 
        f.close()
271
 
        found = False
272
 
        for i in lines:
273
 
            if i.rstrip('\r\n') == pattern:
274
 
                found = True
275
 
                break
276
 
 
277
 
        if delete_path and found:
 
248
        if delete_path and bzr_dir_in_path:
278
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
279
255
            if not dry_run:
280
256
                f = file(abat, 'w')
281
257
                for i in lines:
285
261
            else:
286
262
                print '*** Remove line <%s> from autoexec.bat' % pattern
287
263
                    
288
 
        elif add_path and not found:
 
264
        elif add_path and not bzr_dir_in_path:
289
265
            backup_autoexec_bat(abat, abak, dry_run)
 
266
 
 
267
            pattern = 'SET PATH=%PATH%;' + bzr_dir
290
268
            if not dry_run:
291
269
                f = file(abat, 'a')
292
270
                f.write(pattern)
313
291
            _winreg.SetValue(hkey2, '', _winreg.REG_SZ,
314
292
                             '%s /K "%s"' % (
315
293
                                    os.environ.get('COMSPEC', '%COMSPEC%'),
316
 
                                    os.path.join(bzr_dir, 'start_bzr.bat')))
 
294
                                    os.path.join(bzr_dir, 'start_bzr.bat'))
317
295
            _winreg.CloseKey(hkey2)
318
296
            _winreg.CloseKey(hkey)
319
297