Changeset 3514 for install/g2pkg/src/bootstrap.py
- Timestamp:
- Jul 29, 2018 9:03:43 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
install/g2pkg/src/bootstrap.py
r3431 r3514 4 4 import os, stat, sys, platform, subprocess, datetime 5 5 6 version = "$Id: 35xx $" 6 7 g2home = 'https://subversion.xray.aps.anl.gov/pyGSAS/' 7 8 path2GSAS2 = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) 8 9 now = str(datetime.datetime.now()) 9 print('Running bootstrap from {} at {} '.format(path2GSAS2,now))10 print('Running bootstrap from {} at {}\n\tId: {}'.format(path2GSAS2,now,version)) 10 11 fp = open(os.path.join(path2GSAS2,'bootstrap.log'),'a') 11 fp.write('Running bootstrap from {} at {}\n '.format(path2GSAS2,now))12 fp.write('Running bootstrap from {} at {}\n\tId: {}\n'.format(path2GSAS2,now,version)) 12 13 fp.close() 13 14 ################################################################################ 14 15 ################################################################################ 16 def GetConfigValue(*args): return True 15 17 # routines copied from GSASIIpath.py 16 18 proxycmds = [] … … 19 21 'Cached location of svn to avoid multiple searches for it' 20 22 23 def MakeByte2str(arg): 24 '''Convert output from subprocess pipes (bytes) to str (unicode) in Python 3. 25 In Python 2: Leaves output alone (already str). 26 Leaves stuff of other types alone (including unicode in Py2) 27 Works recursively for string-like stuff in nested loops and tuples. 28 29 typical use:: 30 31 out = MakeByte2str(out) 32 33 or:: 34 35 out,err = MakeByte2str(s.communicate()) 36 37 ''' 38 if isinstance(arg,str): return arg 39 if isinstance(arg,bytes): return arg.decode() 40 if isinstance(arg,list): 41 return [MakeByte2str(i) for i in arg] 42 if isinstance(arg,tuple): 43 return tuple([MakeByte2str(i) for i in arg]) 44 return arg 45 46 def getsvnProxy(): 47 '''Loads a proxy for subversion from the file created by bootstrap.py 48 ''' 49 proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt") 50 if os.path.exists(proxyinfo): 51 global proxycmds 52 global host,port # only in bootstrap.py 53 proxycmds = [] 54 fp = open(proxyinfo,'r') 55 host = fp.readline().strip() 56 port = fp.readline().strip() 57 fp.close() 58 setsvnProxy(host,port) 59 if not host.strip(): return '','' 60 return host,port 61 return '','' 62 63 def setsvnProxy(host,port): 64 '''Sets the svn commands needed to use a proxy 65 ''' 66 global proxycmds 67 proxycmds = [] 68 host = host.strip() 69 port = port.strip() 70 if not host.strip(): return 71 proxycmds.append('--config-option') 72 proxycmds.append('servers:global:http-proxy-host='+host) 73 if port.strip(): 74 proxycmds.append('--config-option') 75 proxycmds.append('servers:global:http-proxy-port='+port) 76 21 77 def whichsvn(): 22 78 '''Returns a path to the subversion exe file, if any is found. … … 34 90 svnprog = 'svn' 35 91 if sys.platform.startswith('win'): svnprog += '.exe' 36 gsaspath = os.path.split(__file__)[0] 37 # check for a proxy 38 proxyinfo = os.path.join(gsaspath,"proxyinfo.txt") 39 if os.path.exists(proxyinfo): 40 global proxycmds 41 proxycmds = [] 42 fp = open(proxyinfo,'r') 43 host = fp.readline().strip() 44 port = fp.readline().strip() 45 fp.close() 46 proxycmds.append('--config-option') 47 proxycmds.append('servers:global:http-proxy-host='+host) 48 proxycmds.append('--config-option') 49 proxycmds.append('servers:global:http-proxy-port='+port) 92 host,port = getsvnProxy() 93 if GetConfigValue('debug') and host: 94 print('DBG_Using proxy host {} port {}'.format(host,port)) 50 95 # add likely places to find subversion when installed with GSAS-II 51 96 pathlist = os.environ["PATH"].split(os.pathsep) 52 pathlist. append(os.path.split(sys.executable)[0])53 pathlist. append(gsaspath)97 pathlist.insert(0,os.path.split(sys.executable)[0]) 98 pathlist.insert(1,path2GSAS2) 54 99 for rpt in ('..','bin'),('..','Library','bin'),('svn','bin'),('svn',),('.'): 55 pt = os.path.normpath(os.path.join( gsaspath,*rpt))100 pt = os.path.normpath(os.path.join(path2GSAS2,*rpt)) 56 101 if os.path.exists(pt): 57 102 pathlist.insert(0,pt) … … 83 128 s = subprocess.Popen(cmd, 84 129 stdout=subprocess.PIPE,stderr=subprocess.PIPE) 85 out,err = s.communicate() 86 if err: 87 print('subversion error!\nout= '+out) 88 print('err= '+err) 130 out,err = MakeByte2str(s.communicate()) 131 if err: 132 print ('subversion error!\nout=%s'%out) 133 print ('err=%s'%err) 134 s = '\nsvn command: ' 135 for i in cmd: s += i + ' ' 136 print(s) 89 137 return None 90 138 return out.strip() … … 169 217 sys.exit() 170 218 219 host = None 220 port = '80' 171 221 print('\nChecking for subversion...') 172 svn = whichsvn() 222 svn = whichsvn() # resets host & port if proxyinfo.txt is found 173 223 if not svn: 174 224 print("Sorry, subversion (svn) could not be found on your system.") … … 186 236 proxycmds = [] 187 237 proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt") 188 host = None189 port = '80'190 238 if os.path.exists(proxyinfo): 191 239 fp = open(proxyinfo,'r') … … 199 247 else: 200 248 getinput = input 201 try: 202 key = None 249 250 # get proxy from environment variable 251 key = None 252 for i in os.environ.keys(): 253 if 'https_proxy' == i.lower(): 254 key = i 255 break 256 else: 203 257 for i in os.environ.keys(): 204 if 'http s_proxy' == i.lower():258 if 'http_proxy' == i.lower(): 205 259 key = i 206 260 break 261 if key: 262 val = os.environ[key].strip() 263 if val[-1] == '/': 264 val = val[:-1] 265 if len(val.split(':')) > 2: 266 host = ':'.join(val.split(':')[:-1]) 267 port = val.split(':')[-1] 207 268 else: 208 for i in os.environ.keys(): 209 if 'http_proxy' == i.lower(): 210 key = i 211 break 212 if key: 213 val = os.environ[key].strip() 214 if val[-1] == '/': 215 val = val[:-1] 216 if len(val.split(':')) > 2: 217 host = ':'.join(val.split(':')[:-1]) 218 port = val.split(':')[-1] 219 else: 220 host = ':'.join(val.split(':')[:-1]) 221 port = val.split(':')[-1] 222 elif host: 223 ans = getinput("Enter the proxy address (type none to remove) ["+host+"]: ") 224 if ans.strip().lower() == "none": host = ans = "" 269 host = ':'.join(val.split(':')[:-1]) 270 port = val.split(':')[-1] 271 272 # get proxy from user, if terminal available 273 try: 274 if host: 275 ans = getinput("Enter the proxy address (type none to remove) ["+host+"]: ").strip() 276 if ans.lower() == "none": host = "" 225 277 else: 226 ans = getinput("Enter your proxy address [none needed]: ") 227 if ans.strip() != "" or host: 228 ans = getinput("Enter the proxy port ["+port+"]: ") 229 if ans.strip() == "": ans=port 278 ans = getinput("Enter your proxy address [none needed]: ").strip() 279 if ans: host = ans 280 if host: 281 ans = getinput("Enter the proxy port ["+port+"]: ").strip() 282 if ans == "": ans=port 230 283 port = ans 231 284 except EOFError: … … 242 295 fp.write(port.strip()+'\n') 243 296 fp.close() 297 fp = open(os.path.join(path2GSAS2,'bootstrap.log'),'a') 298 fp.write('Proxy info written: {} port\n'.format(host,port)) 299 print('Proxy info written: {} port'.format(host,port)) 300 fp.close() 244 301 245 302 # patch: switch GSAS-II location if linked to XOR server (removed May/June 2017) … … 272 329 print(res) 273 330 274 cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2, '--non-interactive', '--trust-server-cert']275 if proxycmds: cmd += proxycmds276 msg = 'Now preparing to install GSAS-II'277 331 print('\n'+75*'*') 278 print(msg + u' from ' + cmd[2]) 279 msg = 'svn load command: ' 280 for item in cmd: msg += " "+item 281 print(msg) 282 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) 283 print('\nsubversion output:') 284 out,err = s.communicate() 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] 341 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) 342 out,err = s.communicate() 343 if err: 344 print('subversion returned an error:') 345 print(out) 346 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() 355 if err: 356 print('subversion returned an error:') 357 print(out) 358 print(err) 359 if firstPass == 0: tryagain = True 360 firstPass += 1 285 361 if err: 286 print('subversion returned an error:') 287 print(err) 288 print('Retrying with a cleanup and a command for older svn version...') 289 cmd = [svn, 'cleanup', path2GSAS2] 290 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) 291 out,err = s.communicate() 362 print('Retrying with a command for older svn version...') 292 363 cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2] 293 364 if proxycmds: cmd += proxycmds 294 365 msg = "" 295 for item in cmd: msg += item366 for item in cmd: msg += " " + item 296 367 print(msg) 297 368 s = subprocess.Popen(cmd,stderr=subprocess.PIPE) … … 300 371 print('subversion returned an error:') 301 372 print(err) 302 print(' *** GSAS-II failed to be installed. In case the cleanup worked, try running this again') 303 print(' *** If this installation continues to fail, a likely reason is a network access') 373 print(' *** GSAS-II failed to be installed. A likely reason is a network access') 304 374 print(' *** problem, most commonly because you need to use a network proxy. Please') 305 375 print(' *** check with a network administrator or use http://www.whatismyproxy.com/\n')
Note: See TracChangeset
for help on using the changeset viewer.