#!/usr/bin/env python import os, stat, sys, platform, subprocess home = 'https://subversion.xor.aps.anl.gov/pyGSAS/' print sys.argv gsaspath = os.path.split(sys.argv[0])[0] gsaspath = os.path.abspath(os.path.expanduser(gsaspath)) print 'Checking for subversion...', try: #p = subprocess.call(['svn','status'],stdout=subprocess.PIPE) p = subprocess.Popen(['svn','help'],stdout=subprocess.PIPE) except: raise Exception('Subversion (svn) not found') res = p.stdout.read() p.communicate() print 'OK' print 'GSAS-II is being bootstrapped from repository\n',home,'\nto '+gsaspath print 'Determining system type...', if sys.platform.startswith('linux'): #if platform.processor().find('86') <= -1: # ans = raw_input("Note, GSAS requires an Intel-compatible processor and 32-bit" # "libraries.\nAre you sure want to continue? [Yes]/no: ") # if ans.lower().find('no') > -1: sys.exit() repos = 'linux' print 'Linux, Intel-compatible' elif sys.platform == "darwin" and platform.processor() == 'i386': repos = 'osxi86' print 'Mac OS X, Intel-compatible' elif sys.platform == "darwin": repos = 'osxppc' print 'Mac OS X, PowerPC -- you will need to run f2py on fsource files' else: print 'Unidentifed platform -- you may need to run f2py on fsource files' cmds = ( (['svn', 'co', home+ 'trunk/', gsaspath],'loading GSAS-II'), #(['svn', 'co', home+ 'gsas/all', gsaspath],'loading GSAS common'), ) for cmd,msg in cmds: print 70*'*' print msg + ' from ' + cmd[2] for item in cmd: print item, print "" p = subprocess.call(cmd) #=========================================================================== # could try to load .so files here and run scons if needed. #=========================================================================== # on a Mac, make an applescript if sys.platform.startswith('darwin'): script = ''' (* GSAS-II AppleScript by B. Toby (brian.toby@anl.gov) It can launch GSAS-II by double clicking or by dropping a data file or folder over that app. thanks to F. Farges; farges@univ-mlv.fr for showing me how to do much of this *) (* -------------------------------------------- Define subroutines used in later sections of code -------------------------------------------- *) (* get directory from a file name *) on GetParentPath(theFile) tell application "Finder" to return container of theFile as text end GetParentPath (* test if a file is present and exit with an error message if it is not *) on TestFilePresent(appwithpath) tell application "System Events" if (file appwithpath exists) then else display dialog "Error: file " & appwithpath & " not found. This AppleScript must be run from a directory containing the GSAS-II executable. Did you move it?" with icon caution buttons {"Quit"} return end if end tell end TestFilePresent (* -------------------------------------------------------------- this section responds to a double-click. No file is supplied to GSAS-II o First find the location of the script o then convert the colon-delimited macintosh file location to a POSIX filename o start the app with no file as argument -- opens last file or none (depending on GSAS-II preferences) -------------------------------------------------------------- *) on run set python to "%s" set myPath to (path to me) set ParentPath to GetParentPath(myPath) set appwithpath to ParentPath & "GSASII.py" TestFilePresent(appwithpath) set posixapp to quoted form of the POSIX path of appwithpath set results to do shell script python & " " & posixapp & " > ~/GSASIIerrors 2>&1 &" end run (* ---------------------------------------------------------------------- this section handles opening files dragged into the AppleScript o it finds the location of the current script and finds the GSAS-II executable relative to the applescript o it goes through the list of files dragged in o then it converts the colon-delimited macintosh file location to a POSIX filename o for every non-directory file dragged into the icon, it tries to pass that file to GSAS-II o for directories select a file from the directory ----------------------------------------------------------------------- *) on open names set python to "%s" set myPath to (path to me) set ParentPath to GetParentPath(myPath) set appwithpath to ParentPath & "GSASII.py" TestFilePresent(appwithpath) set posixapp to the quoted form of the POSIX path of appwithpath set filePath to "" repeat with filename in names set filestr to (filename as string) if filestr ends with ":" then set myfile to choose file default location filename with prompt "Select a GSAS-II input file" multiple selections allowed no set myfile to the quoted form of the POSIX path of myfile set results to do shell script python & " " & posixapp & " " & myfile & " > ~/GSASIIerrors 2>&1 &" else (* if this is an input file, open it *) set filename to the quoted form of the POSIX path of filename set results to do shell script python & " " & posixapp & " " & filename & " > ~/GSASIIerrors 2>&1 &" end if end repeat end open ''' app = os.path.join(gsaspath, 'GSASII.app') p = subprocess.Popen(['/usr/bin/osacompile','-o',app],stdin=subprocess.PIPE) p.stdin.write(script % (sys.executable,sys.executable) ) p.stdin.close() p.communicate() if os.path.exists('GSAS2.rsrc'): print "Note: ignore the -d warning from osacompile" p = subprocess.call(['/Developer/Tools/Rez','-append','GSAS2.rsrc','-o',app + "/Icon\r"]) p = subprocess.call(['/Developer/Tools/SetFile','-a','C',app]) #=========================================================================== # On linux, make desktop icon if sys.platform.startswith('linux'): os.chmod(os.path.join(gsaspath, 'GSASII.py'), stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) if os.path.exists(os.path.expanduser('~/Desktop/')): open(os.path.expanduser('~/Desktop/GSASII.desktop'),'w').write(''' [Desktop Entry] Encoding=UTF-8 Version=1.0 Type=Application Terminal=false Exec=%s Name=GSAS-II Icon=%s ''' % (os.path.join(gsaspath, 'GSASII.py'),os.path.join(gsaspath, 'gsas2.png'))) os.chmod(os.path.expanduser('~/Desktop/GSASII.desktop'), stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH)