Ignore:
Timestamp:
Mar 19, 2020 4:27:06 PM (4 years ago)
Author:
toby
Message:

update bootstrap to use all proxy options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • install/g2complete/src/bootstrap.py

    • Property svn:keywords set to Date Author Revision URL Id
    r4261 r4376  
    55import os, stat, sys, platform, subprocess, datetime
    66
    7 version = "$Id: bootstrap.py 3515 2018-07-30 02:14:14Z toby $"
     7version = "$Id$"
    88g2home = 'https://subversion.xray.aps.anl.gov/pyGSAS/'
    99path2GSAS2 = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
     
    6969    else:
    7070        print("BOOTSTRAP WARNING: ",file=sys.stderr)
    71         print(msg.replace('\n',' '),file=sys.stderr)
    72         print(" Recreate this using command: {} {} {}".format(
     71        for line in msg.split('\n'):
     72            print(line,file=sys.stderr)
     73        print("Recreate this using command:")
     74        print("     {} {} {}".format(
    7375            os.path.abspath(sys.executable),
    7476            os.path.abspath(os.path.expanduser(__file__)),
     
    110112    '''Loads a proxy for subversion from the file created by bootstrap.py
    111113    '''
    112     proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt")
    113     if os.path.exists(proxyinfo):
    114         global proxycmds
    115         global host,port  # only in bootstrap.py
    116         proxycmds = []
    117         fp = open(proxyinfo,'r')
     114    global proxycmds
     115    proxycmds = []
     116    proxyinfo = os.path.join(os.path.expanduser('~/.G2local/'),"proxyinfo.txt")
     117    if not os.path.exists(proxyinfo):
     118        proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt")
     119    if not os.path.exists(proxyinfo):
     120        return '','',''
     121    fp = open(proxyinfo,'r')
     122    host = fp.readline().strip()
     123    # allow file to begin with comments
     124    while host.startswith('#'):
    118125        host = fp.readline().strip()
    119         port = fp.readline().strip()
    120         fp.close()
    121         setsvnProxy(host,port)
    122         if not host.strip(): return '',''
    123         return host,port
    124     return '',''
    125 
    126 def setsvnProxy(host,port):
     126    port = fp.readline().strip()
     127    etc = []
     128    line = fp.readline()
     129    while line:
     130        etc.append(line.strip())
     131        line = fp.readline()
     132    fp.close()
     133    setsvnProxy(host,port,etc)
     134    return host,port,etc
     135
     136def setsvnProxy(host,port,etc=[]):
    127137    '''Sets the svn commands needed to use a proxy
    128138    '''
     
    131141    host = host.strip()
    132142    port = port.strip()
    133     if not host.strip(): return
    134     proxycmds.append('--config-option')
    135     proxycmds.append('servers:global:http-proxy-host='+host)
    136     if port.strip():
     143    if host:
    137144        proxycmds.append('--config-option')
    138         proxycmds.append('servers:global:http-proxy-port='+port)
     145        proxycmds.append('servers:global:http-proxy-host='+host)
     146        if port:
     147            proxycmds.append('--config-option')
     148            proxycmds.append('servers:global:http-proxy-port='+port)
     149    for item in etc:
     150        proxycmds.append(item)
    139151       
    140152def whichsvn():
     
    153165    svnprog = 'svn'
    154166    if sys.platform.startswith('win'): svnprog += '.exe'
    155     host,port = getsvnProxy()
     167    host,port,etc = getsvnProxy()
    156168    if GetConfigValue('debug') and host:
    157169        print('DBG_Using proxy host {} port {}'.format(host,port))
     
    269281print('Ready to bootstrap GSAS-II from repository\n\t'+g2home+'\nto '+path2GSAS2)
    270282proxycmds = []
    271 proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt")
    272 if os.path.exists(proxyinfo):
    273     fp = open(proxyinfo,'r')
    274     host = fp.readline().strip()
    275     port = fp.readline().strip()
    276     fp.close()
    277     os.remove(proxyinfo)
    278 print(70*"=")
     283host,port,etc = getsvnProxy()
    279284if sys.version_info[0] == 2:
    280285    getinput = raw_input
     
    282287    getinput = input
    283288
    284 # get proxy from environment variable
     289# get proxy setting from environment variable
    285290key = None
    286291for i in os.environ.keys():
     
    311316        host = ""
    312317    elif host:
     318        print('\n'+75*'*')
    313319        ans = getinput("Enter the proxy address (type none to remove) ["+host+"]: ").strip()
    314320        if ans.lower() == "none": host = ""
     
    320326        if ans == "": ans=port
    321327        port = ans
     328        print('If your site needs additional svn commands (such as \n\t',
     329                  '--config-option servers:global:http-proxy-username=*account*','\n\t',
     330                  '--config-option servers:global:http-proxy-password=*password*',
     331                  '\nenter them now:')
     332        if etc:
     333            prevetc = ' '.join(etc)
     334            print('\nDefault for next input is "{}"'.format(prevetc))
     335            prompt = "Enter additional svn options (if any) [use previous]: "
     336        else:
     337            prompt = "Enter additional svn options (if any) [none]: "
     338        ans = 'start'
     339        etcstr = ''
     340        while ans:
     341            ans = getinput(prompt).strip()
     342            prompt = "more svn options (if any): "
     343            if etcstr: etcstr += ' '
     344            etcstr += ans
     345        if etcstr.strip():
     346           etc = etcstr.split()
    322347except EOFError:
    323348    host = ""
    324349    port = ""
     350    etc = []
     351setsvnProxy(host,port,etc)
     352# delete old proxy files
     353localproxy = os.path.join(os.path.expanduser('~/.G2local/'),"proxyinfo.txt")
     354for proxyinfo in localproxy,os.path.join(path2GSAS2,"proxyinfo.txt"):
     355    if os.path.exists(proxyinfo):
     356        try:
     357            os.remove(proxyinfo)
     358            print('Deleted file {}'.format(proxyinfo))
     359        except:
     360            pass
    325361if host:
    326     proxycmds.append('--config-option')
    327     proxycmds.append('servers:global:http-proxy-host='+host.strip())
    328     if port:
    329         proxycmds.append('--config-option')
    330         proxycmds.append('servers:global:http-proxy-port='+port.strip())
    331     fp = open(proxyinfo,'w')
    332     fp.write(host.strip()+'\n')
    333     fp.write(port.strip()+'\n')
    334     fp.close()
    335     fp = open(os.path.join(path2GSAS2,'bootstrap.log'),'a')
    336     fp.write('Proxy info written: {} port\n'.format(host,port))
    337     print('Proxy info written: {} port'.format(host,port))
    338     fp.close()
    339 
     362    try:
     363        fp = open(proxyinfo,'w')
     364    except:
     365        fp = open(localproxy,'w')
     366        proxyinfo = localproxy
     367    try:
     368        fp.write(host.strip()+'\n')
     369        fp.write(port.strip()+'\n')
     370        for i in etc:
     371            if i.strip():
     372                fp.write(i.strip()+'\n')
     373        fp.close()
     374        msg = 'Proxy info written: {} port {} etc {}\n'.format(host,port,etc)
     375        print(msg)
     376        fp = open(os.path.join(path2GSAS2,'bootstrap.log'),'a')
     377        fp.write(msg)
     378        fp.close()
     379    except Exception as err:
     380        print('Error writing file {}:\n{}'.format(proxyinfo,err))
    340381if not skipDownloadSteps:
    341382    # patch: switch GSAS-II location if linked to XOR server (relocated May/June 2017)
     
    412453            if os.path.exists(os.path.join(path2GSAS2,"makeBat.py")):
    413454                msg += '\n\nGSAS-II failed to be updated. A likely reason is a network access'
    414                 msg += '\nproblem. If your web browser works, but the update did not,'
    415                 msg += '\nthe most common reason is you need to use a network proxy. Please'
     455                msg += '\nproblem. If your web browser works, but the update did not.'
     456                msg += '\nThe most common reason is you need to use a network proxy. Please'
    416457                msg += '\ncheck with a network administrator or use http://www.whatismyproxy.com/'
    417458            else:
     
    420461                msg += '\n\n  *** GSAS-II failed to be installed. A likely reason is a network access'
    421462                msg += '\n  *** problem, most commonly because you need to use a network proxy. Please'
    422                 msg += '  *** check with a network administrator or use http://www.whatismyproxy.com/\n'
     463                msg += '\n  *** check with a network administrator or use http://www.whatismyproxy.com/\n'
    423464            BailOut(msg)
    424465    print('\n'+75*'*')
Note: See TracChangeset for help on using the changeset viewer.