source: install/bootstrap.py @ 333

Last change on this file since 333 was 333, checked in by toby, 12 years ago

Add Mac/Linux? install script

File size: 6.3 KB
Line 
1#!/usr/bin/env python
2import os, stat, sys, platform, subprocess
3home = 'https://subversion.xor.aps.anl.gov/pyGSAS/'
4
5print sys.argv
6gsaspath = os.path.split(sys.argv[0])[0]
7gsaspath = os.path.abspath(os.path.expanduser(gsaspath))
8
9print 'Checking for subversion...',
10try: 
11    #p = subprocess.call(['svn','status'],stdout=subprocess.PIPE)
12    p = subprocess.Popen(['svn','help'],stdout=subprocess.PIPE)
13except:
14    raise Exception('Subversion (svn) not found')
15res = p.stdout.read()
16p.communicate()
17print 'OK'
18
19print 'GSAS-II is being bootstrapped from repository\n',home,'\nto '+gsaspath
20
21print 'Determining system type...',
22if sys.platform.startswith('linux'):
23    #if platform.processor().find('86') <= -1:
24    #    ans = raw_input("Note, GSAS requires an Intel-compatible processor and 32-bit"
25    #                    "libraries.\nAre you sure want to continue? [Yes]/no: ")
26    #    if ans.lower().find('no') > -1: sys.exit()
27    repos = 'linux'
28    print 'Linux, Intel-compatible'
29elif sys.platform == "darwin" and platform.processor() == 'i386':
30    repos = 'osxi86'
31    print 'Mac OS X, Intel-compatible'
32elif sys.platform == "darwin":
33    repos = 'osxppc'
34    print 'Mac OS X, PowerPC -- you will need to run f2py on fsource files'
35else:
36    print 'Unidentifed platform -- you may need to run f2py on fsource files'
37
38cmds = (
39    (['svn', 'co', home+ 'trunk/', gsaspath],'loading GSAS-II'),
40    #(['svn', 'co', home+ 'gsas/all', gsaspath],'loading GSAS common'),
41)
42
43for cmd,msg in cmds: 
44    print 70*'*'
45    print msg + ' from ' + cmd[2]
46    for item in cmd: print item,
47    print ""
48    p = subprocess.call(cmd)
49
50#===========================================================================
51# could try to load .so files here and run scons if needed.
52
53#===========================================================================
54# on a Mac, make an applescript
55if sys.platform.startswith('darwin'):
56    script = '''
57(*   GSAS-II AppleScript by B. Toby (brian.toby@anl.gov)
58         It can launch GSAS-II by double clicking or by dropping a data file or folder over that app.
59         thanks to F. Farges; farges@univ-mlv.fr for showing me how to do much of this
60*)
61
62
63(*
64--------------------------------------------
65Define subroutines used in later sections of code
66--------------------------------------------
67*)
68
69(*  get  directory  from a file name *)
70on GetParentPath(theFile)
71        tell application "Finder" to return container of theFile as text
72end GetParentPath
73
74(* test if a file is present and exit with an error message if it is not  *)
75on TestFilePresent(appwithpath)
76        tell application "System Events"
77                if (file appwithpath exists) then
78                else
79                        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"}
80                        return
81                end if
82        end tell
83end TestFilePresent
84
85(*
86--------------------------------------------------------------
87this section responds to a double-click. No file is supplied to GSAS-II
88 o  First find the location of the script
89 o  then convert the colon-delimited macintosh file location to a POSIX filename
90 o  start the app with no file as argument -- opens last file or none (depending on GSAS-II preferences)
91--------------------------------------------------------------
92*)
93on run
94        set python to "%s"
95        set myPath to (path to me)
96        set ParentPath to GetParentPath(myPath)
97        set appwithpath to ParentPath & "GSASII.py"
98        TestFilePresent(appwithpath)
99        set posixapp to quoted form of the POSIX path of appwithpath
100        set results to do shell script python & " " & posixapp & " > ~/GSASIIerrors 2>&1  &"
101end run
102
103(*
104----------------------------------------------------------------------
105this section handles opening files dragged into the AppleScript
106 o it finds the location of the current script and finds the GSAS-II
107     executable relative to the applescript
108 o it goes through the list of files dragged in
109 o then it converts the colon-delimited macintosh file location to a POSIX filename
110 o for every non-directory file dragged into the icon, it tries to pass that file  to GSAS-II
111 o for directories select a file from the directory
112-----------------------------------------------------------------------
113*)
114
115on open names
116       
117        set python to "%s"
118        set myPath to (path to me)
119        set ParentPath to GetParentPath(myPath)
120        set appwithpath to ParentPath & "GSASII.py"
121        TestFilePresent(appwithpath)
122        set posixapp to the quoted form of the POSIX path of appwithpath
123        set filePath to ""
124        repeat with filename in names
125                set filestr to (filename as string)
126                if filestr ends with ":" then
127                        set myfile to choose file default location filename with prompt "Select a GSAS-II input file" multiple selections allowed no
128                        set myfile to the quoted form of the POSIX path of myfile
129                        set results to do shell script python & " " & posixapp & " " & myfile & " > ~/GSASIIerrors 2>&1  &"
130                else
131                        (* if this is an input file, open it *)
132                        set filename to the quoted form of the POSIX path of filename
133                        set results to do shell script python & " " & posixapp & " " & filename & " > ~/GSASIIerrors 2>&1  &"
134                end if
135        end repeat
136end open
137'''
138    app = os.path.join(gsaspath, 'GSASII.app')
139    p = subprocess.Popen(['/usr/bin/osacompile','-o',app],stdin=subprocess.PIPE)
140    p.stdin.write(script % (sys.executable,sys.executable) )
141    p.stdin.close()
142    p.communicate()
143    if os.path.exists('GSAS2.rsrc'):
144        print "Note: ignore the -d warning from osacompile"
145        p = subprocess.call(['/Developer/Tools/Rez','-append','GSAS2.rsrc','-o',app + "/Icon\r"])
146        p = subprocess.call(['/Developer/Tools/SetFile','-a','C',app])
147
148#===========================================================================
149# On linux, make desktop icon
150if sys.platform.startswith('linux'):
151    os.chmod(os.path.join(gsaspath, 'GSASII.py'),
152             stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) 
153    if os.path.exists(os.path.expanduser('~/Desktop/')):
154        open(os.path.expanduser('~/Desktop/GSASII.desktop'),'w').write('''
155[Desktop Entry]
156Encoding=UTF-8
157Version=1.0
158Type=Application
159Terminal=false
160Exec=%s
161Name=GSAS-II
162Icon=%s
163''' % (os.path.join(gsaspath, 'GSASII.py'),os.path.join(gsaspath, 'gsas2.png')))
164        os.chmod(os.path.expanduser('~/Desktop/GSASII.desktop'),
165                 stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) 
Note: See TracBrowser for help on using the repository browser.