Changeset 4396 for trunk/GSASIIpath.py


Ignore:
Timestamp:
Apr 6, 2020 6:05:40 PM (20 months ago)
Author:
toby
Message:

improve end-of-life message, add tools to run bash/bat scripts outside GSAS-II

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpath.py

    r4352 r4396  
    507507        version = str(version)
    508508    # start the upgrade in a separate interpreter (avoids loading .pyd files)
    509     proc = subprocess.Popen([sys.executable,__file__,projectfile,version])
     509    ex = sys.executable
     510    if sys.platform == "darwin": # mac requires pythonw which is not always reported as sys.executable
     511        if os.path.exists(ex+'w'): ex += 'w'
     512    proc = subprocess.Popen([ex,__file__,projectfile,version])
    510513    if sys.platform != "win32":
    511514        proc.wait()
     
    10321035    subprocess.Popen(["osascript","-e",script])
    10331036
     1037def findConda():
     1038    '''Determines if GSAS-II has been installed as g2conda or gsas2full
     1039    with conda located relative to this file.
     1040    We could also look for conda relative to the python (sys.executable)
     1041    image, but I don't want to muck around with python that someone else
     1042    installed.
     1043    '''
     1044    parent = os.path.split(path2GSAS2)[0]
     1045    if sys.platform != "win32":
     1046        activate = os.path.join(parent,'bin','activate')
     1047        conda = os.path.join(parent,'bin','conda')
     1048    else:
     1049        activate = os.path.join(parent,'Scripts','activate.bat')
     1050        conda = os.path.join(parent,'condabin','conda.bat')
     1051    if os.path.exists(activate) and os.path.exists(conda):
     1052        return conda,activate
     1053    else:
     1054        return None
     1055
     1056def runScript(cmds=[], wait=False, G2frame=None):
     1057    '''run a shell script of commands in an external process
     1058   
     1059    :param list cmds: a list of str's, each ietm containing a shell (cmd.exe
     1060      or bash) command
     1061    :param bool wait: if True indicates the commands should be run and then
     1062      the script should return. If False, then the currently running Python
     1063      will exit. Default is False
     1064    :param wx.Frame G2frame: provides the location of the current .gpx file
     1065      to be used to restart GSAS-II after running the commands, if wait
     1066      is False. Default is None which prevents restarting GSAS-II regardless of
     1067      the value of wait.
     1068    '''
     1069    import tempfile
     1070    if not cmds:  #debug
     1071        print('nothing to do in runScript')
     1072        return
     1073    if sys.platform != "win32":
     1074        suffix = '.sh'
     1075    else:
     1076        suffix = '.bat'
     1077       
     1078    fp = tempfile.NamedTemporaryFile(mode='w', suffix=suffix, delete=False)
     1079    shellname = fp.name
     1080    for line in cmds:
     1081        fp.write(line)
     1082        fp.write('\n')
     1083
     1084    if not wait:
     1085        if G2frame:
     1086            projectfile = ''
     1087            if G2frame.GSASprojectfile:
     1088                projectfile = os.path.realpath(G2frame.GSASprojectfile)
     1089            main = os.path.join(path2GSAS2,'GSASII.py')
     1090            ex = sys.executable
     1091            if sys.platform == "darwin": # mac requires pythonw which is not always reported as sys.executable
     1092                if os.path.exists(ex+'w'): ex += 'w'
     1093            print ('restart using ',' '.join([ex,main,projectfile]))
     1094            fp.write(' '.join([ex,main,projectfile]))
     1095            fp.write('\n')
     1096    fp.close()
     1097
     1098    # start the upgrade in a separate interpreter (avoids loading .pyd files)
     1099    if sys.platform != "win32":
     1100        proc = subprocess.Popen(['bash',shellname])
     1101    else:
     1102        proc = subprocess.Popen([shellname],shell=True)
     1103    if wait:
     1104        proc.wait()
     1105    else:
     1106        if sys.platform != "win32": proc.wait()
     1107        sys.exit()
     1108   
    10341109if __name__ == '__main__':
    10351110    '''What follows is called to update (or downdate) GSAS-II in a separate process.
Note: See TracChangeset for help on using the changeset viewer.