Changeset 2925 for trunk/GSASIIpath.py


Ignore:
Timestamp:
Jul 8, 2017 3:45:15 PM (6 years ago)
Author:
toby
Message:

add switch to 2frame; allow for latest G2path

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpath.py

    r2904 r2925  
    231231    return d
    232232
     233svnLastError = ''
    233234def svnGetRev(fpath=os.path.split(__file__)[0],local=True):
    234235    '''Obtain the version number for the either the last update of the local version
     
    243244    :Returns: the version number as an str or
    244245       None if there is a subversion error (likely because the path is
    245        not a repository or svn is not found)
     246       not a repository or svn is not found). The error message is placed in
     247       global variable svnLastError
    246248    '''
    247249
     
    261263        print 'svn failed\n',out
    262264        print 'err=',err
     265        global svnLastError
     266        svnLastError = err
    263267        return None
    264268    x = ET.fromstring(out)
     
    342346        print err
    343347           
    344 def svnUpdateProcess(version=None,projectfile=None):
     348def svnUpdateProcess(version=None,projectfile=None,branch=None):
    345349    '''perform an update of GSAS-II in a separate python process'''
    346350    if not projectfile:
     
    349353        projectfile = os.path.realpath(projectfile)
    350354        print 'restart using',projectfile
    351     if not version:
     355    if branch:
     356        version = branch
     357    elif not version:
    352358        version = ''
    353359    else:
     
    493499    svnSwitchDir('bindist','',distdir,verbose=verbose)
    494500    return os.path.join(path2GSAS2,'bindist')
     501
     502def svnTestBranch(loc=None):
     503    '''Returns the name of the branch directory if the installation has been switched.
     504    Returns none, if not a branch
     505    the test 2frame branch. False otherwise
     506    '''
     507    if loc is None: loc = path2GSAS2
     508    svn = whichsvn()
     509    if not svn:
     510        print('**** unable to load files: svn not found ****')
     511        return ''
     512    cmd = [svn, 'info', loc]
     513    if proxycmds: cmd += proxycmds
     514    p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     515    res,err = p.communicate()
     516    for l in res.split('\n'):
     517        if "Relative URL:" in l: break
     518    if "/branch/" in l:
     519        return l[l.find("/branch/")+8:].strip()
     520    else:
     521        return None
     522   
     523def svnSwitch2branch(branch=None,loc=None,svnHome=None):
     524    '''Switch to a subversion branch if specified. Switches to trunk otherwise.
     525    '''
     526    if svnHome is None: svnHome = g2home
     527    svnURL = svnHome + '/trunk'
     528    if branch:
     529        if svnHome.endswith('/'):
     530            svnURL = svnHome[:-1]
     531        else:
     532            svnURL = svnHome
     533        if branch.startswith('/'):
     534            svnURL += branch
     535        else:
     536            svnURL += '/' + branch
     537    svnSwitchDir('','',svnURL,loadpath=loc)
     538   
    495539
    496540def IPyBreak_base():
     
    607651        print("  "+files)
    608652        print("*"*75)
    609 ################################################################################
    610 # commands below are executed during the first import of this file
    611 ################################################################################
    612 # Add location of GSAS-II shared libraries (binaries: .so or .pyd files) to path
    613 binpath = None
    614 for loc in os.path.abspath(sys.path[0]),os.path.abspath(os.path.split(__file__)[0]):
    615     # Look at bin directory (created by a local compile) before standard dist
    616     # that at the top of the path
    617     for d in 'bin','bindist':
    618         if not d: continue
    619         fpth = os.path.join(loc,d)
    620         if TestSPG(fpth):
    621             binpath = fpth
    622             break       
    623     if binpath: break
    624 if binpath:                                            # were GSAS-II binaries found
    625     sys.path.insert(0,binpath)
    626     print('GSAS-II binary directory: {}'.format(binpath))
    627 else:                                                  # try loading them
    628     print('Attempting to download GSAS-II binary files...')
    629     try:
    630         binpath = DownloadG2Binaries(g2home)
    631     except AttributeError:
    632         print('Problem with download')
    633     if binpath and TestSPG(binpath):
    634         print('GSAS-II binary directory: {}'.format(binpath))
    635         sys.path.insert(0,binpath)
    636     #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    637     #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    638     # patch: use old location based on the host OS and the python version, 
    639     # path is relative to location of the script that is called as well as this file
    640     # this must be imported before anything that imports any .pyd/.so file for GSASII
    641     else:
    642         print('\n'+75*'*')
    643         print('  Warning. Using an old-style GSAS-II binary library. This is unexpected')
    644         print('  and will break in future GSAS-II versions. Please contact toby@anl.gov')
    645         print('  so we can learn what is not working on your installation.')
    646         bindir = None
    647         if sys.platform == "win32":
    648             if platform.architecture()[0] == '64bit':
    649                 bindir = 'binwin64-%d.%d' % sys.version_info[0:2]
    650             else:
    651                 bindir = 'binwin%d.%d' % sys.version_info[0:2]
    652         elif sys.platform == "darwin":
    653             if platform.architecture()[0] == '64bit':
    654                 bindir = 'binmac64-%d.%d' % sys.version_info[0:2]
    655             else:
    656                 bindir = 'binmac%d.%d' % sys.version_info[0:2]
    657             #if platform.mac_ver()[0].startswith('10.5.'):
    658             #    bindir += '_10.5'
    659         elif sys.platform == "linux2":
    660             if platform.architecture()[0] == '64bit':
    661                 bindir = 'binlinux64-%d.%d' % sys.version_info[0:2]
    662             else:
    663                 bindir = 'binlinux%d.%d' % sys.version_info[0:2]
    664         for loc in os.path.abspath(sys.path[0]),os.path.abspath(os.path.split(__file__)[0]):
     653
     654BinaryPathLoaded = False
     655def SetBinaryPath():
     656    '''
     657    Add location of GSAS-II shared libraries (binaries: .so or .pyd files) to path
     658   
     659    This routine must be executed after GSASIIpath is imported and before any other
     660    GSAS-II imports are done.
     661    '''
     662    # do this only once no matter how many times it is called
     663    global BinaryPathLoaded
     664    if BinaryPathLoaded: return
     665    BinaryPathLoaded = True
     666    binpath = None
     667    for loc in os.path.abspath(sys.path[0]),os.path.abspath(os.path.split(__file__)[0]):
    665668        # Look at bin directory (created by a local compile) before standard dist
    666669        # that at the top of the path
    667             fpth = os.path.join(loc,bindir)
     670        for d in 'bin','bindist':
     671            if not d: continue
     672            fpth = os.path.join(loc,d)
    668673            if TestSPG(fpth):
    669674                binpath = fpth
    670                 sys.path.insert(0,binpath)
    671                 print('GSAS-II binary directory: {}'.format(binpath))
     675                break       
     676        if binpath: break
     677    if binpath:                                            # were GSAS-II binaries found
     678        sys.path.insert(0,binpath)
     679        print('GSAS-II binary directory: {}'.format(binpath))
     680    else:                                                  # try loading them
     681        print('Attempting to download GSAS-II binary files...')
     682        try:
     683            binpath = DownloadG2Binaries(g2home)
     684        except AttributeError:   # this happens when building in Read The Docs
     685            print('Problem with download')
     686        if binpath and TestSPG(binpath):
     687            print('GSAS-II binary directory: {}'.format(binpath))
     688            sys.path.insert(0,binpath)
     689        # this must be imported before anything that imports any .pyd/.so file for GSASII
     690        else:
     691            #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     692            #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     693            # patch: use old location based on the host OS and the python version, 
     694            # path is relative to location of the script that is called as well as this file
     695            bindir = None
     696            if sys.platform == "win32":
     697                if platform.architecture()[0] == '64bit':
     698                    bindir = 'binwin64-%d.%d' % sys.version_info[0:2]
     699                else:
     700                    bindir = 'binwin%d.%d' % sys.version_info[0:2]
     701            elif sys.platform == "darwin":
     702                if platform.architecture()[0] == '64bit':
     703                    bindir = 'binmac64-%d.%d' % sys.version_info[0:2]
     704                else:
     705                    bindir = 'binmac%d.%d' % sys.version_info[0:2]
     706                #if platform.mac_ver()[0].startswith('10.5.'):
     707                #    bindir += '_10.5'
     708            elif sys.platform == "linux2":
     709                if platform.architecture()[0] == '64bit':
     710                    bindir = 'binlinux64-%d.%d' % sys.version_info[0:2]
     711                else:
     712                    bindir = 'binlinux%d.%d' % sys.version_info[0:2]
     713            for loc in os.path.abspath(sys.path[0]),os.path.abspath(os.path.split(__file__)[0]):
     714            # Look at bin directory (created by a local compile) before standard dist
     715            # that at the top of the path
     716                fpth = os.path.join(loc,bindir)
     717                binpath = fpth
     718                if TestSPG(fpth):
     719                    sys.path.insert(0,binpath)
     720                    print('\n'+75*'*')
     721                    print('  Warning. Using an old-style GSAS-II binary library. This is unexpected')
     722                    print('  and will break in future GSAS-II versions. Please contact toby@anl.gov')
     723                    print('  so we can learn what is not working on your installation.')
     724                    print('GSAS-II binary directory: {}'.format(binpath))
     725                    print(75*'*')
     726                    break
     727            else:
     728            # end patch
     729            #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     730            #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    672731                print(75*'*')
    673                 break
    674         else:
    675     #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    676             raise Exception,"**** ERROR GSAS-II binary libraries not found, GSAS-II cannot run ****"
    677 
    678 # add the data import and export directory to the search path
    679 newpath = os.path.join(path2GSAS2,'imports')
    680 if newpath not in sys.path: sys.path.append(newpath)
    681 newpath = os.path.join(path2GSAS2,'exports')
    682 if newpath not in sys.path: sys.path.append(newpath)
    683 
    684 # setup read of config.py, if present
    685 try:
    686     import config
    687     configDict = config.__dict__
    688     import inspect
    689     vals = [True for i in inspect.getmembers(config) if '__' not in i[0]]
    690     print str(len(vals))+' values read from config file '+os.path.abspath(config.__file__)
    691 except ImportError:
    692     configDict = {'Clip_on':True}
    693 except Exception as err:
    694     print("Error importing config.py file: "+str(err))
    695     configDict = {'Clip_on':True}
     732                print('Use of GSAS-II binary directory {} failed!'.format(binpath))
     733                print(75*'*')
     734                raise Exception,"**** ERROR GSAS-II binary libraries not found, GSAS-II cannot run ****"
     735
     736    # add the data import and export directory to the search path
     737    newpath = os.path.join(path2GSAS2,'imports')
     738    if newpath not in sys.path: sys.path.append(newpath)
     739    newpath = os.path.join(path2GSAS2,'exports')
     740    if newpath not in sys.path: sys.path.append(newpath)
     741
     742    # setup read of config.py, if present
     743    global configDict
     744    try:
     745        import config
     746        configDict = config.__dict__
     747        import inspect
     748        vals = [True for i in inspect.getmembers(config) if '__' not in i[0]]
     749        print str(len(vals))+' values read from config file '+os.path.abspath(config.__file__)
     750    except ImportError:
     751        configDict = {'Clip_on':True}
     752    except Exception as err:
     753        print("Error importing config.py file: "+str(err))
     754        configDict = {'Clip_on':True}
    696755
    697756if __name__ == '__main__':
     
    703762    project,version = sys.argv[1:3]
    704763    loc = os.path.dirname(__file__)
    705     if version:
     764    if version == 'trunk':
     765        svnSwitch2branch('')
     766    elif '/' in version:
     767        svnSwitch2branch(version)
     768    elif version:
    706769        print("Regress to version "+str(version))
    707770        svnUpdateDir(loc,version=version)
     
    709772        print("Update to current version")
    710773        svnUpdateDir(loc)
     774    ex = sys.executable
     775    if sys.platform == "darwin": # mac requires pythonw which is not always reported as sys.executable
     776        if os.path.exists(ex+'w'): ex += 'w'
    711777    if project:
    712778        print("Restart GSAS-II with project file "+str(project))
    713         subprocess.Popen([sys.executable,os.path.join(loc,'GSASII.py'),project])
     779        subprocess.Popen([ex,os.path.join(loc,'GSASII.py'),project])
    714780    else:
    715781        print("Restart GSAS-II without a project file ")
    716         subprocess.Popen([sys.executable,os.path.join(loc,'GSASII.py')])
     782        subprocess.Popen([ex,os.path.join(loc,'GSASII.py')])
    717783    print 'exiting update process'
    718784    sys.exit()
Note: See TracChangeset for help on using the changeset viewer.