/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/win32/brz_postinstall.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
""" % os.path.basename(sys.argv[0])
50
50
 
51
51
# Windows version
52
 
_major, _minor, _build, _platform, _text = sys.getwindowsversion()
 
52
_major,_minor,_build,_platform,_text = sys.getwindowsversion()
53
53
# from MSDN:
54
54
# dwPlatformId
55
55
#   The operating system platform.
93
93
    hkey_str = {_winreg.HKEY_LOCAL_MACHINE: 'HKEY_LOCAL_MACHINE',
94
94
                _winreg.HKEY_CURRENT_USER: 'HKEY_CURRENT_USER',
95
95
                _winreg.HKEY_CLASSES_ROOT: 'HKEY_CLASSES_ROOT',
96
 
                }
 
96
               }
97
97
 
98
98
    dry_run = False
99
99
    silent = False
115
115
                                    "add-shell-menu",
116
116
                                    "delete-shell-menu",
117
117
                                    "check-mfc71",
118
 
                                    ])
 
118
                                   ])
119
119
 
120
120
        for o, a in opts:
121
121
            if o in ("-h", "--help"):
159
159
    if start_brz:
160
160
        fname = os.path.join(brz_dir, "start_brz.bat")
161
161
        if os.path.isfile(fname):
162
 
            with open(fname, "r") as f:
163
 
                content = f.readlines()
 
162
            f = file(fname, "r")
 
163
            content = f.readlines()
 
164
            f.close()
164
165
        else:
165
166
            content = ["brz.exe help\n"]
166
167
 
181
182
            print("*** File content:")
182
183
            print(''.join(content))
183
184
        else:
184
 
            with open(fname, 'w') as f:
185
 
                f.write(''.join(content))
 
185
            f = file(fname, 'w')
 
186
            f.write(''.join(content))
 
187
            f.close()
186
188
 
187
189
    if (add_path or delete_path) and winver == 'Windows NT':
188
190
        # find appropriate registry key:
191
193
        keys = ((_winreg.HKEY_LOCAL_MACHINE, (r'System\CurrentControlSet\Control'
192
194
                                              r'\Session Manager\Environment')),
193
195
                (_winreg.HKEY_CURRENT_USER, r'Environment'),
194
 
                )
 
196
               )
195
197
 
196
198
        hkey = None
197
199
        for key, subkey in keys:
239
241
                    _winreg.SetValueEx(hkey, 'Path', 0, type_, path_u)
240
242
                    _winreg.FlushKey(hkey)
241
243
 
242
 
        if hkey is not None:
 
244
        if not hkey is None:
243
245
            _winreg.CloseKey(hkey)
244
246
 
245
247
    if (add_path or delete_path) and winver == 'Windows 98':
266
268
        pattern = 'SET PATH=%PATH%;' + brz_dir_8_3
267
269
 
268
270
        # search pattern
269
 
        with open(abat, 'r') as f:
270
 
            lines = f.readlines()
 
271
        f = file(abat, 'r')
 
272
        lines = f.readlines()
 
273
        f.close()
271
274
        found = False
272
275
        for i in lines:
273
276
            if i.rstrip('\r\n') == pattern:
277
280
        if delete_path and found:
278
281
            backup_autoexec_bat(abat, abak, dry_run)
279
282
            if not dry_run:
280
 
                with open(abat, 'w') as f:
281
 
                    for i in lines:
282
 
                        if i.rstrip('\r\n') != pattern:
283
 
                            f.write(i)
 
283
                f = file(abat, 'w')
 
284
                for i in lines:
 
285
                    if i.rstrip('\r\n') != pattern:
 
286
                        f.write(i)
 
287
                f.close()
284
288
            else:
285
289
                print('*** Remove line <%s> from autoexec.bat' % pattern)
286
 
 
 
290
                    
287
291
        elif add_path and not found:
288
292
            backup_autoexec_bat(abat, abak, dry_run)
289
293
            if not dry_run:
290
 
                with open(abat, 'a') as f:
291
 
                    f.write(pattern)
292
 
                    f.write('\n')
 
294
                f = file(abat, 'a')
 
295
                f.write(pattern)
 
296
                f.write('\n')
 
297
                f.close()
293
298
            else:
294
299
                print('*** Add line <%s> to autoexec.bat' % pattern)
295
300
 
305
310
                            'EnvironmentError',
306
311
                            MB_OK | MB_ICONERROR)
307
312
 
308
 
        if hkey is not None:
 
313
        if not hkey is None:
309
314
            _winreg.SetValue(hkey, '', _winreg.REG_SZ, 'Brz Here')
310
315
            hkey2 = _winreg.CreateKey(hkey, 'command')
311
316
            _winreg.SetValue(hkey2, '', _winreg.REG_SZ,
340
345
                         "where Brz installed.\n"
341
346
                         "For detailed instructions see:\n"
342
347
                         "http://wiki.bazaar.canonical.com/BzrOnPureWindows"
343
 
                         ),
 
348
                        ),
344
349
                        "Warning",
345
350
                        MB_OK | MB_ICONEXCLAMATION)
346
351