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