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