1 | #!/usr/bin/env python |
---|
2 | import os, stat, sys, platform, subprocess |
---|
3 | home = 'https://subversion.xor.aps.anl.gov/pyGSAS/' |
---|
4 | |
---|
5 | print sys.argv |
---|
6 | gsaspath = os.path.split(sys.argv[0])[0] |
---|
7 | gsaspath = os.path.abspath(os.path.expanduser(gsaspath)) |
---|
8 | |
---|
9 | print 'Checking for subversion...', |
---|
10 | try: |
---|
11 | #p = subprocess.call(['svn','status'],stdout=subprocess.PIPE) |
---|
12 | p = subprocess.Popen(['svn','help'],stdout=subprocess.PIPE) |
---|
13 | except: |
---|
14 | raise Exception('Subversion (svn) not found') |
---|
15 | res = p.stdout.read() |
---|
16 | p.communicate() |
---|
17 | print 'OK' |
---|
18 | |
---|
19 | print 'GSAS-II is being bootstrapped from repository\n',home,'\nto '+gsaspath |
---|
20 | |
---|
21 | print 'Determining system type...', |
---|
22 | if 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' |
---|
29 | elif sys.platform == "darwin" and platform.processor() == 'i386': |
---|
30 | repos = 'osxi86' |
---|
31 | print 'Mac OS X, Intel-compatible' |
---|
32 | elif sys.platform == "darwin": |
---|
33 | repos = 'osxppc' |
---|
34 | print 'Mac OS X, PowerPC -- you will need to run f2py on fsource files' |
---|
35 | else: |
---|
36 | print 'Unidentifed platform -- you may need to run f2py on fsource files' |
---|
37 | |
---|
38 | cmds = ( |
---|
39 | (['svn', 'co', home+ 'trunk/', gsaspath],'loading GSAS-II'), |
---|
40 | #(['svn', 'co', home+ 'gsas/all', gsaspath],'loading GSAS common'), |
---|
41 | ) |
---|
42 | |
---|
43 | for 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 |
---|
55 | if 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 | -------------------------------------------- |
---|
65 | Define subroutines used in later sections of code |
---|
66 | -------------------------------------------- |
---|
67 | *) |
---|
68 | |
---|
69 | (* get directory from a file name *) |
---|
70 | on GetParentPath(theFile) |
---|
71 | tell application "Finder" to return container of theFile as text |
---|
72 | end GetParentPath |
---|
73 | |
---|
74 | (* test if a file is present and exit with an error message if it is not *) |
---|
75 | on 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 |
---|
83 | end TestFilePresent |
---|
84 | |
---|
85 | (* |
---|
86 | -------------------------------------------------------------- |
---|
87 | this 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 | *) |
---|
93 | on 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 &" |
---|
101 | end run |
---|
102 | |
---|
103 | (* |
---|
104 | ---------------------------------------------------------------------- |
---|
105 | this 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 | |
---|
115 | on 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 |
---|
136 | end 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 |
---|
150 | if 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] |
---|
156 | Encoding=UTF-8 |
---|
157 | Version=1.0 |
---|
158 | Type=Application |
---|
159 | Terminal=false |
---|
160 | Exec=%s |
---|
161 | Name=GSAS-II |
---|
162 | Icon=%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) |
---|