Changeset 2952


Ignore:
Timestamp:
Jul 30, 2017 7:37:08 PM (6 years ago)
Author:
toby
Message:

GSASII installation: support downloading of all binaries

Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • branch/2frame/GSASIIpath.py

    r2936 r2952  
    2828   
    2929path2GSAS2 = os.path.dirname(os.path.realpath(__file__)) # location of this file; save before any changes in pwd
     30
     31# convert version numbers as '1.2.3' to integers (1002) and back (to 1.2)
     32fmtver = lambda v: str(v//1000)+'.'+str(v%1000)
     33intver = lambda vs: sum([int(i) for i in vs.split('.')[0:2]]*np.array((1000,1)))
    3034
    3135def GetConfigValue(key,default=None):
     
    432436    print ("Files installed at: "+loadpath)
    433437    return True
    434            
    435 def DownloadG2Binaries(g2home,verbose=True):
    436     '''Download GSAS-II binaries from appropriate section of the
    437     GSAS-II svn repository based on the platform, numpy and Python
    438     version
    439     '''
    440     # convert version numbers as '1.2.3' to integers (1002) and back (to 1.2)
    441     fmtver = lambda v: str(v//1000)+'.'+str(v%1000)
    442     intver = lambda vs: sum([int(i) for i in vs.split('.')[0:2]]*np.array((1000,1)))
    443    
     438
     439def GetBinaryPrefix():
    444440    if sys.platform == "win32":
    445441        prefix = 'win'
     
    456452        bits = '32'
    457453
    458     # format current python & numpy versions
     454    # format current python version
    459455    pyver = 'p{}.{}'.format(*sys.version_info[0:2])
    460     npver = 'n{}.{}'.format(*np.__version__.split('.')[0:2])
     456
     457    items = [prefix,bits,pyver]
     458    return '_'.join(items)
     459
     460def DownloadG2Binaries(g2home,verbose=True):
     461    '''Download GSAS-II binaries from appropriate section of the
     462    GSAS-II svn repository based on the platform, numpy and Python
     463    version
     464    '''   
     465    bindir = GetBinaryPrefix()
     466    #npver = 'n{}.{}'.format(*np.__version__.split('.')[0:2])
    461467    inpver = intver(np.__version__)
    462 
    463     items = [prefix,bits,pyver]
    464     bindir = '_'.join(items)
    465 
    466468    svn = whichsvn()
    467469    if not svn:
     
    669671    global BinaryPathLoaded
    670672    if BinaryPathLoaded: return
    671     BinaryPathLoaded = True
     673    inpver = intver(np.__version__)
    672674    binpath = None
     675    binprfx = GetBinaryPrefix()
    673676    for loc in os.path.abspath(sys.path[0]),os.path.abspath(os.path.split(__file__)[0]):
    674         # Look at bin directory (created by a local compile) before standard dist
    675         # that at the top of the path
    676         for d in 'bin','bindist':
    677             if not d: continue
    678             fpth = os.path.join(loc,d)
     677        # Look at bin directory (created by a local compile) before looking for standard dist files
     678        searchpathlist = [os.path.join(loc,'bin')]
     679        # also look for matching binary dist in loc/AllBinaries
     680        versions = {}
     681        for d in glob.glob(os.path.join(loc,'AllBinaries',binprfx+'*')):
     682            v = intver(d.rstrip('/').split('_')[3].lstrip('n'))
     683            versions[v] = d
     684        searchpathlist = [os.path.join(loc,'bin')]
     685        vmin = None
     686        vmax = None
     687        for v in sorted(versions.keys()):
     688            if v <= inpver:
     689                vmin = v
     690            elif v > inpver:
     691                vmax = v
     692                break
     693        if vmin in versions:
     694            searchpathlist.append(versions[vmin])
     695        if vmax in versions:
     696            searchpathlist.append(versions[vmax])
     697        searchpathlist.append(os.path.join(loc,'bindist'))
     698        for fpth in searchpathlist:
    679699            if TestSPG(fpth):
    680700                binpath = fpth
     
    684704        sys.path.insert(0,binpath)
    685705        print('GSAS-II binary directory: {}'.format(binpath))
     706        BinaryPathLoaded = True
    686707    else:                                                  # try loading them
    687708        print('Attempting to download GSAS-II binary files...')
     
    693714            print('GSAS-II binary directory: {}'.format(binpath))
    694715            sys.path.insert(0,binpath)
     716            BinaryPathLoaded = True
    695717        # this must be imported before anything that imports any .pyd/.so file for GSASII
    696718        else:
     
    699721            # patch: use old location based on the host OS and the python version, 
    700722            # path is relative to location of the script that is called as well as this file
     723            BinaryPathLoaded = True
    701724            bindir = None
    702725            if sys.platform == "win32":
  • install/bootstrap.py

    r2887 r2952  
    231231print('\n'+75*'*')
    232232print(msg + u' from ' + cmd[2])
    233 print('  *** If GSAS-II fails to be installed, you likely have a network access')
    234 print('  *** problem, most commonly because you need to use a network proxy. Please')
    235 print('  *** check with a network administrator or use http://www.whatismyproxy.com/\n')
    236233print 'svn load command:'
    237234for item in cmd: print item,
    238235print ""
    239 p = subprocess.call(cmd)
    240 if p:
    241     print 'subversion returned an error; Retrying with command for older version...'
     236s = subprocess.Popen(cmd,stderr=subprocess.PIPE)
     237print('\nsubversion output:')
     238out,err = s.communicate()
     239if err:
     240    print('subversion returned an error:')
     241    print(err)
     242    print('Retrying with command for older svn version...')
    242243    cmd = [svn, 'co', g2home+ 'trunk/', gsaspath]
    243244    if proxycmds: cmd += proxycmds
    244245    for item in cmd: print item,
    245246    print ""
    246     p = subprocess.call(cmd)
     247    s = subprocess.Popen(cmd,stderr=subprocess.PIPE)
     248    out,err = s.communicate()
     249    if err:
     250        print('subversion returned an error:')
     251        print(err)
     252        print('  *** GSAS-II failed to be installed: you likely have a network access')
     253        print('  *** problem, most commonly because you need to use a network proxy. Please')
     254        print('  *** check with a network administrator or use http://www.whatismyproxy.com/\n')
     255        sys.exit()
    247256print('\n'+75*'*')
    248257
    249 #===========================================================================
    250 # test if the compiled files load correctly
    251 #===========================================================================
    252258try:
    253259    import GSASIIpath
     
    261267    sys.exit()
    262268
     269for a in sys.argv[1:]:
     270    if 'allbin' in a.lower() or 'server' in a.lower():
     271        print('Loading all binaries with command...')
     272        if not GSASIIpath.svnSwitchDir('AllBinaries','',g2home+ 'Binaries/',None,True):
     273            print('Binary load failed')
     274            sys.exit()
     275        break
     276else:
     277    GSASIIpath.DownloadG2Binaries(g2home)
     278       
     279#===========================================================================
     280# test if the compiled files load correctly
     281#===========================================================================
     282
    263283script = """  # commands that test each module can at least be loaded & run something in pyspg
    264284try:
    265285    import GSASIIpath
     286    GSASIIpath.SetBinaryPath()
    266287    import pyspg
    267288    import histogram2d
     
    274295    pass
    275296"""
    276 p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     297p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE,stderr=subprocess.PIPE,
     298                     cwd=gsaspath)
    277299res,err = p.communicate()
    278300if '==OK==' not in res or p.returncode != 0:
     
    313335elif sys.platform.startswith('darwin') and os.path.exists(
    314336    os.path.join(gsaspath,"makeMacApp.py")):
    315     print('running '+os.path.join(gsaspath,"makeMacApp.py"))
    316     execfile(os.path.join(gsaspath,"makeMacApp.py"))
     337    sys.argv = [os.path.join(gsaspath,"makeMacApp.py")]
     338    print(u'running '+sys.argv[0])
     339    execfile(sys.argv[0])
    317340#===========================================================================
    318341# On linux, make desktop icon
Note: See TracChangeset for help on using the changeset viewer.