1 | #!/usr/bin/env python |
---|
2 | # Installs GSAS-II from network using subversion and creates platform-specific |
---|
3 | # shortcuts. |
---|
4 | # works for Mac & Linux; Windows being tested. |
---|
5 | import os, stat, sys, platform, subprocess |
---|
6 | home = 'https://subversion.xray.aps.anl.gov/pyGSAS/' |
---|
7 | print 70*'*' |
---|
8 | #testing for incorrect locale code' |
---|
9 | try: |
---|
10 | import locale |
---|
11 | locale.getdefaultlocale() |
---|
12 | except ValueError: |
---|
13 | print 'Your location is not set properly. This causes problems for matplotlib' |
---|
14 | print ' (see https://github.com/matplotlib/matplotlib/issues/5420.)' |
---|
15 | print 'Will try to bypass problem by setting LC_ALL to en_US.UTF-8 (US English)' |
---|
16 | os.environ['LC_ALL'] = 'en_US.UTF-8' |
---|
17 | locale.getdefaultlocale() |
---|
18 | print 'Preloading matplotlib to build fonts...' |
---|
19 | try: |
---|
20 | import matplotlib |
---|
21 | except: |
---|
22 | pass |
---|
23 | print 'Checking python packages...', |
---|
24 | missing = [] |
---|
25 | for pkg in ['numpy','scipy','matplotlib','wx',]: |
---|
26 | try: |
---|
27 | exec('import '+pkg) |
---|
28 | except: |
---|
29 | missing.append(pkg) |
---|
30 | |
---|
31 | if missing: |
---|
32 | print """Sorry, this version of Python cannot be used |
---|
33 | for GSAS-II. It is missing the following package(s): |
---|
34 | \t""", |
---|
35 | for pkg in missing: print " ",pkg, |
---|
36 | print |
---|
37 | print "This should not happen as this script should be called with a " |
---|
38 | print "specially configured version of the free Anaconda python package." |
---|
39 | print "Please contact Brian Toby (toby@anl.gov)" |
---|
40 | for pkg in ['numpy','scipy','matplotlib','wx',]: |
---|
41 | exec('import '+pkg) |
---|
42 | sys.exit() |
---|
43 | try: |
---|
44 | import OpenGL |
---|
45 | except: |
---|
46 | print "Missing the OpenGL Python package." |
---|
47 | print "This should not happen as this script should be called with a " |
---|
48 | print "specially configured version of the free Anaconda python package," |
---|
49 | print "but GSAS-II can install this package anyway." |
---|
50 | print "Please contact Brian Toby (toby@anl.gov) to report this problem." |
---|
51 | |
---|
52 | # path to where this script is located |
---|
53 | gsaspath = os.path.split(sys.argv[0])[0] |
---|
54 | if not gsaspath: gsaspath = os.path.curdir |
---|
55 | gsaspath = os.path.abspath(os.path.expanduser(gsaspath)) |
---|
56 | |
---|
57 | print '\nChecking for subversion...', |
---|
58 | if sys.platform.startswith('win'): |
---|
59 | pathlist = os.environ['PATH'].split(';') |
---|
60 | if os.path.exists(os.path.join(gsaspath,'svn')): |
---|
61 | pathlist.append(os.path.join(gsaspath,'svn','bin')) |
---|
62 | else: |
---|
63 | pathlist = os.environ['PATH'].split(':') |
---|
64 | # add the standard location for wandisco svn to the path |
---|
65 | pathlist.append('/opt/subversion/bin') |
---|
66 | if sys.platform.startswith('win'): |
---|
67 | svn = 'svn.exe' |
---|
68 | else: |
---|
69 | svn = 'svn' |
---|
70 | # use svn installed via conda 1st (mac) |
---|
71 | if os.path.exists(os.path.join(os.path.split(sys.executable)[0],svn)): |
---|
72 | pathlist.insert(0,os.path.split(sys.executable)[0]) |
---|
73 | # use svn installed via conda 1st (Windows) |
---|
74 | if os.path.exists(os.path.join(os.path.split(sys.executable)[0],'Library','bin',svn)): |
---|
75 | pathlist.insert(0,os.path.join(os.path.split(sys.executable)[0],'Library','bin')) |
---|
76 | |
---|
77 | for path in pathlist: |
---|
78 | svn = os.path.join(path,'svn') |
---|
79 | try: |
---|
80 | p = subprocess.Popen([svn,'help'],stdout=subprocess.PIPE) |
---|
81 | res = p.stdout.read() |
---|
82 | p.communicate() |
---|
83 | break |
---|
84 | except: |
---|
85 | pass |
---|
86 | else: |
---|
87 | raise Exception('Subversion (svn) not found') |
---|
88 | print ' found svn image: '+svn |
---|
89 | |
---|
90 | print 'Ready to bootstrap GSAS-II from repository\n\t',home,'\nto '+gsaspath |
---|
91 | proxycmds = [] |
---|
92 | if os.path.exists("proxyinfo.txt"): |
---|
93 | fp = open("proxyinfo.txt",'r') |
---|
94 | os.remove("proxyinfo.txt") |
---|
95 | print(70*"=") |
---|
96 | ans = raw_input("Enter the proxy address [none needed]: ") |
---|
97 | if ans.strip() != "": |
---|
98 | proxycmds.append('--config-option') |
---|
99 | proxycmds.append('servers:global:http-proxy-host='+ans.strip()) |
---|
100 | fp = open("proxyinfo.txt",'w') |
---|
101 | fp.write(ans.strip()+'\n') |
---|
102 | ans = raw_input("Enter the proxy port [8080]: ") |
---|
103 | if ans.strip() == "": ans="8080" |
---|
104 | proxycmds.append('--config-option') |
---|
105 | proxycmds.append('servers:global:http-proxy-port='+ans.strip()) |
---|
106 | fp.write(ans.strip()+'\n') |
---|
107 | fp.close() |
---|
108 | |
---|
109 | print 'Determining system type...', |
---|
110 | if sys.platform.startswith('linux'): |
---|
111 | #if platform.processor().find('86') <= -1: |
---|
112 | # ans = raw_input("Note, GSAS requires an Intel-compatible processor and 32-bit" |
---|
113 | # "libraries.\nAre you sure want to continue? [Yes]/no: ") |
---|
114 | # if ans.lower().find('no') > -1: sys.exit() |
---|
115 | repos = 'linux' |
---|
116 | print 'Linux, assuming Intel-compatible' |
---|
117 | elif sys.platform == "darwin" and platform.processor() == 'i386': |
---|
118 | repos = 'osxi86' |
---|
119 | print 'Mac OS X, Intel-compatible' |
---|
120 | elif sys.platform == "darwin": |
---|
121 | repos = 'osxppc' |
---|
122 | print 'Mac OS X, PowerPC -- you will need to run scons on fsource files' |
---|
123 | elif sys.platform.startswith('win'): |
---|
124 | repos = 'win' |
---|
125 | print 'Windows' |
---|
126 | else: |
---|
127 | print 'Unidentifed platform -- you probably will need to run scons to compile the fsource files' |
---|
128 | |
---|
129 | cmd = [svn, 'co', home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert'] |
---|
130 | if proxycmds: cmd += proxycmds |
---|
131 | msg = 'loading GSAS-II' |
---|
132 | |
---|
133 | print 70*'*' |
---|
134 | print msg + ' from ' + cmd[2] |
---|
135 | print 'svn load command:' |
---|
136 | for item in cmd: print item, |
---|
137 | print "" |
---|
138 | p = subprocess.call(cmd) |
---|
139 | if p: |
---|
140 | print 'subversion returned an error; Retrying with command for older version...' |
---|
141 | cmd = [svn, 'co', home+ 'trunk/', gsaspath] |
---|
142 | if proxycmds: cmd += proxycmds |
---|
143 | for item in cmd: print item, |
---|
144 | print "" |
---|
145 | p = subprocess.call(cmd) |
---|
146 | |
---|
147 | #=========================================================================== |
---|
148 | # import all .py files so that .pyc files get created |
---|
149 | print 'Byte-compiling all .py files...', |
---|
150 | import compileall |
---|
151 | compileall.compile_dir(gsaspath,quiet=True) |
---|
152 | print 'done' |
---|
153 | #=========================================================================== |
---|
154 | # platform-dependent stuff |
---|
155 | #=========================================================================== |
---|
156 | # on Windows, |
---|
157 | if sys.platform.startswith('win') and os.path.exists( |
---|
158 | os.path.join(gsaspath,"makeBat.py")): |
---|
159 | execfile(os.path.join(gsaspath,"makeBat.py")) |
---|
160 | #=========================================================================== |
---|
161 | # on a Mac, make an applescript |
---|
162 | elif sys.platform.startswith('darwin') and os.path.exists( |
---|
163 | os.path.join(gsaspath,"makeMacApp.py")): |
---|
164 | print('running '+os.path.join(gsaspath,"makeMacApp.py")) |
---|
165 | execfile(os.path.join(gsaspath,"makeMacApp.py")) |
---|
166 | #=========================================================================== |
---|
167 | # On linux, make desktop icon |
---|
168 | elif sys.platform.startswith('linux'): |
---|
169 | desktop_template = """ |
---|
170 | [Desktop Entry] |
---|
171 | Encoding=UTF-8 |
---|
172 | Version=1.0 |
---|
173 | Type=Application |
---|
174 | Terminal=false |
---|
175 | Exec=xterm -hold -e %s |
---|
176 | Name=GSAS-II |
---|
177 | Icon=%s |
---|
178 | """ |
---|
179 | loc = '~/Desktop/' |
---|
180 | eloc = os.path.expanduser(loc) |
---|
181 | dfile = os.path.join(eloc,'GSASII.desktop') |
---|
182 | icon = os.path.join(gsaspath, 'gsas2.png') |
---|
183 | script = os.path.join(gsaspath, 'GSASII.py') |
---|
184 | os.chmod(script, # make the .py file executable and readable |
---|
185 | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) |
---|
186 | if os.path.exists(eloc): |
---|
187 | open(dfile,'w').write(desktop_template % (script,icon)) |
---|
188 | os.chmod( |
---|
189 | dfile, |
---|
190 | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) |
---|
191 | print("created GNOME desktop shortcut "+dfile) |
---|
192 | |
---|