/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-06-05 23:35:09 UTC
  • mfrom: (6658 work)
  • mto: (6653.3.3 bzrwt)
  • mto: This revision was merged to the branch mainline in revision 6667.
  • Revision ID: jelmer@jelmer.uk-20170605233509-30wo916k6meuggqf
MergeĀ lp:brz

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""bzr postinstall helper for win32 installation
 
17
"""brz postinstall helper for win32 installation
18
18
Written by Alexander Belchenko
19
19
 
20
20
Dependency: ctypes
30
30
 
31
31
VERSION = "1.5.20070131"
32
32
 
33
 
USAGE = """Bzr postinstall helper for win32 installation
 
33
USAGE = """Brz postinstall helper for win32 installation
34
34
Usage: %s [options]
35
35
 
36
36
OPTIONS:
40
40
    -n, --dry-run               - print actions rather than execute them
41
41
    -q, --silent                - no messages for user
42
42
 
43
 
    --start-bzr                 - update start_bzr.bat
44
 
    --add-path                  - add bzr directory to environment PATH
45
 
    --delete-path               - delete bzr directory to environment PATH
46
 
    --add-shell-menu            - add shell context menu to start bzr session
 
43
    --start-brz                 - update start_brz.bat
 
44
    --add-path                  - add brz directory to environment PATH
 
45
    --delete-path               - delete brz directory to environment PATH
 
46
    --add-shell-menu            - add shell context menu to start brz session
47
47
    --delete-shell-menu         - delete context menu from shell
48
48
    --check-mfc71               - check if MFC71.DLL present in system
49
49
""" % os.path.basename(sys.argv[0])
97
97
 
98
98
    dry_run = False
99
99
    silent = False
100
 
    start_bzr = False
 
100
    start_brz = False
101
101
    add_path = False
102
102
    delete_path = False
103
103
    add_shell_menu = False
109
109
                                   ["help", "version",
110
110
                                    "dry-run",
111
111
                                    "silent",
112
 
                                    "start-bzr",
 
112
                                    "start-brz",
113
113
                                    "add-path",
114
114
                                    "delete-path",
115
115
                                    "add-shell-menu",
119
119
 
120
120
        for o, a in opts:
121
121
            if o in ("-h", "--help"):
122
 
                print USAGE
 
122
                print(USAGE)
123
123
                return OK
124
124
            elif o in ("-v", "--version"):
125
 
                print VERSION_FORMAT % (USAGE.splitlines()[0], VERSION)
 
125
                print(VERSION_FORMAT % (USAGE.splitlines()[0], VERSION))
126
126
                return OK
127
127
 
128
128
            elif o in ('-n', "--dry-run"):
130
130
            elif o in ('-q', '--silent'):
131
131
                silent = True
132
132
 
133
 
            elif o == "--start-bzr":
134
 
                start_bzr = True
 
133
            elif o == "--start-brz":
 
134
                start_brz = True
135
135
            elif o == "--add-path":
136
136
                add_path = True
137
137
            elif o == "--delete-path":
143
143
            elif o == "--check-mfc71":
144
144
                check_mfc71 = True
145
145
 
146
 
    except getopt.GetoptError, msg:
147
 
        print str(msg)
148
 
        print USAGE
 
146
    except getopt.GetoptError as msg:
 
147
        print(str(msg))
 
148
        print(USAGE)
149
149
        return ERROR
150
150
 
151
151
    # message box from Win32API
154
154
    MB_ICONERROR = 16
155
155
    MB_ICONEXCLAMATION = 48
156
156
 
157
 
    bzr_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
 
157
    brz_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
158
158
 
159
 
    if start_bzr:
160
 
        fname = os.path.join(bzr_dir, "start_bzr.bat")
 
159
    if start_brz:
 
160
        fname = os.path.join(brz_dir, "start_brz.bat")
161
161
        if os.path.isfile(fname):
162
162
            f = file(fname, "r")
163
163
            content = f.readlines()
164
164
            f.close()
165
165
        else:
166
 
            content = ["bzr.exe help\n"]
 
166
            content = ["brz.exe help\n"]
167
167
 
168
168
        for ix in xrange(len(content)):
169
169
            s = content[ix]
170
 
            if re.match(r'.*(?<!\\)bzr\.exe([ "].*)?$',
 
170
            if re.match(r'.*(?<!\\)brz\.exe([ "].*)?$',
171
171
                        s.rstrip('\r\n'),
172
172
                        re.IGNORECASE):
173
 
                content[ix] = s.replace('bzr.exe',
174
 
                                        '"%s"' % os.path.join(bzr_dir,
175
 
                                                              'bzr.exe'))
 
173
                content[ix] = s.replace('brz.exe',
 
174
                                        '"%s"' % os.path.join(brz_dir,
 
175
                                                              'brz.exe'))
 
176
            elif s.find(r'C:\Program Files\Breezy') != -1:
 
177
                content[ix] = s.replace(r'C:\Program Files\Breezy',
 
178
                                        brz_dir)
176
179
 
177
180
        if dry_run:
178
 
            print "*** Write file: start_bzr.bat"
179
 
            print "*** File content:"
180
 
            print ''.join(content)
 
181
            print("*** Write file: start_brz.bat")
 
182
            print("*** File content:")
 
183
            print(''.join(content))
181
184
        else:
182
185
            f = file(fname, 'w')
183
186
            f.write(''.join(content))
211
214
            break
212
215
 
213
216
        if hkey is None:
214
 
            print "Cannot find appropriate registry key for PATH"
 
217
            print("Cannot find appropriate registry key for PATH")
215
218
        else:
216
219
            path_list = [i for i in path_u.split(os.pathsep) if i != '']
217
220
            f_change = False
218
221
            for ix, item in enumerate(path_list[:]):
219
 
                if item == bzr_dir:
 
222
                if item == brz_dir:
220
223
                    if delete_path:
221
224
                        del path_list[ix]
222
225
                        f_change = True
223
226
                    elif add_path:
224
 
                        print "*** Bzr already in PATH"
 
227
                        print("*** brz already in PATH")
225
228
                    break
226
229
            else:
227
230
                if add_path and not delete_path:
228
 
                    path_list.append(bzr_dir.decode(user_encoding))
 
231
                    path_list.append(brz_dir.decode(user_encoding))
229
232
                    f_change = True
230
233
 
231
234
            if f_change:
232
235
                path_u = os.pathsep.join(path_list)
233
236
                if dry_run:
234
 
                    print "*** Registry key %s\\%s" % (hkey_str[key], subkey)
235
 
                    print "*** Modify PATH variable. New value:"
236
 
                    print path_u
 
237
                    print("*** Registry key %s\\%s" % (hkey_str[key], subkey))
 
238
                    print("*** Modify PATH variable. New value:")
 
239
                    print(path_u)
237
240
                else:
238
241
                    _winreg.SetValueEx(hkey, 'Path', 0, type_, path_u)
239
242
                    _winreg.FlushKey(hkey)
244
247
    if (add_path or delete_path) and winver == 'Windows 98':
245
248
        # mutating autoexec.bat
246
249
        # adding or delete string:
247
 
        # SET PATH=%PATH%;C:\PROGRA~1\Bazaar
 
250
        # SET PATH=%PATH%;C:\PROGRA~1\Breezy
248
251
        abat = 'C:\\autoexec.bat'
249
252
        abak = 'C:\\autoexec.bak'
250
253
 
254
257
                if not dry_run:
255
258
                    shutil.copyfile(name, backupname)
256
259
                else:
257
 
                    print '*** backup copy of autoexec.bat created'
 
260
                    print('*** backup copy of autoexec.bat created')
258
261
 
259
262
        GetShortPathName = ctypes.windll.kernel32.GetShortPathNameA
260
263
        buf = ctypes.create_string_buffer(260)
261
 
        if GetShortPathName(bzr_dir, buf, 260):
262
 
            bzr_dir_8_3 = buf.value
 
264
        if GetShortPathName(brz_dir, buf, 260):
 
265
            brz_dir_8_3 = buf.value
263
266
        else:
264
 
            bzr_dir_8_3 = bzr_dir
265
 
        pattern = 'SET PATH=%PATH%;' + bzr_dir_8_3
 
267
            brz_dir_8_3 = brz_dir
 
268
        pattern = 'SET PATH=%PATH%;' + brz_dir_8_3
266
269
 
267
270
        # search pattern
268
271
        f = file(abat, 'r')
283
286
                        f.write(i)
284
287
                f.close()
285
288
            else:
286
 
                print '*** Remove line <%s> from autoexec.bat' % pattern
 
289
                print('*** Remove line <%s> from autoexec.bat' % pattern)
287
290
                    
288
291
        elif add_path and not found:
289
292
            backup_autoexec_bat(abat, abak, dry_run)
293
296
                f.write('\n')
294
297
                f.close()
295
298
            else:
296
 
                print '*** Add line <%s> to autoexec.bat' % pattern
 
299
                print('*** Add line <%s> to autoexec.bat' % pattern)
297
300
 
298
301
    if add_shell_menu and not delete_shell_menu:
299
302
        hkey = None
300
303
        try:
301
304
            hkey = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
302
 
                                     r'Folder\shell\bzr')
 
305
                                     r'Folder\shell\brz')
303
306
        except EnvironmentError:
304
307
            if not silent:
305
308
                MessageBoxA(None,
308
311
                            MB_OK | MB_ICONERROR)
309
312
 
310
313
        if not hkey is None:
311
 
            _winreg.SetValue(hkey, '', _winreg.REG_SZ, 'Bzr Here')
 
314
            _winreg.SetValue(hkey, '', _winreg.REG_SZ, 'Brz Here')
312
315
            hkey2 = _winreg.CreateKey(hkey, 'command')
313
316
            _winreg.SetValue(hkey2, '', _winreg.REG_SZ,
314
317
                             '%s /K "%s"' % (
315
318
                                    os.environ.get('COMSPEC', '%COMSPEC%'),
316
 
                                    os.path.join(bzr_dir, 'start_bzr.bat')))
 
319
                                    os.path.join(brz_dir, 'start_brz.bat')))
317
320
            _winreg.CloseKey(hkey2)
318
321
            _winreg.CloseKey(hkey)
319
322
 
320
323
    if delete_shell_menu:
321
324
        try:
322
325
            _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
323
 
                              r'Folder\shell\bzr\command')
 
326
                              r'Folder\shell\brz\command')
324
327
        except EnvironmentError:
325
328
            pass
326
329
 
327
330
        try:
328
331
            _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
329
 
                              r'Folder\shell\bzr')
 
332
                              r'Folder\shell\brz')
330
333
        except EnvironmentError:
331
334
            pass
332
335
 
339
342
                         "This library needed for SFTP transport.\n"
340
343
                         "If you need to work via SFTP you should download\n"
341
344
                         "this library manually and put it to directory\n"
342
 
                         "where Bzr installed.\n"
 
345
                         "where Brz installed.\n"
343
346
                         "For detailed instructions see:\n"
344
347
                         "http://wiki.bazaar.canonical.com/BzrOnPureWindows"
345
348
                        ),