source: trunk/GSASIIpath.py @ 2901

Last change on this file since 2901 was 2901, checked in by toby, 4 years ago

try to fix Docs build

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 26.4 KB
Line 
1# -*- coding: utf-8 -*-
2'''
3*GSASIIpath: locations & updates*
4---------------------------------
5
6Routines for dealing with file locations, etc.
7
8Determines the location of the compiled (.pyd or .so) libraries.
9
10Interfaces with subversion (svn):
11Determine the subversion release number by determining the highest version number
12where :func:`SetVersionNumber` is called (best done in every GSASII file).
13Other routines will update GSASII from the subversion server if svn can be
14found.
15
16Accesses configuration options, as defined in config.py
17'''
18
19import os
20import sys
21import platform
22import glob
23import subprocess
24import numpy as np
25
26g2home = 'https://subversion.xray.aps.anl.gov/pyGSAS'
27'Define the location of the GSAS-II subversion repository'
28   
29path2GSAS2 = os.path.dirname(os.path.realpath(__file__)) # location of this file; save before any changes in pwd
30
31def GetConfigValue(key,default=None):
32    '''Return the configuration file value for key or a default value if not present
33   
34    :param str key: a value to be found in the configuration (config.py) file
35    :param default: a value to be supplied is none is in the config file or
36      the config file is not found. Defaults to None
37    :returns: the value found or the default.
38    '''
39    return configDict.get(key,default)
40
41def SetConfigValue(parmdict):
42    '''Set configuration variables from a dictionary where elements are lists
43    First item in list is the default value and second is the value to use.
44    '''
45    global configDict
46    for var in parmdict:
47        if var in configDict:
48            del configDict[var]
49        if parmdict[var][1] is None: continue
50        if parmdict[var][1] == '': continue
51        if parmdict[var][0] == parmdict[var][1]: continue
52        configDict[var] = parmdict[var][1]
53
54# routines for looking a version numbers in files
55version = -1
56def SetVersionNumber(RevString):
57    '''Set the subversion version number
58
59    :param str RevString: something like "$Revision: 2901 $"
60      that is set by subversion when the file is retrieved from subversion.
61
62    Place ``GSASIIpath.SetVersionNumber("$Revision: 2901 $")`` in every python
63    file.
64    '''
65    try:
66        RevVersion = int(RevString.split(':')[1].split()[0])
67        global version
68        version = max(version,RevVersion)
69    except:
70        pass
71       
72def GetVersionNumber():
73    '''Return the maximum version number seen in :func:`SetVersionNumber`
74    '''
75    if version > 1000:
76        return version
77    else:
78        return "unknown"
79
80def LoadConfigFile(filename):
81    '''Read a GSAS-II configuration file.
82    Comments (starting with "%") are removed, as are empty lines
83   
84    :param str filename: base file name (such as 'file.dat'). Files with this name
85      are located from the path and the contents of each are concatenated.
86    :returns: a list containing each non-empty (after removal of comments) line
87      found in every matching config file.
88    '''
89    info = []
90    for path in sys.path:
91        fil = os.path.join(path,filename)
92        if not os.path.exists(fil): continue
93        try:
94            i = 0
95            fp = open(fil,'r')
96            for line in fp:
97                expr = line.split('#')[0].strip()
98                if expr:
99                    info.append(expr)
100                    i += 1
101            print(str(i)+' lines read from config file '+fil)
102        finally:
103            fp.close()
104    return info
105
106
107# routines to interface with subversion
108proxycmds = []
109'Used to hold proxy information for subversion, set if needed in whichsvn'
110svnLocCache = None
111'Cached location of svn to avoid multiple searches for it'
112
113def whichsvn():
114    '''Returns a path to the subversion exe file, if any is found.
115    Searches the current path after adding likely places where GSAS-II
116    might install svn.
117
118    :returns: None if svn is not found or an absolute path to the subversion
119      executable file.
120    '''
121    # use a previosuly cached svn location
122    global svnLocCache
123    if svnLocCache: return svnLocCache
124    # prepare to find svn
125    is_exe = lambda fpath: os.path.isfile(fpath) and os.access(fpath, os.X_OK)
126    svnprog = 'svn'
127    if sys.platform.startswith('win'): svnprog += '.exe'
128    gsaspath = os.path.split(__file__)[0]
129    # check for a proxy
130    proxyinfo = os.path.join(gsaspath,"proxyinfo.txt")
131    if os.path.exists(proxyinfo):
132        global proxycmds
133        proxycmds = []
134        fp = open(proxyinfo,'r')
135        host = fp.readline().strip()
136        port = fp.readline().strip()
137        fp.close()
138        proxycmds.append('--config-option')
139        proxycmds.append('servers:global:http-proxy-host='+host)
140        proxycmds.append('--config-option')
141        proxycmds.append('servers:global:http-proxy-port='+port)
142    # add likely places to find subversion when installed with GSAS-II
143    pathlist = os.environ["PATH"].split(os.pathsep)
144    pathlist.append(os.path.split(sys.executable)[0])
145    pathlist.append(gsaspath)
146    for rpt in ('..','bin'),('..','Library','bin'),('svn','bin'),('svn',),('.'):
147        pt = os.path.normpath(os.path.join(gsaspath,*rpt))
148        if os.path.exists(pt):
149            pathlist.insert(0,pt)   
150    # search path for svn or svn.exe
151    for path in pathlist:
152        exe_file = os.path.join(path, svnprog)
153        if is_exe(exe_file):
154            try:
155                p = subprocess.Popen([exe_file,'help'],stdout=subprocess.PIPE)
156                res = p.stdout.read()
157                p.communicate()
158                svnLocCache = os.path.abspath(exe_file)
159                return svnLocCache
160            except:
161                pass       
162    svnLocCache = None
163
164def svnVersion(svn=None):
165    '''Get the version number of the current subversion executable
166
167    :returns: a string with a version number such as "1.6.6" or None if
168      subversion is not found.
169
170    '''
171    if not svn: svn = whichsvn()
172    if not svn: return
173
174    cmd = [svn,'--version','--quiet']
175    s = subprocess.Popen(cmd,
176                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
177    out,err = s.communicate()
178    if err:
179        print 'subversion error!\nout=',out
180        print 'err=',err
181        return None
182    return out.strip()
183
184def svnVersionNumber(svn=None):
185    '''Get the version number of the current subversion executable
186
187    :returns: a fractional version number such as 1.6 or None if
188      subversion is not found.
189
190    '''
191    ver = svnVersion(svn)
192    if not ver: return 
193    M,m = ver.split('.')[:2]
194    return int(M)+int(m)/10.
195
196def svnGetLog(fpath=os.path.split(__file__)[0],version=None):
197    '''Get the revision log information for a specific version of the specified package
198
199    :param str fpath: path to repository dictionary, defaults to directory where
200       the current file is located.
201    :param int version: the version number to be looked up or None (default)
202       for the latest version.
203
204    :returns: a dictionary with keys (one hopes) 'author', 'date', 'msg', and 'revision'
205
206    '''
207    import xml.etree.ElementTree as ET
208    svn = whichsvn()
209    if not svn: return
210    if version is not None:
211        vstr = '-r'+str(version)
212    else:
213        vstr = '-rHEAD'
214
215    cmd = [svn,'log',fpath,'--xml',vstr]
216    if proxycmds: cmd += proxycmds
217    s = subprocess.Popen(cmd,
218                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
219    out,err = s.communicate()
220    if err:
221        print 'out=',out
222        print 'err=',err
223        return None
224    x = ET.fromstring(out)
225    d = {}
226    for i in x.iter('logentry'):
227        d = {'revision':i.attrib.get('revision','?')}
228        for j in i:
229            d[j.tag] = j.text
230        break # only need the first
231    return d
232
233def svnGetRev(fpath=os.path.split(__file__)[0],local=True):
234    '''Obtain the version number for the either the last update of the local version
235    or contacts the subversion server to get the latest update version (# of Head).
236
237    :param str fpath: path to repository dictionary, defaults to directory where
238       the current file is located
239    :param bool local: determines the type of version number, where
240       True (default): returns the latest installed update
241       False: returns the version number of Head on the server
242
243    :Returns: the version number as an str or
244       None if there is a subversion error (likely because the path is
245       not a repository or svn is not found)
246    '''
247
248    import xml.etree.ElementTree as ET
249    svn = whichsvn()
250    if not svn: return
251    if local:
252        cmd = [svn,'info',fpath,'--xml']
253    else:
254        cmd = [svn,'info',fpath,'--xml','-rHEAD']
255    if svnVersionNumber() >= 1.6:
256        cmd += ['--non-interactive', '--trust-server-cert']
257    if proxycmds: cmd += proxycmds
258    s = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
259    out,err = s.communicate()
260    if err:
261        print 'svn failed\n',out
262        print 'err=',err
263        return None
264    x = ET.fromstring(out)
265    for i in x.iter('entry'):
266        rev = i.attrib.get('revision')
267        if rev: return rev
268
269def svnFindLocalChanges(fpath=os.path.split(__file__)[0]):
270    '''Returns a list of files that were changed locally. If no files are changed,
271       the list has length 0
272
273    :param fpath: path to repository dictionary, defaults to directory where
274       the current file is located
275
276    :returns: None if there is a subversion error (likely because the path is
277       not a repository or svn is not found)
278
279    '''
280    import xml.etree.ElementTree as ET
281    svn = whichsvn()
282    if not svn: return
283    cmd = [svn,'status',fpath,'--xml']
284    if proxycmds: cmd += proxycmds
285    s = subprocess.Popen(cmd,
286                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
287    out,err = s.communicate()
288    if err: return None
289    x = ET.fromstring(out)
290    changed = []
291    for i in x.iter('entry'):
292        if i.find('wc-status').attrib.get('item') == 'modified': 
293            changed.append(i.attrib.get('path'))
294    return changed
295
296def svnUpdateDir(fpath=os.path.split(__file__)[0],version=None):
297    '''This performs an update of the files in a local directory from a server.
298
299    :param str fpath: path to repository dictionary, defaults to directory where
300       the current file is located
301    :param version: the number of the version to be loaded. Used only
302       cast as a string, but should be an integer or something that corresponds to a
303       string representation of an integer value when cast. A value of None (default)
304       causes the latest version on the server to be used.
305    '''
306    svn = whichsvn()
307    if not svn: return
308    if version:
309        verstr = '-r' + str(version)
310    else:
311        verstr = '-rHEAD'
312    cmd = [svn,'update',fpath,verstr,
313           '--non-interactive',
314           '--accept','theirs-conflict','--force']
315    if svnVersionNumber() >= 1.6:
316        cmd += ['--trust-server-cert']
317    if proxycmds: cmd += proxycmds
318    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
319    out,err = s.communicate()
320    if err:
321        print(60*"=")
322        print ("****** An error was noted, see below *********")
323        print(60*"=")
324        print err
325        sys.exit()
326
327def svnUpgrade(fpath=os.path.split(__file__)[0]):
328    '''This reformats subversion files, which may be needed if an upgrade of subversion is
329    done.
330
331    :param str fpath: path to repository dictionary, defaults to directory where
332       the current file is located
333    '''
334    svn = whichsvn()
335    if not svn: return
336    cmd = [svn,'upgrade',fpath,'--non-interactive']
337    if proxycmds: cmd += proxycmds
338    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
339    out,err = s.communicate()
340    if err:
341        print("svn upgrade did not happen (this is probably OK). Messages:")
342        print err
343           
344def svnUpdateProcess(version=None,projectfile=None):
345    '''perform an update of GSAS-II in a separate python process'''
346    if not projectfile:
347        projectfile = ''
348    else:
349        projectfile = os.path.realpath(projectfile)
350        print 'restart using',projectfile
351    if not version:
352        version = ''
353    else:
354        version = str(version)
355    # start the upgrade in a separate interpreter (avoids loading .pyd files)
356    subprocess.Popen([sys.executable,__file__,projectfile,version])
357    sys.exit()
358
359def svnSwitchDir(rpath,filename,baseURL,loadpath=None,verbose=True):
360    '''This performs a switch command to move files between subversion trees.
361    Note that if the files were previously downloaded,
362    the switch command will update the files to the newest version.
363   
364    :param str rpath: path to locate files, relative to the GSAS-II
365      installation path (defaults to path2GSAS2)
366    :param str URL: the repository URL
367    :param str loadpath: the prefix for the path, if specified. Defaults to path2GSAS2
368    :param bool verbose: if True (default) diagnostics are printed
369    '''
370    svn = whichsvn()
371    if not svn: return
372    URL = baseURL[:]
373    if baseURL[-1] != '/':
374        URL = baseURL + '/' + filename
375    else:
376        URL = baseURL + filename
377    if loadpath:
378        fpath = os.path.join(loadpath,rpath,filename)
379    else:
380        fpath = os.path.join(path2GSAS2,rpath,filename)
381    cmd = [svn,'switch',URL,fpath,
382           '--non-interactive','--trust-server-cert',
383           '--accept','theirs-conflict','--force']
384    if svnVersionNumber(svn) > 1.6: cmd += ['--ignore-ancestry']
385    if proxycmds: cmd += proxycmds
386    if verbose: print(u"Loading files to "+fpath+u"\n  from "+URL)
387    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
388    out,err = s.communicate()
389    if err:
390        print(60*"=")
391        print ("****** An error was noted, see below *********")
392        print(60*"=")
393        print 'out=',out
394        print 'err=',err
395        return False
396    if verbose:
397        print('=== Output from svn switch'+(43*'='))
398        print(out.strip())
399        print((70*'=')+'\n')
400    return True
401
402def svnInstallDir(URL,loadpath):
403    '''Load a subversion tree into a specified directory
404
405    :param str URL: the repository URL
406    :param str loadpath: path to locate files
407
408    '''
409    svn = whichsvn()
410    if not svn: return
411    cmd = [svn,'co',URL,loadpath,'--non-interactive']
412    if svnVersionNumber() >= 1.6: cmd += ['--trust-server-cert']
413    print("Loading files from "+URL)
414    if proxycmds: cmd += proxycmds
415    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
416    out,err = s.communicate()   #this fails too easily
417    if err:
418        print(60*"=")
419        print ("****** An error was noted, see below *********")
420        print(60*"=")
421        print err
422        return False
423    print ("Files installed at: "+loadpath)
424    return True
425           
426def DownloadG2Binaries(g2home,verbose=True):
427    '''Download GSAS-II binaries from appropriate section of the
428    GSAS-II svn repository based on the platform, numpy and Python
429    version
430    '''
431    # convert version numbers as '1.2.3' to integers (1002) and back (to 1.2)
432    fmtver = lambda v: str(v//1000)+'.'+str(v%1000)
433    intver = lambda vs: sum([int(i) for i in vs.split('.')[0:2]]*np.array((1000,1)))
434   
435    if sys.platform == "win32":
436        prefix = 'win'
437    elif sys.platform == "darwin":
438        prefix = 'mac'
439    elif sys.platform == "linux2":
440        prefix = 'linux'
441    else:
442        print(u'Unknown platform: '+sys.platform)
443        raise Exception('Unknown platform')
444    if platform.architecture()[0] == '64bit':
445        bits = '64'
446    else:
447        bits = '32'
448
449    # if np.__version__ is None we must be in Read The Docs
450    if np.__version__ is None: return
451   
452    # format current python & numpy versions
453    pyver = 'p{}.{}'.format(*sys.version_info[0:2])
454    npver = 'n{}.{}'.format(*np.__version__.split('.')[0:2])
455    inpver = intver(np.__version__)
456
457    items = [prefix,bits,pyver]
458    bindir = '_'.join(items)
459
460    svn = whichsvn()
461    if not svn:
462        print('**** unable to load files: svn not found ****')
463        return ''
464    # get binaries matching the required type -- other than for the numpy version
465    cmd = [svn, 'list', g2home + '/Binaries/']
466    if proxycmds: cmd += proxycmds
467    p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
468    res,err = p.communicate()
469    versions = {}
470    for d in res.split():
471        if d.startswith(bindir):
472            v = intver(d.rstrip('/').split('_')[3].lstrip('n'))
473            versions[v] = d
474    intVersionsList = sorted(versions.keys())
475    if inpver < min(intVersionsList):
476        vsel = min(intVersionsList)
477        print('Warning: The current numpy version, {}, is older than\n\tthe oldest dist version, {}'
478              .format(np.__version__,fmtver(vsel)))
479    elif inpver >= max(intVersionsList):
480        vsel = max(intVersionsList)
481        if verbose: print(
482                'FYI: The current numpy version, {}, is newer than the newest dist version {}'
483                .format(np.__version__,fmtver(vsel)))
484    else:
485        vsel = min(intVersionsList)
486        for v in intVersionsList:
487            if v <= inpver:
488                vsel = v
489            else:
490                if verbose: print(
491                        'FYI: Selecting dist version {} as the current numpy version, {},\n\tis older than the next dist version {}'
492                        .format(fmtver(vsel),np.__version__,fmtver(v)))
493                break
494    distdir = g2home + '/Binaries/' + versions[vsel]
495    # switch reset command: distdir = g2home + '/trunk/bindist'
496    svnSwitchDir('bindist','',distdir,verbose=verbose)
497    return os.path.join(path2GSAS2,'bindist')
498
499def IPyBreak_base():
500    '''A routine that invokes an IPython session at the calling location
501    This routine is only used when debug=True is set in config.py
502    '''
503    savehook = sys.excepthook # save the exception hook
504    try: 
505        from IPython.terminal.embed import InteractiveShellEmbed
506    except ImportError:
507        try:
508            # try the IPython 0.12 approach
509            from IPython.frontend.terminal.embed import InteractiveShellEmbed
510        except ImportError:
511            print 'IPython InteractiveShellEmbed not found'
512            return
513    import inspect
514    ipshell = InteractiveShellEmbed()
515
516    frame = inspect.currentframe().f_back
517    msg   = 'Entering IPython console inside {0.f_code.co_filename} at line {0.f_lineno}\n'.format(frame)
518    ipshell(msg,stack_depth=2) # Go up one level, to see the calling routine
519    sys.excepthook = savehook # reset IPython's change to the exception hook
520
521def exceptHook(*args):
522    '''A routine to be called when an exception occurs. It prints the traceback
523    with fancy formatting and then calls an IPython shell with the environment
524    of the exception location.
525   
526    This routine is only used when debug=True is set in config.py   
527    '''
528    from IPython.core import ultratb
529    if 'win' in sys.platform:
530        ultratb.FormattedTB(call_pdb=False,color_scheme='NoColor')(*args)
531    else:
532        ultratb.FormattedTB(call_pdb=False,color_scheme='LightBG')(*args)
533    try: 
534        from IPython.terminal.embed import InteractiveShellEmbed
535    except ImportError:
536        try:
537            # try the IPython 0.12 approach
538            from IPython.frontend.terminal.embed import InteractiveShellEmbed
539        except ImportError:
540            print 'IPython InteractiveShellEmbed not found'
541            return
542    import inspect
543    frame = inspect.getinnerframes(args[2])[-1][0]
544    msg   = 'Entering IPython console at {0.f_code.co_filename} at line {0.f_lineno}\n'.format(frame)
545    savehook = sys.excepthook # save the exception hook
546    try:
547        InteractiveShellEmbed(banner1=msg)(local_ns=frame.f_locals,global_ns=frame.f_globals)
548    except: # use a different call for IPython 5
549        class c(object): pass
550        pseudomod = c() # create something that acts like a module
551        pseudomod.__dict__ = frame.f_locals
552        InteractiveShellEmbed(banner1=msg)(module=pseudomod,global_ns=frame.f_globals)
553    sys.excepthook = savehook # reset IPython's change to the exception hook
554
555def DoNothing():
556    '''A routine that does nothing. This is called in place of IPyBreak and pdbBreak
557    except when the debug option is set True in config.py
558    '''
559    pass 
560
561IPyBreak = DoNothing
562pdbBreak = DoNothing
563def InvokeDebugOpts():
564    'Called in GSASII.py to set up debug options'
565    if GetConfigValue('debug'):
566        print 'Debug on: IPython: Exceptions and G2path.IPyBreak(); pdb: G2path.pdbBreak()'
567        sys.excepthook = exceptHook
568        import pdb
569        global pdbBreak
570        pdbBreak = pdb.set_trace
571        global IPyBreak
572        IPyBreak = IPyBreak_base
573
574def TestSPG(fpth):
575    '''Test if pyspg.[so,.pyd] can be run from a location in the path
576    '''
577    if not os.path.exists(fpth): return False
578    if not glob.glob(os.path.join(fpth,'pyspg.*')): return False
579    savpath = sys.path[:]
580    sys.path = [fpth]
581    # test to see if a shared library can be used
582    try:
583        import pyspg
584        pyspg.sgforpy('P -1')
585    except Exception as err:
586        print(70*'=')
587        print('Failed to run pyspg in {}\nerror: {}'.format(fpth,err))
588        print(70*'=')
589        sys.path = savpath
590        return False
591    sys.path = savpath
592    return True
593   
594# see if a directory for local modifications is defined. If so, stick that in the path
595if os.path.exists(os.path.expanduser('~/.G2local/')):
596    sys.path.insert(0,os.path.expanduser('~/.G2local/'))
597    import glob
598    fl = glob.glob(os.path.expanduser('~/.G2local/GSASII*.py*'))
599    files = ""
600    prev = None
601    for f in sorted(fl): # make a list of files, dropping .pyc files where a .py exists
602        f = os.path.split(f)[1]
603        if os.path.splitext(f)[0] == prev: continue
604        prev = os.path.splitext(f)[0]
605        if files: files += ", "
606        files += f
607    if files:
608        print("*"*75)
609        print("Warning: the following source files are locally overridden in "+os.path.expanduser('~/.G2local/'))
610        print("  "+files)
611        print("*"*75)
612################################################################################
613# commands below are executed during the first import of this file
614################################################################################
615# Add location of GSAS-II shared libraries (binaries: .so or .pyd files) to path
616binpath = None
617for loc in os.path.abspath(sys.path[0]),os.path.abspath(os.path.split(__file__)[0]):
618    # Look at bin directory (created by a local compile) before standard dist
619    # that at the top of the path
620    for d in 'bin','bindist':
621        if not d: continue
622        fpth = os.path.join(loc,d)
623        if TestSPG(fpth):
624            binpath = fpth
625            break       
626    if binpath: break
627if binpath:                                            # were GSAS-II binaries found
628    sys.path.insert(0,binpath)
629    print('GSAS-II binary directory: {}'.format(binpath))
630else:                                                  # try loading them
631    print('Attempting to download GSAS-II binary files...')
632    binpath = DownloadG2Binaries(g2home)
633    if 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]):
665        # Look at bin directory (created by a local compile) before standard dist
666        # that at the top of the path
667            fpth = os.path.join(loc,bindir)
668            if TestSPG(fpth):
669                binpath = fpth
670                sys.path.insert(0,binpath)
671                print('GSAS-II binary directory: {}'.format(binpath))
672                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
679newpath = os.path.join(path2GSAS2,'imports')
680if newpath not in sys.path: sys.path.append(newpath)
681newpath = os.path.join(path2GSAS2,'exports')
682if newpath not in sys.path: sys.path.append(newpath)
683
684# setup read of config.py, if present
685try:
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__)
691except ImportError:
692    configDict = {'Clip_on':True}
693except Exception as err:
694    print("Error importing config.py file: "+str(err))
695    configDict = {'Clip_on':True}
696
697if __name__ == '__main__':
698    '''What follows is called to update (or downdate) GSAS-II in a separate process.
699    '''
700    import time
701    time.sleep(1) # delay to give the main process a chance to exit
702    # perform an update and restart GSAS-II
703    project,version = sys.argv[1:3]
704    loc = os.path.dirname(__file__)
705    if version:
706        print("Regress to version "+str(version))
707        svnUpdateDir(loc,version=version)
708    else:
709        print("Update to current version")
710        svnUpdateDir(loc)
711    if project:
712        print("Restart GSAS-II with project file "+str(project))
713        subprocess.Popen([sys.executable,os.path.join(loc,'GSASII.py'),project])
714    else:
715        print("Restart GSAS-II without a project file ")
716        subprocess.Popen([sys.executable,os.path.join(loc,'GSASII.py')])
717    print 'exiting update process'
718    sys.exit()
Note: See TracBrowser for help on using the repository browser.