1 | # Note: This script should be moved the upper folder to run properly. |
---|
2 | # Script for linux to setup all SansView internal packages (Not on sansview itself) |
---|
3 | # |
---|
4 | # Usage: |
---|
5 | # python setup_all.py |
---|
6 | |
---|
7 | import os |
---|
8 | import sys |
---|
9 | import shutil |
---|
10 | import logging |
---|
11 | |
---|
12 | # Installation folder |
---|
13 | import time |
---|
14 | timestamp = int(time.time()) |
---|
15 | CWD = os.getcwd() |
---|
16 | |
---|
17 | # On Windows, the python executable is not always on the path. |
---|
18 | # Use its most frequent location as the default. |
---|
19 | if sys.platform == 'win32': |
---|
20 | PYTHON = "c:\python25\python" |
---|
21 | |
---|
22 | else: |
---|
23 | PYTHON = 'python' |
---|
24 | |
---|
25 | |
---|
26 | def check_system(): |
---|
27 | """ |
---|
28 | Checks that the system has the necessary modules. |
---|
29 | """ |
---|
30 | is_ok = True |
---|
31 | msg = '' |
---|
32 | try: |
---|
33 | import wx |
---|
34 | if not wx.__version__.count('2.8.11') and \ |
---|
35 | not wx.__version__.count('2.8.12'): |
---|
36 | mesg = "wx: Recommending version 2.8.11 or 2.8.12" |
---|
37 | msg += mesg + "\n" |
---|
38 | print mesg |
---|
39 | except: |
---|
40 | is_ok = False |
---|
41 | mesg = "Error: wxpython 2.8.11 (12) missing" |
---|
42 | msg += mesg + "\n" |
---|
43 | print mesg |
---|
44 | logging.error("wxpython missing") |
---|
45 | |
---|
46 | try: |
---|
47 | import matplotlib |
---|
48 | if not matplotlib.__version__.count('0.99.0') and \ |
---|
49 | not matplotlib.__version__.count('0.99.1'): |
---|
50 | mesg = "matplotlib: Recommending version 0.99.0 or 0.99.1" |
---|
51 | msg += mesg + "\n" |
---|
52 | print mesg |
---|
53 | except: |
---|
54 | is_ok = False |
---|
55 | mesg = "Error: matplotlib 0.99.0 (1) missing" |
---|
56 | msg += mesg + "\n" |
---|
57 | print mesg |
---|
58 | logging.error("matplotlib missing") |
---|
59 | |
---|
60 | try: |
---|
61 | import numpy |
---|
62 | if not numpy.__version__.count('1.4.1'): |
---|
63 | mesg = "numpy: Recommending version 1.4.1" |
---|
64 | msg += mesg + "\n" |
---|
65 | print mesg |
---|
66 | except: |
---|
67 | is_ok = False |
---|
68 | mesg = "Error: numpy 1.4.1 missing" |
---|
69 | msg += mesg + "\n" |
---|
70 | print mesg |
---|
71 | logging.error("numpy missing") |
---|
72 | |
---|
73 | try: |
---|
74 | import scipy |
---|
75 | if not scipy.__version__.count('0.7.2'): |
---|
76 | mesg = "scipy: Recommending version 0.7.2" |
---|
77 | msg += mesg + "\n" |
---|
78 | print mesg |
---|
79 | except: |
---|
80 | is_ok = False |
---|
81 | mesg = "Error: scipy 0.7.2 missing" |
---|
82 | msg += mesg + "\n" |
---|
83 | print mesg |
---|
84 | logging.error("scipy missing") |
---|
85 | |
---|
86 | try: |
---|
87 | import periodictable |
---|
88 | if not periodictable.__version__.count('1.3.0'): |
---|
89 | mesg = "periodictable: Recommending version 1.3.0" |
---|
90 | msg += mesg + "\n" |
---|
91 | print mesg |
---|
92 | except: |
---|
93 | print "Trying to install perodic table..." |
---|
94 | try: |
---|
95 | os.system("easy_install periodictable") |
---|
96 | print "installed periodictable" |
---|
97 | except: |
---|
98 | is_ok = False |
---|
99 | mesg = "Error: periodictable missing" |
---|
100 | msg += mesg + "\n" |
---|
101 | print "easy_install periodictable failed" |
---|
102 | logging.error("periodictable missing") |
---|
103 | |
---|
104 | |
---|
105 | try: |
---|
106 | if sys.platform.count("win32")> 0: |
---|
107 | from wx.lib.pdfwin import PDFWindow |
---|
108 | except: |
---|
109 | is_ok = False |
---|
110 | mesg = "comtypes missing" |
---|
111 | msg += mesg + "\n" |
---|
112 | print mesg |
---|
113 | logging.error("comtypes missing") |
---|
114 | |
---|
115 | try: |
---|
116 | if sys.platform.count("win32")> 0: |
---|
117 | import win32com |
---|
118 | except: |
---|
119 | is_ok = False |
---|
120 | mesg = "pywin32 missing" |
---|
121 | msg += mesg + "\n" |
---|
122 | print mesg |
---|
123 | logging.error("pywin32 missing") |
---|
124 | |
---|
125 | try: |
---|
126 | import pyparsing |
---|
127 | except: |
---|
128 | try: |
---|
129 | os.system("easy_install pyparsing") |
---|
130 | print "installed pyparsing" |
---|
131 | except: |
---|
132 | is_ok = False |
---|
133 | mesg = "pyparsing missing" |
---|
134 | msg += mesg + "\n" |
---|
135 | print mesg |
---|
136 | print "easy_install pyparsing failed" |
---|
137 | logging.error("pyparsing missing") |
---|
138 | |
---|
139 | if os.system("gcc -dumpversion")==1: |
---|
140 | is_ok = False |
---|
141 | mesg = "missing mingw/gcc" |
---|
142 | msg += mesg + "\n" |
---|
143 | print mesg |
---|
144 | logging.error("missing mingw/gcc") |
---|
145 | |
---|
146 | return is_ok, msg |
---|
147 | |
---|
148 | |
---|
149 | def install_pkg(setup_dir): |
---|
150 | """ |
---|
151 | Check a package out and install it |
---|
152 | |
---|
153 | @param install_dir: directory to put the code in |
---|
154 | @param setup_dir: relative location of the setup.py script |
---|
155 | @param url: URL of the SVN repo |
---|
156 | """ |
---|
157 | #print "PYTHON, LIB_FOLDER=====",PYTHON |
---|
158 | #logging.info("Installing Pakages" ) |
---|
159 | try: |
---|
160 | os.chdir(setup_dir) |
---|
161 | os.system("%s setup.py install" % PYTHON) |
---|
162 | print "Installation %s successful.." % setup_dir |
---|
163 | except: |
---|
164 | logging.error("Installation failed on %s"% setup_dir) |
---|
165 | logging.error(sys.exc_value) |
---|
166 | raw_input("Press enter to continue\n") |
---|
167 | sys.exit() |
---|
168 | |
---|
169 | def install(release=False): |
---|
170 | """ |
---|
171 | Check the SansView code out |
---|
172 | """ |
---|
173 | wd = os.getcwd() |
---|
174 | os.chdir(wd) |
---|
175 | for folder in os.listdir(wd): |
---|
176 | if os.path.isdir(os.path.join(wd, folder)): |
---|
177 | if folder.count('sansview') > 0: |
---|
178 | setup_dir = folder |
---|
179 | try: |
---|
180 | install_pkg(folder) |
---|
181 | except: |
---|
182 | pass |
---|
183 | os.chdir(wd) |
---|
184 | |
---|
185 | |
---|
186 | # run sansview |
---|
187 | try: |
---|
188 | os.chdir(setup_dir) |
---|
189 | os.system("%s sansview.py" % PYTHON) |
---|
190 | except: |
---|
191 | pass |
---|
192 | |
---|
193 | # try to make the sansview dir writable to everyone |
---|
194 | os.chdir(wd) |
---|
195 | try: |
---|
196 | if sys.platform == 'darwin': |
---|
197 | os.system("chmod -R g+w %s"% setup_dir) |
---|
198 | else: |
---|
199 | os.system("chmod 777 -R %s"% setup_dir) |
---|
200 | except: |
---|
201 | print "Could not give a permission to everyone for %s." % setup_dir |
---|
202 | |
---|
203 | |
---|
204 | def prepare(wipeout = True): |
---|
205 | """ |
---|
206 | Prepare the build |
---|
207 | |
---|
208 | @param wipeout: If True, the DANSE modules in the standard site-packages will be |
---|
209 | removed to avoid conflicts. |
---|
210 | """ |
---|
211 | # Remove existing libraries |
---|
212 | if wipeout == True: |
---|
213 | |
---|
214 | logging.info("Deleting DANSES modules in site-packages") |
---|
215 | from distutils.sysconfig import get_python_lib |
---|
216 | libdir = get_python_lib() |
---|
217 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
218 | os.path.join(libdir, 'data_util'), |
---|
219 | os.path.join(libdir, 'park'), |
---|
220 | os.path.join(libdir, 'sans'), |
---|
221 | ] |
---|
222 | for d in old_dirs: |
---|
223 | if os.path.isdir(d): |
---|
224 | shutil.rmtree(d) |
---|
225 | |
---|
226 | |
---|
227 | if __name__ == "__main__": |
---|
228 | |
---|
229 | is_ok, _msg = check_system() |
---|
230 | if is_ok: |
---|
231 | if len(sys.argv)==1: |
---|
232 | # If there is no argument, build the installer |
---|
233 | sys.argv.append("-t") |
---|
234 | |
---|
235 | if len(sys.argv)>1: |
---|
236 | # Help |
---|
237 | if sys.argv[1]=="-h": |
---|
238 | print "Usage:" |
---|
239 | print " python build_sansview [command]\n" |
---|
240 | print "[command] can be any of the following:" |
---|
241 | print " -h: lists the command line options" |
---|
242 | print " -r: Builds a SansView using the released modules" |
---|
243 | print " -t: Builds SansView from the trunk" |
---|
244 | |
---|
245 | else: |
---|
246 | logging.info("Build script for SansView") |
---|
247 | print "Warning: This script will delete the previous SansView packages..." |
---|
248 | prepare() |
---|
249 | # Check the command line argument |
---|
250 | if sys.argv[1]=="-t": |
---|
251 | logging.info("Building from trunk version") |
---|
252 | install() |
---|
253 | else: |
---|
254 | logging.info("Building from release version") |
---|
255 | install(True) |
---|
256 | |
---|
257 | |
---|
258 | print _msg |
---|
259 | raw_input("Press enter to continue\n") |
---|
260 | |
---|
261 | else: |
---|
262 | print _msg |
---|
263 | raw_input("Press enter and install the missing packages before re-run this scripts.\n") |
---|