~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/win32/bzr-win32-bdist-postinstall.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 17:42:23 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730174223-0ca6148aa4a070f7
improved postinstall script for python installer; added minimal support of win98

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#
16
16
# [bialix]: bzr de-facto does not support win98.
17
17
#           Although it seems to work on. Sometimes.
 
18
# 2006/07/30    added minimal support of win98.
18
19
 
19
20
import os
20
21
import sys
21
22
import _winreg
22
23
 
23
24
 
24
 
if len(sys.argv) == 2 and sys.argv[1] == "-install":
 
25
def _quoted_path(path):
 
26
    if ' ' in path:
 
27
        return '"' + path + '"'
 
28
    else:
 
29
        return path
 
30
 
 
31
def _win_batch_args():
 
32
    if os.name == 'nt':
 
33
        return '%*'
 
34
    else:
 
35
        return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
 
36
 
 
37
 
 
38
if "-install" in sys.argv[1:]:
25
39
    # try to detect version number automatically
26
40
    try:
27
41
        import bzrlib
44
58
        ##
45
59
        # try to create
46
60
        scripts_dir = os.path.join(prefix, "Scripts")
47
 
        script_path = os.path.join(scripts_dir, "bzr")
48
 
        python_path = os.path.join(prefix, "python.exe")
49
 
        batch_str = "@%s %s %%*\n" % (python_path, script_path)
 
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')
 
68
        for home in homes:
 
69
            bzr_home = os.environ.get(home, None)
 
70
            if bzr_home is not None:
 
71
                break
 
72
        else:
 
73
            try:
 
74
                bzr_home = get_special_folder('CSIDL_APPDATA')
 
75
            except OSError:
 
76
                # no Application Data
 
77
                bzr_home = ''
 
78
 
 
79
            if not bzr_home:
 
80
                bzr_home = os.path.splitdrive(sys.prefix)[0] + '\\'
 
81
 
 
82
            batch_str = ("@SET BZR_HOME=" + _quoted_path(bzr_home) + "\n" +
 
83
                         batch_str)
 
84
 
50
85
        batch_path = script_path + ".bat"
51
86
        f = file(batch_path, "w")
52
87
        f.write(batch_str)
60
95
    except Exception, e:
61
96
        print "ERROR: Unable to create %s: %s" % (batch_path, e)
62
97
 
63
 
    # make entry in APPDATA
64
 
    appdata = get_special_folder_path("CSIDL_APPDATA")
65
 
    dst = os.path.join(appdata, "bazaar", "2.0")
 
98
    # make entry in bzr home directory
 
99
    dst = os.path.join(bzr_home, "bazaar", "2.0")
66
100
    if not os.path.isdir(dst):
67
101
        os.makedirs(dst)
68
102
        import locale
103
137
    print 'Documentation for Bazaar: Start => Programs => Bazaar'
104
138
 
105
139
    # bzr in cmd shell
106
 
    cmd = os.environ.get('COMSPEC', 'cmd.exe')
 
140
    if os.name == 'nt':
 
141
        cmd = os.environ.get('COMSPEC', 'cmd.exe')
 
142
        args = "/K bzr help"
 
143
    else:
 
144
        # minimal support of win98
 
145
        cmd = os.environ.get('COMSPEC', 'command.com')
 
146
        args = "bzr help"
107
147
    dst = os.path.join(fldr, 'Start bzr.lnk')
108
148
    create_shortcut(cmd,
109
149
                    'Start bzr in cmd shell',
110
150
                    dst,
111
 
                    "/K bzr help",
 
151
                    args,
112
152
                    os.path.join(sys.exec_prefix, 'Scripts'))
113
153
    file_created(dst)