Changeset 2887 for install/bootstrap.py


Ignore:
Timestamp:
Jun 29, 2017 5:54:41 PM (6 years ago)
Author:
toby
Message:

setup & use bindist location for downloaded binaries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • install/bootstrap.py

    r2866 r2887  
    33# works for Mac & Linux & Windows
    44import os, stat, sys, platform, subprocess
    5 home = 'https://subversion.xray.aps.anl.gov/pyGSAS/'
     5
     6g2home = 'https://subversion.xray.aps.anl.gov/pyGSAS/'
     7################################################################################
     8################################################################################
     9# routines copied from GSASIIpath.py
     10proxycmds = []
     11'Used to hold proxy information for subversion, set if needed in whichsvn'
     12svnLocCache = None
     13'Cached location of svn to avoid multiple searches for it'
     14
     15def 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
     66def 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
     86def 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################################################################################
    6100print 70*'*'
    7101#testing for incorrect locale code'
     
    73167
    74168print '\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:
     169svn = whichsvn()
     170if not svn:
    104171    print "Sorry, subversion (svn) could not be found on your system."
    105172    print "Please install this or place in path and rerun this."
     
    113180    print 'done.'
    114181   
    115 print 'Ready to bootstrap GSAS-II from repository\n\t',home,'\nto '+gsaspath
     182print 'Ready to bootstrap GSAS-II from repository\n\t',g2home,'\nto '+gsaspath
    116183proxycmds = []
    117 if os.path.exists("proxyinfo.txt"):
    118     fp = open("proxyinfo.txt",'r')
    119     os.remove("proxyinfo.txt")
     184proxyinfo = os.path.join(gsaspath,"proxyinfo.txt")
     185host = None
     186port = '8080'
     187if 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)
    120193print(70*"=")
    121 ans = raw_input("Enter the proxy address [none needed]: ")
    122 if ans.strip() != "":
     194if host:
     195    ans = raw_input("Enter the proxy address (type none to remove) ["+host+"]: ")
     196    if ans.strip().lower() == "none": host = ans = ""
     197else:
     198    ans = raw_input("Enter the proxy address [none needed]: ")
     199if ans.strip() != "" or host:
    123200    proxycmds.append('--config-option')
     201    if ans.strip() == "": ans=host
    124202    proxycmds.append('servers:global:http-proxy-host='+ans.strip())
    125     fp = open("proxyinfo.txt",'w')
     203    fp = open(proxyinfo,'w')
    126204    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
    129207    proxycmds.append('--config-option')
    130208    proxycmds.append('servers:global:http-proxy-port='+ans.strip())
     
    132210    fp.close()
    133211
    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)
    154213cmd = [svn, 'info']
    155214p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     
    159218    cmd = [svn, 'switch','--relocate','https://subversion.xor.aps.anl.gov/pyGSAS',
    160219           'https://subversion.xray.aps.anl.gov/pyGSAS']
     220    if proxycmds: cmd += proxycmds
    161221    p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    162222    res,err = p.communicate()
     
    166226        print(res)
    167227       
    168 cmd = [svn, 'co', home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert']
     228cmd = [svn, 'co', g2home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert']
    169229if proxycmds: cmd += proxycmds
    170230msg = 'Now preparing to install GSAS-II'
     
    180240if p:
    181241    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]
    183243    if proxycmds: cmd += proxycmds
    184244    for item in cmd: print item,
    185245    print ""
    186246    p = subprocess.call(cmd)
     247print('\n'+75*'*')
    187248
    188249#===========================================================================
    189250# test if the compiled files load correctly
    190251#===========================================================================
    191 script = """
     252try:
     253    import GSASIIpath
     254    print('import of GSASIIpath completed')
     255except 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
     263script = """  # commands that test each module can at least be loaded & run something in pyspg
    192264try:
    193265    import GSASIIpath
     
    202274    pass
    203275"""
    204 p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE,cwd=gsaspath)
     276p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    205277res,err = p.communicate()
    206278if '==OK==' not in res or p.returncode != 0:
    207279    print('\n'+75*'=')
    208280    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...')
    210291    print('(https://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII)')
    211     print(75*'=')
    212     print('\n')
    213292    import webbrowser
    214293    webbrowser.open_new('https://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII')
     294    print(75*'=')
    215295    sys.exit()
    216296else:
Note: See TracChangeset for help on using the changeset viewer.