/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: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

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
 
            f = file(fname, "r")
163
 
            content = f.readlines()
164
 
            f.close()
 
162
            with open(fname, "r") as f:
 
163
                content = f.readlines()
165
164
        else:
166
165
            content = ["brz.exe help\n"]
167
166
 
182
181
            print("*** File content:")
183
182
            print(''.join(content))
184
183
        else:
185
 
            f = file(fname, 'w')
186
 
            f.write(''.join(content))
187
 
            f.close()
 
184
            with open(fname, 'w') as f:
 
185
                f.write(''.join(content))
188
186
 
189
187
    if (add_path or delete_path) and winver == 'Windows NT':
190
188
        # find appropriate registry key:
193
191
        keys = ((_winreg.HKEY_LOCAL_MACHINE, (r'System\CurrentControlSet\Control'
194
192
                                              r'\Session Manager\Environment')),
195
193
                (_winreg.HKEY_CURRENT_USER, r'Environment'),
196
 
               )
 
194
                )
197
195
 
198
196
        hkey = None
199
197
        for key, subkey in keys:
241
239
                    _winreg.SetValueEx(hkey, 'Path', 0, type_, path_u)
242
240
                    _winreg.FlushKey(hkey)
243
241
 
244
 
        if not hkey is None:
 
242
        if hkey is not None:
245
243
            _winreg.CloseKey(hkey)
246
244
 
247
245
    if (add_path or delete_path) and winver == 'Windows 98':
268
266
        pattern = 'SET PATH=%PATH%;' + brz_dir_8_3
269
267
 
270
268
        # search pattern
271
 
        f = file(abat, 'r')
272
 
        lines = f.readlines()
273
 
        f.close()
 
269
        with open(abat, 'r') as f:
 
270
            lines = f.readlines()
274
271
        found = False
275
272
        for i in lines:
276
273
            if i.rstrip('\r\n') == pattern:
280
277
        if delete_path and found:
281
278
            backup_autoexec_bat(abat, abak, dry_run)
282
279
            if not dry_run:
283
 
                f = file(abat, 'w')
284
 
                for i in lines:
285
 
                    if i.rstrip('\r\n') != pattern:
286
 
                        f.write(i)
287
 
                f.close()
 
280
                with open(abat, 'w') as f:
 
281
                    for i in lines:
 
282
                        if i.rstrip('\r\n') != pattern:
 
283
                            f.write(i)
288
284
            else:
289
285
                print('*** Remove line <%s> from autoexec.bat' % pattern)
290
 
                    
 
286
 
291
287
        elif add_path and not found:
292
288
            backup_autoexec_bat(abat, abak, dry_run)
293
289
            if not dry_run:
294
 
                f = file(abat, 'a')
295
 
                f.write(pattern)
296
 
                f.write('\n')
297
 
                f.close()
 
290
                with open(abat, 'a') as f:
 
291
                    f.write(pattern)
 
292
                    f.write('\n')
298
293
            else:
299
294
                print('*** Add line <%s> to autoexec.bat' % pattern)
300
295
 
310
305
                            'EnvironmentError',
311
306
                            MB_OK | MB_ICONERROR)
312
307
 
313
 
        if not hkey is None:
 
308
        if hkey is not None:
314
309
            _winreg.SetValue(hkey, '', _winreg.REG_SZ, 'Brz Here')
315
310
            hkey2 = _winreg.CreateKey(hkey, 'command')
316
311
            _winreg.SetValue(hkey2, '', _winreg.REG_SZ,
345
340
                         "where Brz installed.\n"
346
341
                         "For detailed instructions see:\n"
347
342
                         "http://wiki.bazaar.canonical.com/BzrOnPureWindows"
348
 
                        ),
 
343
                         ),
349
344
                        "Warning",
350
345
                        MB_OK | MB_ICONEXCLAMATION)
351
346