1
# (c) Canonical Ltd, 2006
 
 
2
# written by Alexander Belchenko for bzr project
 
 
4
# This script will be executed after installation of bzrlib package
 
 
5
# and before installer exits.
 
 
6
# All printed data will appear on the last screen of installation
 
 
8
# The main goal of this script is to create special batch file
 
 
9
# launcher for bzr. Typical content of this batch file is:
 
 
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.
 
 
16
# [bialix]: bzr de-facto does not support win98.
 
 
17
#           Although it seems to work on. Sometimes.
 
 
18
# 2006/07/30    added minimal support of win98.
 
 
25
def _quoted_path(path):
 
 
27
        return '"' + path + '"'
 
 
31
def _win_batch_args():
 
 
35
        return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
 
 
38
if "-install" in sys.argv[1:]:
 
 
39
    # try to detect version number automatically
 
 
45
        ver = bzrlib.__version__
 
 
48
    # XXX change message for something more appropriate
 
 
51
Congratulation! Bzr successfully installed.
 
 
55
    batch_path = "bzr.bat"
 
 
56
    prefix = sys.exec_prefix
 
 
60
        scripts_dir = os.path.join(prefix, "Scripts")
 
 
61
        script_path = _quoted_path(os.path.join(scripts_dir, "bzr"))
 
 
62
        python_path = _quoted_path(os.path.join(prefix, "python.exe"))
 
 
63
        args = _win_batch_args()
 
 
64
        batch_str = "@%s %s %s" % (python_path, script_path, args)
 
 
65
        # minimal support of win98
 
 
66
        # if there is no HOME in system then set it for Bazaar manually
 
 
67
        homes = ('BZR_HOME', 'APPDATA', 'HOME')
 
 
69
            bzr_home = os.environ.get(home, None)
 
 
70
            if bzr_home is not None:
 
 
74
                bzr_home = get_special_folder('CSIDL_APPDATA')
 
 
80
                bzr_home = os.path.splitdrive(sys.prefix)[0] + '\\'
 
 
82
            batch_str = ("@SET BZR_HOME=" + _quoted_path(bzr_home) + "\n" +
 
 
85
        batch_path = os.path.join(scripts_dir, "bzr.bat")
 
 
86
        f = file(batch_path, "w")
 
 
89
        file_created(batch_path)        # registering manually created files for
 
 
90
                                        # auto-deinstallation procedure
 
 
92
        # inform user where batch launcher is.
 
 
93
        print "Created:", batch_path
 
 
94
        print "Use this batch file to run bzr"
 
 
96
        print "ERROR: Unable to create %s: %s" % (batch_path, e)
 
 
98
    # make entry in bzr home directory
 
 
99
    dst = os.path.join(bzr_home, "bazaar", "2.0")
 
 
100
    if not os.path.isdir(dst):
 
 
103
        print "Configuration files stored in %s" % \
 
 
104
              dst.encode(locale.getpreferredencoding(), 'replace')
 
 
105
        # create dummy bazaar.conf
 
 
106
        f = file(os.path.join(dst,'bazaar.conf'), 'w')
 
 
107
        f.write("# main configuration file of Bazaar\n"
 
 
109
                "#email=Your Name <you@domain.com>\n")
 
 
112
    ## this hunk borrowed from pywin32_postinstall.py
 
 
113
    # use bdist_wininst builtins to create a shortcut.
 
 
114
    # CSIDL_COMMON_PROGRAMS only available works on NT/2000/XP, and
 
 
115
    # will fail there if the user has no admin rights.
 
 
116
    if get_root_hkey()==_winreg.HKEY_LOCAL_MACHINE:
 
 
118
            fldr = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
 
 
120
            # No CSIDL_COMMON_PROGRAMS on this platform
 
 
121
            fldr = get_special_folder_path("CSIDL_PROGRAMS")
 
 
123
        # non-admin install - always goes in this user's start menu.
 
 
124
        fldr = get_special_folder_path("CSIDL_PROGRAMS")
 
 
127
    fldr = os.path.join(fldr, 'Bazaar')
 
 
128
    if not os.path.isdir(fldr):
 
 
130
        directory_created(fldr)
 
 
132
    # link to documentation
 
 
133
    docs = os.path.join(sys.exec_prefix, 'Doc', 'Bazaar', 'index.htm')
 
 
134
    dst = os.path.join(fldr, 'Documentation.lnk')
 
 
135
    create_shortcut(docs, 'Bazaar Documentation', dst)
 
 
137
    print 'Documentation for Bazaar: Start => Programs => Bazaar'
 
 
141
        cmd = os.environ.get('COMSPEC', 'cmd.exe')
 
 
144
        # minimal support of win98
 
 
145
        cmd = os.environ.get('COMSPEC', 'command.com')
 
 
147
    dst = os.path.join(fldr, 'Start bzr.lnk')
 
 
149
                    'Start bzr in cmd shell',
 
 
152
                    os.path.join(sys.exec_prefix, 'Scripts'))