1 | #!/usr/bin/env python |
---|
2 | # Installs GSAS-II from network using subversion and creates platform-specific shortcuts. |
---|
3 | # works for Mac & Linux & Windows |
---|
4 | from __future__ import division, print_function |
---|
5 | import os, stat, sys, platform, subprocess, datetime |
---|
6 | |
---|
7 | version = "$Id: bootstrap.py 4645 2020-11-04 00:19:08Z toby $" |
---|
8 | g2home = 'https://subversion.xray.aps.anl.gov/pyGSAS/' |
---|
9 | path2GSAS2 = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) |
---|
10 | |
---|
11 | skipInstallChecks = False # if set to True, continue installation even if current Python lacks packages and |
---|
12 | # skips platform-dependent installation steps |
---|
13 | skipDownloadSteps = False # if False, svn is used to download GSAS-II files and binaries |
---|
14 | skipProxy = False # if False then the script creates a prompt asking for proxy info |
---|
15 | showWXerror = False # if True, errors are shown in wxPython windows (used on Windows only) |
---|
16 | help = False # if True, a help message is shown |
---|
17 | allBinaries = False # if True, causes all binaries to be installed |
---|
18 | binaryVersion=None # if specified, gives a specific numpy version to use (such as 1.18) |
---|
19 | # for selecting a set of binaries to use |
---|
20 | numpyVersion=None |
---|
21 | |
---|
22 | for a in sys.argv[1:]: |
---|
23 | if 'noinstall' in a.lower(): |
---|
24 | skipInstallChecks = True |
---|
25 | if sys.platform.startswith('win'): showWXerror = True |
---|
26 | elif 'nonet' in a.lower(): |
---|
27 | skipDownloadSteps = True |
---|
28 | skipProxy = True |
---|
29 | elif 'noproxy' in a.lower(): |
---|
30 | skipProxy = True |
---|
31 | elif 'allbin' in a.lower() or 'server' in a.lower(): |
---|
32 | allBinaries = True |
---|
33 | elif 'binary' in a.lower(): |
---|
34 | numpyVersion = a.split('=')[1] |
---|
35 | skipInstallChecks = True |
---|
36 | if sys.platform.startswith('win'): showWXerror = True |
---|
37 | skipProxy = True |
---|
38 | else: |
---|
39 | help = True |
---|
40 | if 'help' in a.lower(): |
---|
41 | help = True |
---|
42 | |
---|
43 | if help: |
---|
44 | print(''' |
---|
45 | bootstrap.py options: |
---|
46 | |
---|
47 | --noinstall skip post-install, such as creating run shortcuts, turns on |
---|
48 | wxpython error display in Windows |
---|
49 | --noproxy do not ask for proxy information |
---|
50 | --server load all binary versions |
---|
51 | --allbin load all binary versions (same as --server) |
---|
52 | --help this message |
---|
53 | --nonet skip steps requiring internet |
---|
54 | --binary=ver specifies a specific numpy binary directory to use (such as |
---|
55 | --binary=1.18); turns on --noinstall and --noproxy |
---|
56 | ''') |
---|
57 | sys.exit() |
---|
58 | |
---|
59 | now = str(datetime.datetime.now()) |
---|
60 | print('Running bootstrap from {} at {}\n\tId: {}'.format(path2GSAS2,now,version)) |
---|
61 | print ("Python: %s"%sys.version.split()[0]) |
---|
62 | try: |
---|
63 | import numpy as np |
---|
64 | print ("numpy: %s"%np.__version__) |
---|
65 | except: |
---|
66 | pass |
---|
67 | fp = open(os.path.join(path2GSAS2,'bootstrap.log'),'a') |
---|
68 | fp.write('Running bootstrap from {} at {}\n\tId: {}\n'.format(path2GSAS2,now,version)) |
---|
69 | fp.close() |
---|
70 | |
---|
71 | ################################################################################ |
---|
72 | ################################################################################ |
---|
73 | def BailOut(msg): |
---|
74 | '''Exit with an error message. Use a GUI to show the error when |
---|
75 | showWXerror == True (on windows when --noinstall is specified) |
---|
76 | ''' |
---|
77 | print(msg) |
---|
78 | if showWXerror: |
---|
79 | import wx |
---|
80 | app = wx.App() |
---|
81 | app.MainLoop() |
---|
82 | dlg = wx.MessageDialog(None,msg,'GSAS-II installation error', |
---|
83 | wx.OK | wx.ICON_ERROR | wx.STAY_ON_TOP) |
---|
84 | dlg.Raise() |
---|
85 | dlg.ShowModal() |
---|
86 | dlg.Destroy() |
---|
87 | else: |
---|
88 | print("Recreate error this using command:") |
---|
89 | print(" {} {} {}".format( |
---|
90 | os.path.abspath(sys.executable), |
---|
91 | os.path.abspath(os.path.expanduser(__file__)), |
---|
92 | ' '.join(sys.argv[1:]), |
---|
93 | ),file=sys.stderr) |
---|
94 | print("\nBOOTSTRAP WARNING: ",file=sys.stderr) |
---|
95 | for line in msg.split('\n'): |
---|
96 | print(line,file=sys.stderr) |
---|
97 | sys.exit() |
---|
98 | |
---|
99 | def GetConfigValue(*args): return True |
---|
100 | # routines copied from GSASIIpath.py |
---|
101 | proxycmds = [] |
---|
102 | 'Used to hold proxy information for subversion, set if needed in whichsvn' |
---|
103 | svnLocCache = None |
---|
104 | 'Cached location of svn to avoid multiple searches for it' |
---|
105 | |
---|
106 | def MakeByte2str(arg): |
---|
107 | '''Convert output from subprocess pipes (bytes) to str (unicode) in Python 3. |
---|
108 | In Python 2: Leaves output alone (already str). |
---|
109 | Leaves stuff of other types alone (including unicode in Py2) |
---|
110 | Works recursively for string-like stuff in nested loops and tuples. |
---|
111 | |
---|
112 | typical use:: |
---|
113 | |
---|
114 | out = MakeByte2str(out) |
---|
115 | |
---|
116 | or:: |
---|
117 | |
---|
118 | out,err = MakeByte2str(s.communicate()) |
---|
119 | |
---|
120 | ''' |
---|
121 | if isinstance(arg,str): return arg |
---|
122 | if isinstance(arg,bytes): |
---|
123 | try: |
---|
124 | return arg.decode() |
---|
125 | except: |
---|
126 | print('Decode error') |
---|
127 | return arg |
---|
128 | if isinstance(arg,list): |
---|
129 | return [MakeByte2str(i) for i in arg] |
---|
130 | if isinstance(arg,tuple): |
---|
131 | return tuple([MakeByte2str(i) for i in arg]) |
---|
132 | return arg |
---|
133 | |
---|
134 | def getsvnProxy(): |
---|
135 | '''Loads a proxy for subversion from the file created by bootstrap.py |
---|
136 | ''' |
---|
137 | global proxycmds |
---|
138 | proxycmds = [] |
---|
139 | proxyinfo = os.path.join(os.path.expanduser('~/.G2local/'),"proxyinfo.txt") |
---|
140 | if not os.path.exists(proxyinfo): |
---|
141 | proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt") |
---|
142 | if not os.path.exists(proxyinfo): |
---|
143 | return '','','' |
---|
144 | fp = open(proxyinfo,'r') |
---|
145 | host = fp.readline().strip() |
---|
146 | # allow file to begin with comments |
---|
147 | while host.startswith('#'): |
---|
148 | host = fp.readline().strip() |
---|
149 | port = fp.readline().strip() |
---|
150 | etc = [] |
---|
151 | line = fp.readline() |
---|
152 | while line: |
---|
153 | etc.append(line.strip()) |
---|
154 | line = fp.readline() |
---|
155 | fp.close() |
---|
156 | setsvnProxy(host,port,etc) |
---|
157 | return host,port,etc |
---|
158 | |
---|
159 | def setsvnProxy(host,port,etc=[]): |
---|
160 | '''Sets the svn commands needed to use a proxy |
---|
161 | ''' |
---|
162 | global proxycmds |
---|
163 | proxycmds = [] |
---|
164 | host = host.strip() |
---|
165 | port = port.strip() |
---|
166 | if host: |
---|
167 | proxycmds.append('--config-option') |
---|
168 | proxycmds.append('servers:global:http-proxy-host='+host) |
---|
169 | if port: |
---|
170 | proxycmds.append('--config-option') |
---|
171 | proxycmds.append('servers:global:http-proxy-port='+port) |
---|
172 | for item in etc: |
---|
173 | proxycmds.append(item) |
---|
174 | |
---|
175 | def whichsvn(): |
---|
176 | '''Returns a path to the subversion exe file, if any is found. |
---|
177 | Searches the current path after adding likely places where GSAS-II |
---|
178 | might install svn. |
---|
179 | |
---|
180 | :returns: None if svn is not found or an absolute path to the subversion |
---|
181 | executable file. |
---|
182 | ''' |
---|
183 | # use a previosuly cached svn location |
---|
184 | global svnLocCache |
---|
185 | if svnLocCache: return svnLocCache |
---|
186 | # prepare to find svn |
---|
187 | is_exe = lambda fpath: os.path.isfile(fpath) and os.access(fpath, os.X_OK) |
---|
188 | svnprog = 'svn' |
---|
189 | if sys.platform.startswith('win'): svnprog += '.exe' |
---|
190 | host,port,etc = getsvnProxy() |
---|
191 | if GetConfigValue('debug') and host: |
---|
192 | print('DBG_Using proxy host {} port {}'.format(host,port)) |
---|
193 | # add likely places to find subversion when installed with GSAS-II |
---|
194 | pathlist = os.environ["PATH"].split(os.pathsep) |
---|
195 | pathlist.insert(0,os.path.split(sys.executable)[0]) |
---|
196 | pathlist.insert(1,path2GSAS2) |
---|
197 | for rpt in ('..','bin'),('..','Library','bin'),('svn','bin'),('svn',),('.'): |
---|
198 | pt = os.path.normpath(os.path.join(path2GSAS2,*rpt)) |
---|
199 | if os.path.exists(pt): |
---|
200 | pathlist.insert(0,pt) |
---|
201 | # search path for svn or svn.exe |
---|
202 | for path in pathlist: |
---|
203 | exe_file = os.path.join(path, svnprog) |
---|
204 | if is_exe(exe_file): |
---|
205 | try: |
---|
206 | p = subprocess.Popen([exe_file,'help'],stdout=subprocess.PIPE) |
---|
207 | res = p.stdout.read() |
---|
208 | p.communicate() |
---|
209 | svnLocCache = os.path.abspath(exe_file) |
---|
210 | return svnLocCache |
---|
211 | except: |
---|
212 | pass |
---|
213 | svnLocCache = None |
---|
214 | |
---|
215 | def svnVersion(svn=None): |
---|
216 | '''Get the version number of the current subversion executable |
---|
217 | |
---|
218 | :returns: a string with a version number such as "1.6.6" or None if |
---|
219 | subversion is not found. |
---|
220 | |
---|
221 | ''' |
---|
222 | if not svn: svn = whichsvn() |
---|
223 | if not svn: return |
---|
224 | |
---|
225 | cmd = [svn,'--version','--quiet'] |
---|
226 | s = subprocess.Popen(cmd, |
---|
227 | stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
228 | out,err = MakeByte2str(s.communicate()) |
---|
229 | if err: |
---|
230 | print ('subversion error!\nout=%s'%out) |
---|
231 | print ('err=%s'%err) |
---|
232 | s = '\nsvn command: ' |
---|
233 | for i in cmd: s += i + ' ' |
---|
234 | print(s) |
---|
235 | return None |
---|
236 | return out.strip() |
---|
237 | |
---|
238 | def svnVersionNumber(svn=None): |
---|
239 | '''Get the version number of the current subversion executable |
---|
240 | |
---|
241 | :returns: a fractional version number such as 1.6 or None if |
---|
242 | subversion is not found. |
---|
243 | |
---|
244 | ''' |
---|
245 | ver = svnVersion(svn) |
---|
246 | if not ver: return |
---|
247 | M,m = ver.split('.')[:2] |
---|
248 | return int(M)+int(m)/10. |
---|
249 | |
---|
250 | def showsvncmd(cmd): |
---|
251 | s = '\nsvn command: ' |
---|
252 | for i in cmd: s += i + ' ' |
---|
253 | print(s) |
---|
254 | |
---|
255 | def svnChecksumPatch(svn,fpath,verstr): |
---|
256 | '''This performs a fix when svn cannot finish an update because of |
---|
257 | a Checksum mismatch error. This seems to be happening on OS X for |
---|
258 | unclear reasons. |
---|
259 | ''' |
---|
260 | print('\nAttempting patch for svn Checksum mismatch error\n') |
---|
261 | cmd = [svn,'cleanup',fpath] |
---|
262 | showsvncmd(cmd) |
---|
263 | s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
264 | out,err = MakeByte2str(s.communicate()) |
---|
265 | #if err: print('error=',err) |
---|
266 | cmd = ['svn','update','--set-depth','empty', |
---|
267 | os.path.join(fpath,'bindist')] |
---|
268 | showsvncmd(cmd) |
---|
269 | s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
270 | out,err = MakeByte2str(s.communicate()) |
---|
271 | #if err: print('error=',err) |
---|
272 | try: |
---|
273 | import GSASIIpath |
---|
274 | print('import of GSASIIpath completed') |
---|
275 | except Exception as err: |
---|
276 | msg = 'Failed with import of GSASIIpath. This is unexpected.' |
---|
277 | msg += '\nGSAS-II will not run without correcting this. Contact toby@anl.gov' |
---|
278 | BailOut(msg) |
---|
279 | cmd = ['svn','switch',g2home+'/trunk/bindist', |
---|
280 | os.path.join(fpath,'bindist'), |
---|
281 | '--non-interactive', '--trust-server-cert', '--accept', |
---|
282 | 'theirs-conflict', '--force', '-rHEAD', '--ignore-ancestry'] |
---|
283 | showsvncmd(cmd) |
---|
284 | s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
285 | out,err = MakeByte2str(s.communicate()) |
---|
286 | GSASIIpath.DownloadG2Binaries(g2home,verbose=True) |
---|
287 | cmd = ['svn','update','--set-depth','infinity', |
---|
288 | os.path.join(fpath,'bindist')] |
---|
289 | showsvncmd(cmd) |
---|
290 | s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
291 | out,err = MakeByte2str(s.communicate()) |
---|
292 | #if err: print('error=',err) |
---|
293 | cmd = [svn,'update',fpath,verstr, |
---|
294 | '--non-interactive', |
---|
295 | '--accept','theirs-conflict','--force'] |
---|
296 | if svnVersionNumber() >= 1.6: |
---|
297 | cmd += ['--trust-server-cert'] |
---|
298 | if proxycmds: cmd += proxycmds |
---|
299 | #print(cmd) |
---|
300 | showsvncmd(cmd) |
---|
301 | s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
302 | out,err = MakeByte2str(s.communicate()) |
---|
303 | #if err: print('error=',err) |
---|
304 | return err |
---|
305 | |
---|
306 | ################################################################################ |
---|
307 | ################################################################################ |
---|
308 | print(70*'*') |
---|
309 | #testing for incorrect locale code' |
---|
310 | try: |
---|
311 | import locale |
---|
312 | locale.getdefaultlocale() |
---|
313 | except ValueError: |
---|
314 | print('Your location is not set properly. This causes problems for matplotlib') |
---|
315 | print(' (see https://github.com/matplotlib/matplotlib/issues/5420.)') |
---|
316 | print('Will try to bypass problem by setting LC_ALL to en_US.UTF-8 (US English)') |
---|
317 | os.environ['LC_ALL'] = 'en_US.UTF-8' |
---|
318 | locale.getdefaultlocale() |
---|
319 | print('Preloading matplotlib to build fonts...') |
---|
320 | try: |
---|
321 | import matplotlib |
---|
322 | except: |
---|
323 | pass |
---|
324 | print('Checking python packages...') |
---|
325 | missing = [] |
---|
326 | for pkg in ['numpy','scipy','matplotlib','wx','OpenGL',]: |
---|
327 | try: |
---|
328 | exec('import '+pkg) |
---|
329 | except: |
---|
330 | missing.append(pkg) |
---|
331 | |
---|
332 | if missing and not skipInstallChecks: |
---|
333 | msg = """Sorry, this version of Python cannot be used |
---|
334 | for GSAS-II. It is missing the following package(s): |
---|
335 | \t""" |
---|
336 | for pkg in missing: msg += " "+pkg |
---|
337 | msg += "\nPlease install these package(s) and try running bootstrap.py again." |
---|
338 | #print("Showing first error: ") |
---|
339 | #for pkg in ['numpy','scipy','matplotlib','wx','OpenGL',]: |
---|
340 | # exec('import '+pkg) |
---|
341 | BailOut(msg) |
---|
342 | |
---|
343 | if not skipDownloadSteps: |
---|
344 | host = None |
---|
345 | port = '80' |
---|
346 | print('\nChecking for subversion...') |
---|
347 | svn = whichsvn() # resets host & port if proxyinfo.txt is found |
---|
348 | if not svn: |
---|
349 | msg ="Sorry, subversion (svn) could not be found on your system." |
---|
350 | msg += "\nPlease install this or place in path and rerun this." |
---|
351 | BailOut(msg) |
---|
352 | else: |
---|
353 | print(' found svn image: '+svn) |
---|
354 | |
---|
355 | #if install_with_easyinstall: |
---|
356 | # print('\nInstalling PyOpenGL. Lots of warnings will follow... ') |
---|
357 | # install_with_easyinstall('PyOpenGl') |
---|
358 | # print('done.') |
---|
359 | |
---|
360 | print('Ready to bootstrap GSAS-II from repository\n\t'+g2home+'\nto '+path2GSAS2) |
---|
361 | proxycmds = [] |
---|
362 | host,port,etc = getsvnProxy() |
---|
363 | if sys.version_info[0] == 2: |
---|
364 | getinput = raw_input |
---|
365 | else: |
---|
366 | getinput = input |
---|
367 | |
---|
368 | # get proxy setting from environment variable |
---|
369 | key = None |
---|
370 | for i in os.environ.keys(): |
---|
371 | if 'https_proxy' == i.lower(): |
---|
372 | key = i |
---|
373 | break |
---|
374 | else: |
---|
375 | for i in os.environ.keys(): |
---|
376 | if 'http_proxy' == i.lower(): |
---|
377 | key = i |
---|
378 | break |
---|
379 | val = '' |
---|
380 | if key: |
---|
381 | val = os.environ[key].strip() |
---|
382 | if val: |
---|
383 | if val[-1] == '/': |
---|
384 | val = val[:-1] |
---|
385 | if len(val.split(':')) > 2: |
---|
386 | host = ':'.join(val.split(':')[:-1]) |
---|
387 | port = val.split(':')[-1] |
---|
388 | else: |
---|
389 | host = ':'.join(val.split(':')[:-1]) |
---|
390 | port = val.split(':')[-1] |
---|
391 | |
---|
392 | # get proxy from user, if terminal available |
---|
393 | try: |
---|
394 | if skipProxy: |
---|
395 | host = "" |
---|
396 | elif host: |
---|
397 | print('\n'+75*'*') |
---|
398 | ans = getinput("Enter the proxy address (type none to remove) ["+host+"]: ").strip() |
---|
399 | if ans.lower() == "none": host = "" |
---|
400 | else: |
---|
401 | ans = getinput("Enter your proxy address [none needed]: ").strip() |
---|
402 | if ans: host = ans |
---|
403 | if host: |
---|
404 | ans = getinput("Enter the proxy port ["+port+"]: ").strip() |
---|
405 | if ans == "": ans=port |
---|
406 | port = ans |
---|
407 | print('If your site needs additional svn commands (such as \n\t', |
---|
408 | '--config-option servers:global:http-proxy-username=*account*','\n\t', |
---|
409 | '--config-option servers:global:http-proxy-password=*password*', |
---|
410 | '\nenter them now:') |
---|
411 | if etc: |
---|
412 | prevetc = ' '.join(etc) |
---|
413 | print('\nDefault for next input is "{}"'.format(prevetc)) |
---|
414 | prompt = "Enter additional svn options (if any) [use previous]: " |
---|
415 | else: |
---|
416 | prompt = "Enter additional svn options (if any) [none]: " |
---|
417 | ans = 'start' |
---|
418 | etcstr = '' |
---|
419 | while ans: |
---|
420 | ans = getinput(prompt).strip() |
---|
421 | prompt = "more svn options (if any): " |
---|
422 | if etcstr: etcstr += ' ' |
---|
423 | etcstr += ans |
---|
424 | if etcstr.strip(): |
---|
425 | etc = etcstr.split() |
---|
426 | except EOFError: |
---|
427 | host = "" |
---|
428 | port = "" |
---|
429 | etc = [] |
---|
430 | setsvnProxy(host,port,etc) |
---|
431 | # delete old proxy files |
---|
432 | localproxy = os.path.join(os.path.expanduser('~/.G2local/'),"proxyinfo.txt") |
---|
433 | for proxyinfo in localproxy,os.path.join(path2GSAS2,"proxyinfo.txt"): |
---|
434 | if os.path.exists(proxyinfo): |
---|
435 | try: |
---|
436 | os.remove(proxyinfo) |
---|
437 | print('Deleted file {}'.format(proxyinfo)) |
---|
438 | except: |
---|
439 | pass |
---|
440 | if host: |
---|
441 | try: |
---|
442 | fp = open(proxyinfo,'w') |
---|
443 | except: |
---|
444 | fp = open(localproxy,'w') |
---|
445 | proxyinfo = localproxy |
---|
446 | try: |
---|
447 | fp.write(host.strip()+'\n') |
---|
448 | fp.write(port.strip()+'\n') |
---|
449 | for i in etc: |
---|
450 | if i.strip(): |
---|
451 | fp.write(i.strip()+'\n') |
---|
452 | fp.close() |
---|
453 | msg = 'Proxy info written: {} port {} etc {}\n'.format(host,port,etc) |
---|
454 | print(msg) |
---|
455 | fp = open(os.path.join(path2GSAS2,'bootstrap.log'),'a') |
---|
456 | fp.write(msg) |
---|
457 | fp.close() |
---|
458 | except Exception as err: |
---|
459 | print('Error writing file {}:\n{}'.format(proxyinfo,err)) |
---|
460 | |
---|
461 | if not skipDownloadSteps: |
---|
462 | # patch: switch GSAS-II location if linked to XOR server (relocated May/June 2017) |
---|
463 | cmd = [svn, 'info'] |
---|
464 | p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
465 | res,err = p.communicate() |
---|
466 | if '.xor.' in str(res): |
---|
467 | print('Switching previous install with .xor. download location to\n\thttps://subversion.xray.aps.anl.gov/pyGSAS') |
---|
468 | cmd = [svn, 'switch','--relocate','https://subversion.xor.aps.anl.gov/pyGSAS', |
---|
469 | 'https://subversion.xray.aps.anl.gov/pyGSAS'] |
---|
470 | if proxycmds: cmd += proxycmds |
---|
471 | p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
472 | res,err = p.communicate() |
---|
473 | if err: |
---|
474 | print('Please report this error to toby@anl.gov:') |
---|
475 | print(err) |
---|
476 | print(res) |
---|
477 | # patch: switch GSAS-II location if switched to 2frame version (removed August 2017) |
---|
478 | if '2frame' in str(res): |
---|
479 | print('Switching previous 2frame install to trunk\n\thttps://subversion.xray.aps.anl.gov/pyGSAS') |
---|
480 | cmd = [svn, 'switch',g2home + '/trunk',path2GSAS2, |
---|
481 | '--non-interactive','--trust-server-cert', |
---|
482 | '--accept','theirs-conflict','--force','--ignore-ancestry'] |
---|
483 | if proxycmds: cmd += proxycmds |
---|
484 | p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
485 | res,err = p.communicate() |
---|
486 | if err: |
---|
487 | print('Please report this error to toby@anl.gov:') |
---|
488 | print(err) |
---|
489 | print(res) |
---|
490 | |
---|
491 | print('\n'+75*'*') |
---|
492 | print('Now preparing to install GSAS-II') |
---|
493 | tryagain = True |
---|
494 | err = False |
---|
495 | firstPass = 0 |
---|
496 | while(tryagain): |
---|
497 | tryagain = False |
---|
498 | if err: |
---|
499 | print('Retrying after a cleanup...') |
---|
500 | cmd = [svn, 'cleanup', path2GSAS2] |
---|
501 | s = subprocess.Popen(cmd,stderr=subprocess.PIPE) |
---|
502 | out,err = MakeByte2str(s.communicate()) |
---|
503 | if err: |
---|
504 | print('subversion returned an error:') |
---|
505 | print(out) |
---|
506 | print(err) |
---|
507 | cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2, '--non-interactive', '--trust-server-cert'] |
---|
508 | if proxycmds: cmd += proxycmds |
---|
509 | msg = 'svn load command: ' |
---|
510 | for item in cmd: msg += " "+item |
---|
511 | print(msg) |
---|
512 | s = subprocess.Popen(cmd,stderr=subprocess.PIPE) |
---|
513 | print('\nsubversion output:') |
---|
514 | out,err = MakeByte2str(s.communicate()) |
---|
515 | if 'Checksum' in err: # deal with Checksum problem |
---|
516 | err = svnChecksumPatch(svn,path2GSAS2,'-rHEAD') |
---|
517 | if err: |
---|
518 | print('error from svnChecksumPatch\n\t',err) |
---|
519 | elif err: |
---|
520 | print('subversion returned an error:') |
---|
521 | print(out) |
---|
522 | print(err) |
---|
523 | if firstPass == 0: tryagain = True |
---|
524 | firstPass += 1 |
---|
525 | if err: |
---|
526 | print('Retrying with a command for older svn version...') |
---|
527 | cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2] |
---|
528 | if proxycmds: cmd += proxycmds |
---|
529 | msg = "" |
---|
530 | for item in cmd: msg += " " + item |
---|
531 | print(msg) |
---|
532 | s = subprocess.Popen(cmd,stderr=subprocess.PIPE) |
---|
533 | out,err = MakeByte2str(s.communicate()) |
---|
534 | if err: |
---|
535 | msg = 'subversion returned an error:\n' |
---|
536 | msg += err |
---|
537 | if os.path.exists(os.path.join(path2GSAS2,"makeBat.py")): |
---|
538 | msg += '\nGSAS-II appears to be installed but failed to be updated. A likely reason' |
---|
539 | msg += '\nis a network access problem. If your web browser works, but this update did' |
---|
540 | msg += '\nnot, the most common reason is you need to use a network proxy. Please' |
---|
541 | msg += '\ncheck with a network administrator or use http://www.whatismyproxy.com/' |
---|
542 | msg += '\n\nIf installing from the gsas2full dist and your computer is not connected' |
---|
543 | msg += '\nto the internet, this error message can be ignored.\n' |
---|
544 | else: |
---|
545 | # this will happen only with initial installs where all files |
---|
546 | # are to be downloaded (not gsas2full or updates) |
---|
547 | msg += '\n\n *** GSAS-II failed to be installed. A likely reason is a network access' |
---|
548 | msg += '\n *** problem, most commonly because you need to use a network proxy. Please' |
---|
549 | msg += '\n *** check with a network administrator or use http://www.whatismyproxy.com/\n' |
---|
550 | BailOut(msg) |
---|
551 | print('\n'+75*'*') |
---|
552 | |
---|
553 | # subsequent commands require GSASIIpath which better be here now, import it |
---|
554 | try: |
---|
555 | import GSASIIpath |
---|
556 | print('import of GSASIIpath completed') |
---|
557 | except Exception as err: |
---|
558 | msg = 'Failed with import of GSASIIpath. This is unexpected.' |
---|
559 | msg += '\nGSAS-II will not run without correcting this. Contact toby@anl.gov' |
---|
560 | BailOut(msg) |
---|
561 | |
---|
562 | if skipDownloadSteps: |
---|
563 | pass |
---|
564 | elif allBinaries: |
---|
565 | print('Loading all binaries with command...') |
---|
566 | if not GSASIIpath.svnSwitchDir('AllBinaries','',g2home+ 'Binaries/',None,True): |
---|
567 | msg = 'Binary load failed. Subversion problem? Please seek help' |
---|
568 | BailOut(msg) |
---|
569 | elif numpyVersion: |
---|
570 | binaryVersion = GSASIIpath.GetBinaryPrefix()+'_n'+numpyVersion |
---|
571 | if not GSASIIpath.svnSwitchDir('bindist','',g2home+ 'Binaries/'+binaryVersion,None,True): |
---|
572 | msg = 'Binary load failed with '+binaryVersion+'. Subversion problem? Please seek help' |
---|
573 | BailOut(msg) |
---|
574 | else: |
---|
575 | GSASIIpath.DownloadG2Binaries(g2home) |
---|
576 | |
---|
577 | #=========================================================================== |
---|
578 | # test if the compiled files load correctly |
---|
579 | #=========================================================================== |
---|
580 | GSASIItested = False |
---|
581 | if not skipInstallChecks: |
---|
582 | script = """ |
---|
583 | # commands that test each module can at least be loaded & run something in pyspg |
---|
584 | try: |
---|
585 | import GSASIIpath |
---|
586 | GSASIIpath.SetBinaryPath(loadBinary=False) |
---|
587 | import pyspg |
---|
588 | import histogram2d |
---|
589 | import polymask |
---|
590 | import pypowder |
---|
591 | import pytexture |
---|
592 | pyspg.sgforpy('P -1') |
---|
593 | print('==OK==') |
---|
594 | except Exception as err: |
---|
595 | print(err) |
---|
596 | """ |
---|
597 | p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE,stderr=subprocess.PIPE, |
---|
598 | cwd=path2GSAS2) |
---|
599 | res,err = MakeByte2str(p.communicate()) |
---|
600 | if '==OK==' not in str(res) or p.returncode != 0: |
---|
601 | #print('\n'+75*'=') |
---|
602 | msg = 'Failed when testing the GSAS-II compiled files. GSAS-II will not run' |
---|
603 | msg += ' without correcting this.\n\nError message:\n' |
---|
604 | if res: |
---|
605 | msg += res |
---|
606 | msg += '\n' |
---|
607 | if err: |
---|
608 | msg += err |
---|
609 | #print('\nAttempting to open a web page on compiling GSAS-II...') |
---|
610 | msg += '\n\nPlease see web page\nhttps://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII if you wish to compile for yourself (usually not needed for windows and Mac, but sometimes required for Linux.)' |
---|
611 | BailOut(msg) |
---|
612 | #import webbrowser |
---|
613 | #webbrowser.open_new('https://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII') |
---|
614 | #print(75*'=') |
---|
615 | # if '86' in platform.machine() and (sys.platform.startswith('linux') |
---|
616 | # or sys.platform == "darwin" |
---|
617 | # or sys.platform.startswith('win')): |
---|
618 | # print('Platform '+sys.platform+' with processor type '+platform.machine()+' is supported') |
---|
619 | # else: |
---|
620 | # print('Platform '+sys.platform+' with processor type '+platform.machine()+' not is supported') |
---|
621 | else: |
---|
622 | print('Successfully tested compiled routines') |
---|
623 | GSASIItested = True |
---|
624 | #=========================================================================== |
---|
625 | # import all .py files so that .pyc files get created |
---|
626 | if not skipInstallChecks: |
---|
627 | print('Byte-compiling all .py files...') |
---|
628 | import compileall |
---|
629 | compileall.compile_dir(path2GSAS2,quiet=True) |
---|
630 | print('done') |
---|
631 | #=========================================================================== |
---|
632 | # do platform-dependent stuff |
---|
633 | #=========================================================================== |
---|
634 | if sys.version_info[0] > 2: |
---|
635 | def execfile(file): |
---|
636 | with open(file) as source_file: |
---|
637 | exec(source_file.read()) |
---|
638 | |
---|
639 | if skipInstallChecks: |
---|
640 | pass |
---|
641 | #=========================================================================== |
---|
642 | # on Windows, make a batch file with Python and GSAS-II location hard-coded |
---|
643 | elif sys.platform.startswith('win') and os.path.exists( |
---|
644 | os.path.join(path2GSAS2,"makeBat.py")): |
---|
645 | execfile(os.path.join(path2GSAS2,"makeBat.py")) |
---|
646 | #=========================================================================== |
---|
647 | # on a Mac, make an applescript |
---|
648 | elif sys.platform.startswith('darwin') and os.path.exists( |
---|
649 | os.path.join(path2GSAS2,"makeMacApp.py")): |
---|
650 | sys.argv = [os.path.join(path2GSAS2,"makeMacApp.py")] |
---|
651 | print(u'running '+sys.argv[0]) |
---|
652 | execfile(sys.argv[0]) |
---|
653 | #=========================================================================== |
---|
654 | # On linux, make desktop icon |
---|
655 | elif sys.platform.startswith('linux') and os.path.exists( |
---|
656 | os.path.join(path2GSAS2,"makeLinux.py")): |
---|
657 | sys.argv = [os.path.join(path2GSAS2,"makeLinux.py")] |
---|
658 | print(u'running '+sys.argv[0]) |
---|
659 | execfile(sys.argv[0]) |
---|
660 | |
---|