-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup_postinstall.py
125 lines (94 loc) · 4.06 KB
/
setup_postinstall.py
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
#!/usr/bin/env python
#
# Copyright (C) 2007-2018 CZ.NIC, z. s. p. o.
#
# This file is part of FRED.
#
# FRED is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FRED is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FRED. If not, see <https://www.gnu.org/licenses/>.
"""
Create shortcuts on the Windows desktop agter installation.
Distribution create:
$ python setup.py bdist_wininst --install-script=setup_postinstall.py
"""
import sys, os, re
import distutils.sysconfig
from fred.internal_variables import fred_version, config_name
from fred.session_config import get_etc_config_name
if sys.platform[:3] != 'win':
sys.stderr.write('This script is designed only for MS Windows platform.\n')
sys.exit()
config_root = os.path.join(sys.prefix, 'etc/fred')
config_name_ini = re.sub(r'\.conf', '.ini', config_name)
path = os.path.join(sys.prefix, 'share/fred-client')
FRED_CLIENT_SSL_PATH = os.path.join(path, 'ssl')
FRED_CLIENT_SCHEMAS_FILEMANE = os.path.join(path, 'schemas/all-1.4.xsd')
# Name of the main console script
script_name = 'fred-client'
help_name = 'fred_howto_cs.html'
# BAT file is created to prevent closing the console after the script has been finished.
bat_file = 'fred-client.bat'
readme_name = 'README_EN.txt'
# Folder with icon
path_fred_doc = os.path.join('share', 'fred-client')
def replace_patterns(body, names):
for varname in names:
body = re.sub(varname, os.path.join(config_root, globals().get(varname)), body, 1)
return body
def update_fred_config():
'Update fred config after installation'
body = open(os.path.join(config_root, config_name)).read()
# replace paths
body = replace_patterns(body, ('FRED_CLIENT_SSL_PATH', 'FRED_CLIENT_SCHEMAS_FILEMANE'))
# save changes
open(os.path.join(config_root, config_name_ini), 'w').write(body)
# Create paths for join files with desktop
desktopDir = get_special_folder_path('CSIDL_COMMON_DESKTOPDIRECTORY')
bat_file_path = os.path.join(distutils.sysconfig.PREFIX, 'Scripts', bat_file)
# Create BAT file
open(bat_file_path, 'w').write('"%s" -i "%s"\n' % (os.path.join(distutils.sysconfig.PREFIX, 'python.exe'), script_name))
# convert LF to CR/LF be cause of the MS Windows common end of lines
for name in (readme_name, 'README_CS.txt'):
pathfile = os.path.join(distutils.sysconfig.PREFIX, path_fred_doc, name)
body = open(pathfile, 'r').read()
open(pathfile, 'w').write(body)
# Shortcut to the BAT with the main console script on the desktop
create_shortcut(
bat_file_path,
'Fred Client Console %s' % fred_version,
os.path.join(desktopDir, '%s.lnk' % script_name),
'',
os.path.join(distutils.sysconfig.PREFIX, 'Scripts'),
os.path.join(distutils.sysconfig.PREFIX, path_fred_doc, 'niccz_console.ico'))
## Shortcut to the HOWTO on the desktop
#create_shortcut(
# os.path.join(distutils.sysconfig.PREFIX, path_fred_doc, help_name),
# 'How to configure',
# os.path.join(desktopDir, '%s.lnk'%help_name),
# '', '',
# os.path.join(distutils.sysconfig.PREFIX, path_fred_doc, 'help.ico'))
# Shortcut to the configuration file on the desktop
create_shortcut(
os.path.join(sys.prefix, 'etc', 'fred', config_name_ini),
'Fred Client configuration file',
os.path.join(desktopDir, '%s.lnk' % config_name_ini),
'', '',
os.path.join(distutils.sysconfig.PREFIX, path_fred_doc, 'configure.ico'))
# Shortcut to the README on the desktop
create_shortcut(
os.path.join(distutils.sysconfig.PREFIX, path_fred_doc, readme_name),
'Fred README',
os.path.join(desktopDir, '%s.lnk' % readme_name),
'', '',
os.path.join(distutils.sysconfig.PREFIX, path_fred_doc, 'help.ico'))
update_fred_config()