/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-05-21 19:09:26 UTC
  • mfrom: (6622.1.36 breezy)
  • Revision ID: jelmer@jelmer.uk-20170521190926-5vtz8xaf0e9ylrpc
Merge rename to breezy.

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",
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":
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'))
176
 
            elif s.find(r'C:\Program Files\Bazaar') != -1:
177
 
                content[ix] = s.replace(r'C:\Program Files\Bazaar',
178
 
                                        bzr_dir)
 
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)
179
179
 
180
180
        if dry_run:
181
 
            print "*** Write file: start_bzr.bat"
 
181
            print "*** Write file: start_brz.bat"
182
182
            print "*** File content:"
183
183
            print ''.join(content)
184
184
        else:
219
219
            path_list = [i for i in path_u.split(os.pathsep) if i != '']
220
220
            f_change = False
221
221
            for ix, item in enumerate(path_list[:]):
222
 
                if item == bzr_dir:
 
222
                if item == brz_dir:
223
223
                    if delete_path:
224
224
                        del path_list[ix]
225
225
                        f_change = True
226
226
                    elif add_path:
227
 
                        print "*** Bzr already in PATH"
 
227
                        print "*** Brz already in PATH"
228
228
                    break
229
229
            else:
230
230
                if add_path and not delete_path:
231
 
                    path_list.append(bzr_dir.decode(user_encoding))
 
231
                    path_list.append(brz_dir.decode(user_encoding))
232
232
                    f_change = True
233
233
 
234
234
            if f_change:
247
247
    if (add_path or delete_path) and winver == 'Windows 98':
248
248
        # mutating autoexec.bat
249
249
        # adding or delete string:
250
 
        # SET PATH=%PATH%;C:\PROGRA~1\Bazaar
 
250
        # SET PATH=%PATH%;C:\PROGRA~1\Breezy
251
251
        abat = 'C:\\autoexec.bat'
252
252
        abak = 'C:\\autoexec.bak'
253
253
 
261
261
 
262
262
        GetShortPathName = ctypes.windll.kernel32.GetShortPathNameA
263
263
        buf = ctypes.create_string_buffer(260)
264
 
        if GetShortPathName(bzr_dir, buf, 260):
265
 
            bzr_dir_8_3 = buf.value
 
264
        if GetShortPathName(brz_dir, buf, 260):
 
265
            brz_dir_8_3 = buf.value
266
266
        else:
267
 
            bzr_dir_8_3 = bzr_dir
268
 
        pattern = 'SET PATH=%PATH%;' + bzr_dir_8_3
 
267
            brz_dir_8_3 = brz_dir
 
268
        pattern = 'SET PATH=%PATH%;' + brz_dir_8_3
269
269
 
270
270
        # search pattern
271
271
        f = file(abat, 'r')
302
302
        hkey = None
303
303
        try:
304
304
            hkey = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
305
 
                                     r'Folder\shell\bzr')
 
305
                                     r'Folder\shell\brz')
306
306
        except EnvironmentError:
307
307
            if not silent:
308
308
                MessageBoxA(None,
311
311
                            MB_OK | MB_ICONERROR)
312
312
 
313
313
        if not hkey is None:
314
 
            _winreg.SetValue(hkey, '', _winreg.REG_SZ, 'Bzr Here')
 
314
            _winreg.SetValue(hkey, '', _winreg.REG_SZ, 'Brz Here')
315
315
            hkey2 = _winreg.CreateKey(hkey, 'command')
316
316
            _winreg.SetValue(hkey2, '', _winreg.REG_SZ,
317
317
                             '%s /K "%s"' % (
318
318
                                    os.environ.get('COMSPEC', '%COMSPEC%'),
319
 
                                    os.path.join(bzr_dir, 'start_bzr.bat')))
 
319
                                    os.path.join(brz_dir, 'start_brz.bat')))
320
320
            _winreg.CloseKey(hkey2)
321
321
            _winreg.CloseKey(hkey)
322
322
 
323
323
    if delete_shell_menu:
324
324
        try:
325
325
            _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
326
 
                              r'Folder\shell\bzr\command')
 
326
                              r'Folder\shell\brz\command')
327
327
        except EnvironmentError:
328
328
            pass
329
329
 
330
330
        try:
331
331
            _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
332
 
                              r'Folder\shell\bzr')
 
332
                              r'Folder\shell\brz')
333
333
        except EnvironmentError:
334
334
            pass
335
335
 
342
342
                         "This library needed for SFTP transport.\n"
343
343
                         "If you need to work via SFTP you should download\n"
344
344
                         "this library manually and put it to directory\n"
345
 
                         "where Bzr installed.\n"
 
345
                         "where Brz installed.\n"
346
346
                         "For detailed instructions see:\n"
347
347
                         "http://wiki.bazaar.canonical.com/BzrOnPureWindows"
348
348
                        ),