Changeset 3910 for install/bootstrap.py
- Timestamp:
- Apr 19, 2019 1:02:23 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
install/bootstrap.py
r3515 r3910 2 2 # Installs GSAS-II from network using subversion and creates platform-specific shortcuts. 3 3 # works for Mac & Linux & Windows 4 from __future__ import division, print_function 4 5 import os, stat, sys, platform, subprocess, datetime 5 6 … … 7 8 g2home = 'https://subversion.xray.aps.anl.gov/pyGSAS/' 8 9 path2GSAS2 = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) 10 11 skipInstallSteps = False 12 skipDownloadSteps = False 13 skipProxy = False 14 help = False 15 allBinaries = False 16 for a in sys.argv[1:]: 17 if 'noinstall' in a.lower(): 18 skipInstallSteps = True 19 elif 'nonet' in a.lower(): 20 skipDownloadSteps = True 21 skipProxy = True 22 elif 'noproxy' in a.lower(): 23 skipProxy = True 24 elif 'help' in a.lower(): 25 help = True 26 elif 'allbin' in a.lower() or 'server' in a.lower(): 27 allBinaries = True 28 else: 29 help = True 30 31 if help: 32 print(''' 33 bootstrap.py options: 34 35 --noinstall skip post-install, such as creating run shortcuts 36 --noproxy do not ask for proxy information 37 --server load all binary versions 38 --allbin load all binary versions (same as --server) 39 --help this message 40 --nonet skip steps requiring internet 41 42 ''') 43 sys.exit() 44 9 45 now = str(datetime.datetime.now()) 10 46 print('Running bootstrap from {} at {}\n\tId: {}'.format(path2GSAS2,now,version)) … … 12 48 fp.write('Running bootstrap from {} at {}\n\tId: {}\n'.format(path2GSAS2,now,version)) 13 49 fp.close() 50 14 51 ################################################################################ 15 52 ################################################################################ … … 170 207 print('Checking python packages...') 171 208 missing = [] 172 for pkg in ['numpy','scipy','matplotlib','wx', ]:209 for pkg in ['numpy','scipy','matplotlib','wx','OpenGL',]: 173 210 try: 174 211 exec('import '+pkg) … … 187 224 exec('import '+pkg) 188 225 sys.exit() 189 try: 190 import OpenGL 191 install_with_easyinstall = None 192 except: 193 try: 194 from setuptools.command import easy_install 195 except ImportError: 196 print('You are missing the OpenGL Python package. This can be ') 197 print('installed by this script if the setuptools package is installed') 198 print('Please install either OpenGL (pyopengl) or setuptools') 199 print("package and try running this again.") 226 # try: 227 # import OpenGL 228 # install_with_easyinstall = None 229 # except: 230 # try: 231 # from setuptools.command import easy_install 232 # except ImportError: 233 # print('You are missing the OpenGL Python package. This can be ') 234 # print('installed by this script if the setuptools package is installed') 235 # print('Please install either OpenGL (pyopengl) or setuptools') 236 # print("package and try running this again.") 237 # sys.exit() 238 # print("Missing the OpenGL Python package. Will attempt to install this later.") 239 # def install_with_easyinstall(package): 240 # try: 241 # print("trying system-wide ") 242 # easy_install.main(['-f',os.path.split(__file__)[0],package]) 243 # return 244 # except: 245 # pass 246 # try: 247 # print("trying user level ") 248 # easy_install.main(['-f',os.path.split(__file__)[0],'--user',package]) 249 # return 250 # except: 251 # print("\nInstall of "+package+" failed. Error traceback follows:") 252 # import traceback 253 # print(traceback.format_exc()) 254 # sys.exit() 255 256 if not skipDownloadSteps: 257 host = None 258 port = '80' 259 print('\nChecking for subversion...') 260 svn = whichsvn() # resets host & port if proxyinfo.txt is found 261 if not svn: 262 print("Sorry, subversion (svn) could not be found on your system.") 263 print("Please install this or place in path and rerun this.") 264 #raise Exception('Subversion (svn) not found') 200 265 sys.exit() 201 print("Missing the OpenGL Python package. Will attempt to install this later.") 202 def install_with_easyinstall(package): 203 try: 204 print("trying system-wide ") 205 easy_install.main(['-f',os.path.split(__file__)[0],package]) 206 return 207 except: 208 pass 209 try: 210 print("trying user level ") 211 easy_install.main(['-f',os.path.split(__file__)[0],'--user',package]) 212 return 213 except: 214 print("\nInstall of "+package+" failed. Error traceback follows:") 215 import traceback 216 print(traceback.format_exc()) 217 sys.exit() 218 219 host = None 220 port = '80' 221 print('\nChecking for subversion...') 222 svn = whichsvn() # resets host & port if proxyinfo.txt is found 223 if not svn: 224 print("Sorry, subversion (svn) could not be found on your system.") 225 print("Please install this or place in path and rerun this.") 226 #raise Exception('Subversion (svn) not found') 227 sys.exit() 228 print(' found svn image: '+svn) 229 230 if install_with_easyinstall: 231 print('\nInstalling PyOpenGL. Lots of warnings will follow... ') 232 install_with_easyinstall('PyOpenGl') 233 print('done.') 266 print(' found svn image: '+svn) 267 268 #if install_with_easyinstall: 269 # print('\nInstalling PyOpenGL. Lots of warnings will follow... ') 270 # install_with_easyinstall('PyOpenGl') 271 # print('done.') 234 272 235 273 print('Ready to bootstrap GSAS-II from repository\n\t'+g2home+'\nto '+path2GSAS2) … … 272 310 # get proxy from user, if terminal available 273 311 try: 274 if host: 312 if skipProxy: 313 host = "" 314 elif host: 275 315 ans = getinput("Enter the proxy address (type none to remove) ["+host+"]: ").strip() 276 316 if ans.lower() == "none": host = "" … … 300 340 fp.close() 301 341 302 # patch: switch GSAS-II location if linked to XOR server (removed May/June 2017) 303 cmd = [svn, 'info'] 304 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 305 res,err = p.communicate() 306 if '.xor.' in str(res): 307 print('Switching previous install with .xor. download location to\n\thttps://subversion.xray.aps.anl.gov/pyGSAS') 308 cmd = [svn, 'switch','--relocate','https://subversion.xor.aps.anl.gov/pyGSAS', 309 'https://subversion.xray.aps.anl.gov/pyGSAS'] 310 if proxycmds: cmd += proxycmds 342 if not skipDownloadSteps: 343 # patch: switch GSAS-II location if linked to XOR server (relocated May/June 2017) 344 cmd = [svn, 'info'] 311 345 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 312 346 res,err = p.communicate() 313 if err: 314 print('Please report this error to toby@anl.gov:') 315 print(err) 316 print(res) 317 # patch: switch GSAS-II location if switched to 2frame version (removed August 2017) 318 if '2frame' in str(res): 319 print('Switching previous 2frame install to trunk\n\thttps://subversion.xray.aps.anl.gov/pyGSAS') 320 cmd = [svn, 'switch',g2home + '/trunk',path2GSAS2, 321 '--non-interactive','--trust-server-cert', 322 '--accept','theirs-conflict','--force','--ignore-ancestry'] 323 if proxycmds: cmd += proxycmds 324 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 325 res,err = p.communicate() 326 if err: 327 print('Please report this error to toby@anl.gov:') 328 print(err) 329 print(res) 330 331 print('\n'+75*'*') 332 print('Now preparing to install GSAS-II') 333 tryagain = True 334 err = False 335 firstPass = 0 336 while(tryagain): 337 tryagain = False 338 if err: 339 print('Retrying after a cleanup...') 340 cmd = [svn, 'cleanup', path2GSAS2] 347 if '.xor.' in str(res): 348 print('Switching previous install with .xor. download location to\n\thttps://subversion.xray.aps.anl.gov/pyGSAS') 349 cmd = [svn, 'switch','--relocate','https://subversion.xor.aps.anl.gov/pyGSAS', 350 'https://subversion.xray.aps.anl.gov/pyGSAS'] 351 if proxycmds: cmd += proxycmds 352 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 353 res,err = p.communicate() 354 if err: 355 print('Please report this error to toby@anl.gov:') 356 print(err) 357 print(res) 358 # patch: switch GSAS-II location if switched to 2frame version (removed August 2017) 359 if '2frame' in str(res): 360 print('Switching previous 2frame install to trunk\n\thttps://subversion.xray.aps.anl.gov/pyGSAS') 361 cmd = [svn, 'switch',g2home + '/trunk',path2GSAS2, 362 '--non-interactive','--trust-server-cert', 363 '--accept','theirs-conflict','--force','--ignore-ancestry'] 364 if proxycmds: cmd += proxycmds 365 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 366 res,err = p.communicate() 367 if err: 368 print('Please report this error to toby@anl.gov:') 369 print(err) 370 print(res) 371 372 print('\n'+75*'*') 373 print('Now preparing to install GSAS-II') 374 tryagain = True 375 err = False 376 firstPass = 0 377 while(tryagain): 378 tryagain = False 379 if err: 380 print('Retrying after a cleanup...') 381 cmd = [svn, 'cleanup', path2GSAS2] 382 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) 383 out,err = s.communicate() 384 if err: 385 print('subversion returned an error:') 386 print(out) 387 print(err) 388 cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2, '--non-interactive', '--trust-server-cert'] 389 if proxycmds: cmd += proxycmds 390 msg = 'svn load command: ' 391 for item in cmd: msg += " "+item 392 print(msg) 341 393 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) 342 out,err = s.communicate() 394 print('\nsubversion output:') 395 out,err = s.communicate() 343 396 if err: 344 397 print('subversion returned an error:') 345 398 print(out) 346 399 print(err) 347 cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2, '--non-interactive', '--trust-server-cert'] 348 if proxycmds: cmd += proxycmds 349 msg = 'svn load command: ' 350 for item in cmd: msg += " "+item 351 print(msg) 352 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) 353 print('\nsubversion output:') 354 out,err = s.communicate() 400 if firstPass == 0: tryagain = True 401 firstPass += 1 355 402 if err: 356 print('subversion returned an error:') 357 print(out) 358 print(err) 359 if firstPass == 0: tryagain = True 360 firstPass += 1 361 if err: 362 print('Retrying with a command for older svn version...') 363 cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2] 364 if proxycmds: cmd += proxycmds 365 msg = "" 366 for item in cmd: msg += " " + item 367 print(msg) 368 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) 369 out,err = s.communicate() 370 if err: 371 print('subversion returned an error:') 372 print(err) 373 print(' *** GSAS-II failed to be installed. A likely reason is a network access') 374 print(' *** problem, most commonly because you need to use a network proxy. Please') 375 print(' *** check with a network administrator or use http://www.whatismyproxy.com/\n') 376 sys.exit() 377 print('\n'+75*'*') 403 print('Retrying with a command for older svn version...') 404 cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2] 405 if proxycmds: cmd += proxycmds 406 msg = "" 407 for item in cmd: msg += " " + item 408 print(msg) 409 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) 410 out,err = s.communicate() 411 if err: 412 print('subversion returned an error:') 413 print(err) 414 print(' *** GSAS-II failed to be installed. A likely reason is a network access') 415 print(' *** problem, most commonly because you need to use a network proxy. Please') 416 print(' *** check with a network administrator or use http://www.whatismyproxy.com/\n') 417 sys.exit() 418 print('\n'+75*'*') 378 419 379 420 try: … … 388 429 sys.exit() 389 430 390 for a in sys.argv[1:]: 391 if 'allbin' in a.lower() or 'server' in a.lower(): 392 print('Loading all binaries with command...') 393 if not GSASIIpath.svnSwitchDir('AllBinaries','',g2home+ 'Binaries/',None,True): 394 print('Binary load failed') 395 sys.exit() 396 break 431 if allBinaries and skipDownloadSteps: 432 print('Loading all binaries with command...') 433 if not GSASIIpath.svnSwitchDir('AllBinaries','',g2home+ 'Binaries/',None,True): 434 print('Binary load failed') 435 sys.exit() 397 436 else: 398 437 GSASIIpath.DownloadG2Binaries(g2home) … … 405 444 try: 406 445 import GSASIIpath 407 GSASIIpath.SetBinaryPath( )446 GSASIIpath.SetBinaryPath(loadBinary=False) 408 447 import pyspg 409 448 import histogram2d … … 413 452 pyspg.sgforpy('P -1') 414 453 print('==OK==') 415 except :416 p ass454 except Exception as err: 455 print(err) 417 456 """ 418 457 p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE,stderr=subprocess.PIPE, … … 423 462 print('Failed when testing the GSAS-II compiled files. GSAS-II will not run') 424 463 print('without correcting this.\n\nError message:') 425 #print(res) 426 print(err) 464 if res: 465 print(res.decode()) 466 if err: 467 print(err.decode()) 427 468 #print('\nAttempting to open a web page on compiling GSAS-II...') 428 469 print('Please see web page\nhttps://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII') … … 441 482 #=========================================================================== 442 483 # import all .py files so that .pyc files get created 443 print('Byte-compiling all .py files...') 444 import compileall 445 compileall.compile_dir(path2GSAS2,quiet=True) 446 print('done') 484 if not skipInstallSteps: 485 print('Byte-compiling all .py files...') 486 import compileall 487 compileall.compile_dir(path2GSAS2,quiet=True) 488 print('done') 447 489 #=========================================================================== 448 490 # platform-dependent stuff … … 452 494 with open(file) as source_file: 453 495 exec(source_file.read()) 496 497 if skipInstallSteps: 498 pass 499 #=========================================================================== 454 500 # on Windows, make a batch file with Python and GSAS-II location hard-coded 455 if sys.platform.startswith('win') and os.path.exists(501 elif sys.platform.startswith('win') and os.path.exists( 456 502 os.path.join(path2GSAS2,"makeBat.py")): 457 503 execfile(os.path.join(path2GSAS2,"makeBat.py"))
Note: See TracChangeset
for help on using the changeset viewer.