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