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