Changeset 4376


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

update bootstrap to use all proxy options

Location:
install
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • install/bootstrap.py

    r4242 r4376  
    1818    if 'noinstall' in a.lower():
    1919        skipInstallSteps = True
    20         showWXerror = True
     20        if sys.platform.startswith('win'): showWXerror = True
    2121    elif 'nonet' in a.lower():
    2222        skipDownloadSteps = True
     
    5555def BailOut(msg):
    5656    '''Exit with an error message. Use a GUI to show the error when
    57     showWXerror == True (when --noinstall is specified)
     57    showWXerror == True (on windows when --noinstall is specified)
    5858    '''
    5959    print(msg)
     
    6767        dlg.ShowModal()
    6868        dlg.Destroy()
     69    else:
     70        print("BOOTSTRAP WARNING: ",file=sys.stderr)
     71        for line in msg.split('\n'):
     72            print(line,file=sys.stderr)
     73        print("Recreate this using command:")
     74        print("     {} {} {}".format(
     75            os.path.abspath(sys.executable),
     76            os.path.abspath(os.path.expanduser(__file__)),
     77            ' '.join(sys.argv[1:]),
     78        ),file=sys.stderr)
    6979    sys.exit()
    7080       
     
    102112    '''Loads a proxy for subversion from the file created by bootstrap.py
    103113    '''
    104     proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt")
    105     if os.path.exists(proxyinfo):
    106         global proxycmds
    107         global host,port  # only in bootstrap.py
    108         proxycmds = []
    109         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('#'):
    110125        host = fp.readline().strip()
    111         port = fp.readline().strip()
    112         fp.close()
    113         setsvnProxy(host,port)
    114         if not host.strip(): return '',''
    115         return host,port
    116     return '',''
    117 
    118 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=[]):
    119137    '''Sets the svn commands needed to use a proxy
    120138    '''
     
    123141    host = host.strip()
    124142    port = port.strip()
    125     if not host.strip(): return
    126     proxycmds.append('--config-option')
    127     proxycmds.append('servers:global:http-proxy-host='+host)
    128     if port.strip():
     143    if host:
    129144        proxycmds.append('--config-option')
    130         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)
    131151       
    132152def whichsvn():
     
    145165    svnprog = 'svn'
    146166    if sys.platform.startswith('win'): svnprog += '.exe'
    147     host,port = getsvnProxy()
     167    host,port,etc = getsvnProxy()
    148168    if GetConfigValue('debug') and host:
    149169        print('DBG_Using proxy host {} port {}'.format(host,port))
     
    261281print('Ready to bootstrap GSAS-II from repository\n\t'+g2home+'\nto '+path2GSAS2)
    262282proxycmds = []
    263 proxyinfo = os.path.join(path2GSAS2,"proxyinfo.txt")
    264 if os.path.exists(proxyinfo):
    265     fp = open(proxyinfo,'r')
    266     host = fp.readline().strip()
    267     port = fp.readline().strip()
    268     fp.close()
    269     os.remove(proxyinfo)
    270 print(70*"=")
     283host,port,etc = getsvnProxy()
    271284if sys.version_info[0] == 2:
    272285    getinput = raw_input
     
    274287    getinput = input
    275288
    276 # get proxy from environment variable
     289# get proxy setting from environment variable
    277290key = None
    278291for i in os.environ.keys():
     
    303316        host = ""
    304317    elif host:
     318        print('\n'+75*'*')
    305319        ans = getinput("Enter the proxy address (type none to remove) ["+host+"]: ").strip()
    306320        if ans.lower() == "none": host = ""
     
    312326        if ans == "": ans=port
    313327        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()
    314347except EOFError:
    315348    host = ""
    316349    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
    317361if host:
    318     proxycmds.append('--config-option')
    319     proxycmds.append('servers:global:http-proxy-host='+host.strip())
    320     if port:
    321         proxycmds.append('--config-option')
    322         proxycmds.append('servers:global:http-proxy-port='+port.strip())
    323     fp = open(proxyinfo,'w')
    324     fp.write(host.strip()+'\n')
    325     fp.write(port.strip()+'\n')
    326     fp.close()
    327     fp = open(os.path.join(path2GSAS2,'bootstrap.log'),'a')
    328     fp.write('Proxy info written: {} port\n'.format(host,port))
    329     print('Proxy info written: {} port'.format(host,port))
    330     fp.close()
    331 
     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))
    332381if not skipDownloadSteps:
    333382    # patch: switch GSAS-II location if linked to XOR server (relocated May/June 2017)
     
    407456                msg += '\nThe most common reason is you need to use a network proxy. Please'
    408457                msg += '\ncheck with a network administrator or use http://www.whatismyproxy.com/'
    409             else:               
     458            else:
     459                # this will happen only with initial installs where all files
     460                # are to be downloaded (not gsas2full or updates)
    410461                msg += '\n\n  *** GSAS-II failed to be installed. A likely reason is a network access'
    411462                msg += '\n  *** problem, most commonly because you need to use a network proxy. Please'
    412                 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'
    413464            BailOut(msg)
    414465    print('\n'+75*'*')
     
    425476    print('Loading all binaries with command...')
    426477    if not GSASIIpath.svnSwitchDir('AllBinaries','',g2home+ 'Binaries/',None,True):
    427         msg = 'Binary load failed'
     478        msg = 'Binary load failed. Subversion problem? Please seek help'
    428479        BailOut(msg)
    429480else:
     
    461512        msg += err
    462513    #print('\nAttempting to open a web page on compiling GSAS-II...')
    463     msg += '\n\nPlease see web page\nhttps://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII'
     514    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.)'
    464515    BailOut(msg)
    465516    #import webbrowser
  • 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.