~jelmer/brz/tree-reference-fixes

« back to all changes in this revision

Viewing changes to tools/win32/brz_postinstall.py

  • Committer: Jelmer Vernooij
  • Date: 2018-03-25 12:47:13 UTC
  • mfrom: (6926.1.2 work)
  • Revision ID: jelmer@jelmer.uk-20180325124713-dq64vm9bhch1gjow
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 file(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 file(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:
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 file(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 file(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 file(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