Changeset 2887 for install/bootstrap.py
- Timestamp:
- Jun 29, 2017 5:54:41 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
install/bootstrap.py
r2866 r2887 3 3 # works for Mac & Linux & Windows 4 4 import os, stat, sys, platform, subprocess 5 home = 'https://subversion.xray.aps.anl.gov/pyGSAS/' 5 6 g2home = 'https://subversion.xray.aps.anl.gov/pyGSAS/' 7 ################################################################################ 8 ################################################################################ 9 # routines copied from GSASIIpath.py 10 proxycmds = [] 11 'Used to hold proxy information for subversion, set if needed in whichsvn' 12 svnLocCache = None 13 'Cached location of svn to avoid multiple searches for it' 14 15 def whichsvn(): 16 '''Returns a path to the subversion exe file, if any is found. 17 Searches the current path after adding likely places where GSAS-II 18 might install svn. 19 20 :returns: None if svn is not found or an absolute path to the subversion 21 executable file. 22 ''' 23 # use a previosuly cached svn location 24 global svnLocCache 25 if svnLocCache: return svnLocCache 26 # prepare to find svn 27 is_exe = lambda fpath: os.path.isfile(fpath) and os.access(fpath, os.X_OK) 28 svnprog = 'svn' 29 if sys.platform.startswith('win'): svnprog += '.exe' 30 gsaspath = os.path.split(__file__)[0] 31 # check for a proxy 32 proxyinfo = os.path.join(gsaspath,"proxyinfo.txt") 33 if os.path.exists(proxyinfo): 34 global proxycmds 35 proxycmds = [] 36 fp = open(proxyinfo,'r') 37 host = fp.readline().strip() 38 port = fp.readline().strip() 39 fp.close() 40 proxycmds.append('--config-option') 41 proxycmds.append('servers:global:http-proxy-host='+host) 42 proxycmds.append('--config-option') 43 proxycmds.append('servers:global:http-proxy-port='+port) 44 # add likely places to find subversion when installed with GSAS-II 45 pathlist = os.environ["PATH"].split(os.pathsep) 46 pathlist.append(os.path.split(sys.executable)[0]) 47 pathlist.append(gsaspath) 48 for rpt in ('..','bin'),('..','Library','bin'),('svn','bin'),('svn',),('.'): 49 pt = os.path.normpath(os.path.join(gsaspath,*rpt)) 50 if os.path.exists(pt): 51 pathlist.insert(0,pt) 52 # search path for svn or svn.exe 53 for path in pathlist: 54 exe_file = os.path.join(path, svnprog) 55 if is_exe(exe_file): 56 try: 57 p = subprocess.Popen([exe_file,'help'],stdout=subprocess.PIPE) 58 res = p.stdout.read() 59 p.communicate() 60 svnLocCache = os.path.abspath(exe_file) 61 return svnLocCache 62 except: 63 pass 64 svnLocCache = None 65 66 def svnVersion(svn=None): 67 '''Get the version number of the current subversion executable 68 69 :returns: a string with a version number such as "1.6.6" or None if 70 subversion is not found. 71 72 ''' 73 if not svn: svn = whichsvn() 74 if not svn: return 75 76 cmd = [svn,'--version','--quiet'] 77 s = subprocess.Popen(cmd, 78 stdout=subprocess.PIPE,stderr=subprocess.PIPE) 79 out,err = s.communicate() 80 if err: 81 print 'subversion error!\nout=',out 82 print 'err=',err 83 return None 84 return out.strip() 85 86 def svnVersionNumber(svn=None): 87 '''Get the version number of the current subversion executable 88 89 :returns: a fractional version number such as 1.6 or None if 90 subversion is not found. 91 92 ''' 93 ver = svnVersion(svn) 94 if not ver: return 95 M,m = ver.split('.')[:2] 96 return int(M)+int(m)/10. 97 98 ################################################################################ 99 ################################################################################ 6 100 print 70*'*' 7 101 #testing for incorrect locale code' … … 73 167 74 168 print '\nChecking for subversion...', 75 if sys.platform.startswith('win'): 76 pathlist = os.environ['PATH'].split(';') 77 if os.path.exists(os.path.join(gsaspath,'svn')): 78 pathlist.append(os.path.join(gsaspath,'svn','bin')) 79 else: 80 pathlist = os.environ['PATH'].split(':') 81 # add the standard location for wandisco svn to the path 82 pathlist.append('/opt/subversion/bin') 83 if sys.platform.startswith('win'): 84 svn = 'svn.exe' 85 else: 86 svn = 'svn' 87 # use svn installed via conda 1st (mac) 88 if os.path.exists(os.path.join(os.path.split(sys.executable)[0],svn)): 89 pathlist.insert(0,os.path.split(sys.executable)[0]) 90 # use svn installed via conda 1st (Windows) 91 if os.path.exists(os.path.join(os.path.split(sys.executable)[0],'Library','bin',svn)): 92 pathlist.insert(0,os.path.join(os.path.split(sys.executable)[0],'Library','bin')) 93 94 for path in pathlist: 95 svn = os.path.join(path,'svn') 96 try: 97 p = subprocess.Popen([svn,'help'],stdout=subprocess.PIPE) 98 res = p.stdout.read() 99 p.communicate() 100 break 101 except: 102 pass 103 else: 169 svn = whichsvn() 170 if not svn: 104 171 print "Sorry, subversion (svn) could not be found on your system." 105 172 print "Please install this or place in path and rerun this." … … 113 180 print 'done.' 114 181 115 print 'Ready to bootstrap GSAS-II from repository\n\t', home,'\nto '+gsaspath182 print 'Ready to bootstrap GSAS-II from repository\n\t',g2home,'\nto '+gsaspath 116 183 proxycmds = [] 117 if os.path.exists("proxyinfo.txt"): 118 fp = open("proxyinfo.txt",'r') 119 os.remove("proxyinfo.txt") 184 proxyinfo = os.path.join(gsaspath,"proxyinfo.txt") 185 host = None 186 port = '8080' 187 if os.path.exists(proxyinfo): 188 fp = open(proxyinfo,'r') 189 host = fp.readline().strip() 190 port = fp.readline().strip() 191 fp.close() 192 os.remove(proxyinfo) 120 193 print(70*"=") 121 ans = raw_input("Enter the proxy address [none needed]: ") 122 if ans.strip() != "": 194 if host: 195 ans = raw_input("Enter the proxy address (type none to remove) ["+host+"]: ") 196 if ans.strip().lower() == "none": host = ans = "" 197 else: 198 ans = raw_input("Enter the proxy address [none needed]: ") 199 if ans.strip() != "" or host: 123 200 proxycmds.append('--config-option') 201 if ans.strip() == "": ans=host 124 202 proxycmds.append('servers:global:http-proxy-host='+ans.strip()) 125 fp = open( "proxyinfo.txt",'w')203 fp = open(proxyinfo,'w') 126 204 fp.write(ans.strip()+'\n') 127 ans = raw_input("Enter the proxy port [ 8080]: ")128 if ans.strip() == "": ans= "8080"205 ans = raw_input("Enter the proxy port ["+port+"]: ") 206 if ans.strip() == "": ans=port 129 207 proxycmds.append('--config-option') 130 208 proxycmds.append('servers:global:http-proxy-port='+ans.strip()) … … 132 210 fp.close() 133 211 134 print 'Determining system type...', 135 if sys.platform.startswith('linux'): 136 #if platform.processor().find('86') <= -1: 137 # ans = raw_input("Note, GSAS requires an Intel-compatible processor and 32-bit" 138 # "libraries.\nAre you sure want to continue? [Yes]/no: ") 139 # if ans.lower().find('no') > -1: sys.exit() 140 repos = 'linux' 141 print 'Linux, assuming Intel-compatible' 142 elif sys.platform == "darwin" and platform.processor() == 'i386': 143 repos = 'osxi86' 144 print 'Mac OS X, Intel-compatible' 145 elif sys.platform == "darwin": 146 repos = 'osxppc' 147 print 'Mac OS X, PowerPC -- you will need to run scons on fsource files' 148 elif sys.platform.startswith('win'): 149 repos = 'win' 150 print 'Windows' 151 else: 152 print 'Unidentifed platform -- you probably will need to run scons to compile the fsource files' 153 212 # patch: switch GSAS-II location if linked to XOR server (removed May/June 2017) 154 213 cmd = [svn, 'info'] 155 214 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) … … 159 218 cmd = [svn, 'switch','--relocate','https://subversion.xor.aps.anl.gov/pyGSAS', 160 219 'https://subversion.xray.aps.anl.gov/pyGSAS'] 220 if proxycmds: cmd += proxycmds 161 221 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 162 222 res,err = p.communicate() … … 166 226 print(res) 167 227 168 cmd = [svn, 'co', home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert']228 cmd = [svn, 'co', g2home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert'] 169 229 if proxycmds: cmd += proxycmds 170 230 msg = 'Now preparing to install GSAS-II' … … 180 240 if p: 181 241 print 'subversion returned an error; Retrying with command for older version...' 182 cmd = [svn, 'co', home+ 'trunk/', gsaspath]242 cmd = [svn, 'co', g2home+ 'trunk/', gsaspath] 183 243 if proxycmds: cmd += proxycmds 184 244 for item in cmd: print item, 185 245 print "" 186 246 p = subprocess.call(cmd) 247 print('\n'+75*'*') 187 248 188 249 #=========================================================================== 189 250 # test if the compiled files load correctly 190 251 #=========================================================================== 191 script = """ 252 try: 253 import GSASIIpath 254 print('import of GSASIIpath completed') 255 except Exception as err: 256 print('\n'+75*'=') 257 print('Failed with import of GSASIIpath. This is unexpected.') 258 print('GSAS-II will not run without correcting this. Contact toby@anl.gov') 259 print(err) 260 print(75*'=') 261 sys.exit() 262 263 script = """ # commands that test each module can at least be loaded & run something in pyspg 192 264 try: 193 265 import GSASIIpath … … 202 274 pass 203 275 """ 204 p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE, cwd=gsaspath)276 p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE,stderr=subprocess.PIPE) 205 277 res,err = p.communicate() 206 278 if '==OK==' not in res or p.returncode != 0: 207 279 print('\n'+75*'=') 208 280 print('Failed when testing the GSAS-II compiled files. GSAS-II will not run without') 209 print('correcting this. Attempting to open a web page on compiling GSAS-II...') 281 print('correcting this.') 282 #print(res) 283 #print(err) 284 if '86' in platform.machine() and (sys.platform.startswith('linux') 285 or sys.platform == "darwin" 286 or sys.platform.startswith('win')): 287 print('Platform '+sys.platform+' with processor type '+platform.machine()+' is supported') 288 else: 289 print('Platform '+sys.platform+' with processor type '+platform.machine()+' not is supported') 290 print('\nAttempting to open a web page on compiling GSAS-II...') 210 291 print('(https://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII)') 211 print(75*'=')212 print('\n')213 292 import webbrowser 214 293 webbrowser.open_new('https://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII') 294 print(75*'=') 215 295 sys.exit() 216 296 else:
Note: See TracChangeset
for help on using the changeset viewer.