/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
1
# (c) Canonical Ltd, 2006
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
2
# written by Alexander Belchenko for brz project
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
3
#
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
4
# This script will be executed after installation of breezy package
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
5
# and before installer exits.
6
# All printed data will appear on the last screen of installation
7
# procedure.
8
# The main goal of this script is to create special batch file
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
9
# launcher for brz. Typical content of this batch file is:
10
#  @python brz %*
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
11
#
12
# This file works only on Windows 2000/XP. For win98 there is
13
# should be "%1 %2 %3 %4 %5 %6 %7 %8 %9" instead of "%*".
14
# Or even more complex thing.
15
#
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
16
# [bialix]: brz de-facto does not support win98.
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
17
#           Although it seems to work on. Sometimes.
1861.2.11 by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98
18
# 2006/07/30    added minimal support of win98.
2245.4.5 by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support
19
# 2007/01/30    added *real* support of win98.
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
20
21
import os
22
import sys
1860.1.3 by Alexander Belchenko
python-installer:
23
import _winreg
24
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
from breezy import win32utils
2245.4.5 by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support
26
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
27
1861.2.11 by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98
28
def _quoted_path(path):
29
    if ' ' in path:
30
        return '"' + path + '"'
31
    else:
32
        return path
33
34
def _win_batch_args():
2245.4.5 by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support
35
    if win32utils.winver == 'Windows NT':
1861.2.11 by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98
36
        return '%*'
37
    else:
38
        return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
39
40
41
if "-install" in sys.argv[1:]:
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
42
    # try to detect version number automatically
43
    try:
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
44
        import breezy
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
45
    except ImportError:
46
        ver = ''
47
    else:
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
48
        ver = breezy.__version__
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
49
50
    ##
51
    # XXX change message for something more appropriate
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
52
    print("""Breezy %s
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
53
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
54
Congratulation! Brz successfully installed.
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
55
6619.3.3 by Jelmer Vernooij
Apply 2to3 print fix.
56
""" % ver)
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
57
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
58
    batch_path = "brz.bat"
1861.2.22 by Alexander Belchenko
minor polishing after review
59
    prefix = sys.exec_prefix
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
60
    try:
61
        ##
62
        # try to create
63
        scripts_dir = os.path.join(prefix, "Scripts")
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
64
        script_path = _quoted_path(os.path.join(scripts_dir, "brz"))
1861.2.11 by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98
65
        python_path = _quoted_path(os.path.join(prefix, "python.exe"))
66
        args = _win_batch_args()
67
        batch_str = "@%s %s %s" % (python_path, script_path, args)
2245.4.5 by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support
68
        # support of win98
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
69
        # if there is no HOME for brz then set it for Breezy manually
70
        base = os.environ.get('brz_HOME', None)
2245.4.5 by Alexander Belchenko
bzr-win32-bdist-postinstall.py: good win98 support
71
        if base is None:
72
            base = win32utils.get_appdata_location()
73
        if base is None:
74
            base = os.environ.get('HOME', None)
75
        if base is None:
76
            base = os.path.splitdrive(sys.prefix)[0] + '\\'
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
77
            batch_str = ("@SET brz_HOME=" + _quoted_path(base) + "\n" +
1861.2.11 by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98
78
                         batch_str)
79
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
80
        batch_path = os.path.join(scripts_dir, "brz.bat")
6973.7.5 by Jelmer Vernooij
s/file/open.
81
        with open(batch_path, "w") as f:
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
82
            f.write(batch_str)
7143.16.4 by Jelmer Vernooij
Remove E116
83
        # registering manually created files for auto-deinstallation procedure
84
        file_created(batch_path)
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
85
        ##
86
        # inform user where batch launcher is.
6619.3.3 by Jelmer Vernooij
Apply 2to3 print fix.
87
        print("Created:", batch_path)
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
88
        print("Use this batch file to run brz")
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
89
    except Exception as e:
6619.3.3 by Jelmer Vernooij
Apply 2to3 print fix.
90
        print("ERROR: Unable to create %s: %s" % (batch_path, e))
1860.1.3 by Alexander Belchenko
python-installer:
91
92
    ## this hunk borrowed from pywin32_postinstall.py
93
    # use bdist_wininst builtins to create a shortcut.
94
    # CSIDL_COMMON_PROGRAMS only available works on NT/2000/XP, and
95
    # will fail there if the user has no admin rights.
7143.16.17 by Jelmer Vernooij
Fix E225.
96
    if get_root_hkey() == _winreg.HKEY_LOCAL_MACHINE:
1860.1.3 by Alexander Belchenko
python-installer:
97
        try:
98
            fldr = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
99
        except OSError:
100
            # No CSIDL_COMMON_PROGRAMS on this platform
101
            fldr = get_special_folder_path("CSIDL_PROGRAMS")
102
    else:
103
        # non-admin install - always goes in this user's start menu.
104
        fldr = get_special_folder_path("CSIDL_PROGRAMS")
105
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
106
    # make Breezy entry
107
    fldr = os.path.join(fldr, 'Breezy')
1860.1.3 by Alexander Belchenko
python-installer:
108
    if not os.path.isdir(fldr):
109
        os.mkdir(fldr)
110
        directory_created(fldr)
111
112
    # link to documentation
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
113
    docs = os.path.join(sys.exec_prefix, 'Doc', 'Breezy', 'index.html')
1860.1.3 by Alexander Belchenko
python-installer:
114
    dst = os.path.join(fldr, 'Documentation.lnk')
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
115
    create_shortcut(docs, 'Breezy Documentation', dst)
1860.1.3 by Alexander Belchenko
python-installer:
116
    file_created(dst)
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
117
    print('Documentation for Breezy: Start => Programs => Breezy')
1860.1.3 by Alexander Belchenko
python-installer:
118
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
119
    # brz in cmd shell
1861.2.11 by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98
120
    if os.name == 'nt':
121
        cmd = os.environ.get('COMSPEC', 'cmd.exe')
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
122
        args = "/K brz help"
1861.2.11 by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98
123
    else:
124
        # minimal support of win98
125
        cmd = os.environ.get('COMSPEC', 'command.com')
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
126
        args = "brz help"
127
    dst = os.path.join(fldr, 'Start brz.lnk')
1860.1.3 by Alexander Belchenko
python-installer:
128
    create_shortcut(cmd,
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
129
                    'Start brz in cmd shell',
1860.1.3 by Alexander Belchenko
python-installer:
130
                    dst,
1861.2.11 by Alexander Belchenko
improved postinstall script for python installer; added minimal support of win98
131
                    args,
1860.1.3 by Alexander Belchenko
python-installer:
132
                    os.path.join(sys.exec_prefix, 'Scripts'))
133
    file_created(dst)
2946.2.1 by Alexander Belchenko
windows python-based installer: shortcut for uninstall action
134
135
    # uninstall shortcut
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
136
    uninst = os.path.join(sys.exec_prefix, 'Removebrz.exe')
137
    dst = os.path.join(fldr, 'Uninstall Breezy.lnk')
2946.2.1 by Alexander Belchenko
windows python-based installer: shortcut for uninstall action
138
    create_shortcut(uninst,
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
139
                    'Uninstall Breezy',
2946.2.1 by Alexander Belchenko
windows python-based installer: shortcut for uninstall action
140
                    dst,
6622.1.18 by Jelmer Vernooij
Rename some windows stuff.
141
                    '-u brz-wininst.log',
2946.2.1 by Alexander Belchenko
windows python-based installer: shortcut for uninstall action
142
                    sys.exec_prefix,
143
                    )
144
    file_created(dst)