-
Notifications
You must be signed in to change notification settings - Fork 8
/
nMOLDYN_win32_postinstall.py
145 lines (105 loc) · 4.94 KB
/
nMOLDYN_win32_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Add Python DLL directory to PATH
from distutils.version import LooseVersion
import os
import shutil
import sys
import time
import nMOLDYN
def apply_patch_for_scientific_module():
"""Apply a patch for one file that is buggy in case of a win32 installation.
"""
scientific_minversion = '2.8.0'
import Scientific
scientific_version = LooseVersion(vstring = Scientific.__version__)
# Versions > 2.8.0 should not need the patch.
if scientific_version > LooseVersion(vstring = scientific_minversion): return
# The path to the ScientificPythin installation.
scientific_path = Scientific.__path__[0]
# The path to its DistributedComputing path.
dir = os.path.join(scientific_path, 'DistributedComputing')
# The file that will have to be replaced.
src_file = os.path.join(dir, 'MasterSlave.py')
# It will be copy first under this name.
dst_file = os.path.join(dir, 'MasterSlave_copy_%s.py' % time.strftime("%a_%d_%b_%Y", time.localtime()))
# The copy is done.
shutil.copyfile(src_file, dst_file)
# Some info.
print 'The file %s was copied to %s before applying the patch.' % (src_file, dst_file)
# The path to the patch.
patch_file = os.path.join(nMOLDYN.__path__[0],'Patches','MasterSlave_patch.py')
# Try to aply the patch by replacing the MasterSlave.py file by the patch.
try:
shutil.copyfile(patch_file, src_file)
# If this can not be done, this might be due to a permission problem.
except:
print 'The patch %s could not be applied. Perhaps a permission problem.'
# If it is OK, print some info.
else:
print 'The patch %s was successfully applied.' % patch_file
def install():
"""Will performes post-installation opeartions.
"""
# First apply the ScientifcPython patch to make PyRo work on Windows.
apply_patch_for_scientific_module()
# The path to the nMOLDYN icon.
launch_ico_path = os.path.join(nMOLDYN.__path__[0],'win32_files','nMOLDYN_Logo.ico')
# The path to the nMOLDYN uninstall icon.
uninstall_ico_path = os.path.join(nMOLDYN.__path__[0],'win32_files','uninstall_nMOLDYN.ico')
# The path to the nMOLDYN starting script.
script_path = os.path.join(sys.prefix, 'Scripts', 'nMOLDYNStart.py')
# The path to the nMOLDYN uninstall script.
uninstall_script_path = os.path.join(sys.prefix, 'Scripts', 'nMOLDYN_win32_uninstall.py')
try:
desktop_path = get_special_folder_path("CSIDL_COMMON_DESKTOPDIRECTORY")
except OSError:
desktop_path = get_special_folder_path("CSIDL_DESKTOPDIRECTORY")
print 'Desktop path created in %s' % desktop_path
desktop_shortcut = os.path.join(desktop_path, 'nMOLDYN 3.lnk')
# Creates the desktop shortcut.
create_shortcut(script_path,\
'This is the shortcut for the nMOLDYN 3 launcher',\
desktop_shortcut,\
'',\
'',\
launch_ico_path,\
0)
# Register that path with the uninstaller, so that it will be removed when the distribution is uninstalled.
file_created(desktop_shortcut)
try:
start_path = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
except OSError:
start_path = get_special_folder_path("CSIDL_PROGRAMS")
print 'Start path created in %s' % start_path
programs_path = os.path.join(start_path, "nMOLDYN 3")
if not os.path.exists(programs_path):
try :
os.mkdir(programs_path)
except OSError:
pass
# Register that directory with the uninstaller, so that it will be removed when the distribution is uninstalled.
directory_created(programs_path)
start_shortcut = os.path.join(programs_path, 'nMOLDYN 3.lnk')
# Creates the Start Menu launching shortcut
create_shortcut(script_path,\
'nMOLDYN 3 launcher',\
start_shortcut,\
'',\
'',\
launch_ico_path,\
0)
# Register that path with the uninstaller, so that it will be removed when the distribution is uninstalled.
file_created(start_shortcut)
start_uninstall_shortcut = os.path.join(programs_path, 'uninstall nMOLDYN 3.lnk')
# Creates the Start Menu uninstall shortcut.
create_shortcut(uninstall_script_path,\
'Uninstall nMOLDYN 3',\
start_uninstall_shortcut,\
'',\
'',\
uninstall_ico_path,\
0)
# Register that path with the uninstaller, so that it will be removed when the distribution is uninstalled.
file_created(start_uninstall_shortcut)
if __name__=='__main__':
if len(sys.argv) == 2 and sys.argv[1] == '-install':
install()