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 | print 'Checking python packages...', |
---|
9 | missing = [] |
---|
10 | for pkg in ['numpy','scipy','matplotlib','wx']: |
---|
11 | try: |
---|
12 | exec('import '+pkg) |
---|
13 | except: |
---|
14 | missing.append(pkg) |
---|
15 | # handle pyopenGl differently, because that we can install later |
---|
16 | try: |
---|
17 | import OpenGL as ogl |
---|
18 | install_with_easyinstall = None |
---|
19 | except ImportError: |
---|
20 | print '\nPyOpenGL not present. ', |
---|
21 | try: |
---|
22 | from setuptools.command import easy_install |
---|
23 | except ImportError: |
---|
24 | missing.append('setuptools') |
---|
25 | def install_with_easyinstall(package): |
---|
26 | try: |
---|
27 | print "trying system-wide ", |
---|
28 | easy_install.main(['-f',os.path.split(__file__)[0],package]) |
---|
29 | return |
---|
30 | except: |
---|
31 | pass |
---|
32 | try: |
---|
33 | print "trying user level ", |
---|
34 | easy_install.main(['-f',os.path.split(__file__)[0],'--user',package]) |
---|
35 | return |
---|
36 | except: |
---|
37 | print "\nInstall of "+package+" failed. Please report this information:" |
---|
38 | import traceback |
---|
39 | print traceback.format_exc() |
---|
40 | sys.exit() |
---|
41 | |
---|
42 | if missing: |
---|
43 | print """Sorry, this version of Python cannot be used |
---|
44 | for GSAS-II. It is missing the following package(s): |
---|
45 | \t""", |
---|
46 | for pkg in missing: print " ",pkg, |
---|
47 | print |
---|
48 | print "We suggest installing the free Canopy Express package at http://www.enthought.com/downloads" |
---|
49 | print "or the free Anaconda python package at https://store.continuum.io/cshop/anaconda/" |
---|
50 | sys.exit() |
---|
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 | for path in pathlist: |
---|
67 | svn = os.path.join(path,'svn') |
---|
68 | try: |
---|
69 | p = subprocess.Popen([svn,'help'],stdout=subprocess.PIPE) |
---|
70 | res = p.stdout.read() |
---|
71 | p.communicate() |
---|
72 | break |
---|
73 | except: |
---|
74 | pass |
---|
75 | else: |
---|
76 | raise Exception('Subversion (svn) not found') |
---|
77 | print ' found svn in',svn |
---|
78 | |
---|
79 | print 'Ready to bootstrap GSAS-II from repository\n\t',home,'\nto '+gsaspath |
---|
80 | proxycmds = [] |
---|
81 | if os.path.exists("proxyinfo.txt"): |
---|
82 | fp = open("proxyinfo.txt",'r') |
---|
83 | os.remove("proxyinfo.txt") |
---|
84 | print(70*"=") |
---|
85 | ans = raw_input("Enter the proxy address [none needed]: ") |
---|
86 | if ans.strip() != "": |
---|
87 | proxycmds.append('--config-option') |
---|
88 | proxycmds.append('servers:global:http-proxy-host='+ans.strip()) |
---|
89 | fp = open("proxyinfo.txt",'w') |
---|
90 | fp.write(ans.strip()+'\n') |
---|
91 | ans = raw_input("Enter the proxy port [8080]: ") |
---|
92 | if ans.strip() == "": ans="8080" |
---|
93 | proxycmds.append('--config-option') |
---|
94 | proxycmds.append('servers:global:http-proxy-port='+ans.strip()) |
---|
95 | fp.write(ans.strip()+'\n') |
---|
96 | fp.close() |
---|
97 | |
---|
98 | print 'Determining system type...', |
---|
99 | if sys.platform.startswith('linux'): |
---|
100 | #if platform.processor().find('86') <= -1: |
---|
101 | # ans = raw_input("Note, GSAS requires an Intel-compatible processor and 32-bit" |
---|
102 | # "libraries.\nAre you sure want to continue? [Yes]/no: ") |
---|
103 | # if ans.lower().find('no') > -1: sys.exit() |
---|
104 | repos = 'linux' |
---|
105 | print 'Linux, assuming Intel-compatible' |
---|
106 | elif sys.platform == "darwin" and platform.processor() == 'i386': |
---|
107 | repos = 'osxi86' |
---|
108 | print 'Mac OS X, Intel-compatible' |
---|
109 | elif sys.platform == "darwin": |
---|
110 | repos = 'osxppc' |
---|
111 | print 'Mac OS X, PowerPC -- you will need to run scons on fsource files' |
---|
112 | elif sys.platform.startswith('win'): |
---|
113 | repos = 'win' |
---|
114 | print 'Windows' |
---|
115 | else: |
---|
116 | print 'Unidentifed platform -- you probably will need to run scons to compile the fsource files' |
---|
117 | |
---|
118 | cmd = [svn, 'co', home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert'] |
---|
119 | if proxycmds: cmd += proxycmds |
---|
120 | msg = 'loading GSAS-II' |
---|
121 | |
---|
122 | print 70*'*' |
---|
123 | print msg + ' from ' + cmd[2] |
---|
124 | print 'svn load command:' |
---|
125 | for item in cmd: print item, |
---|
126 | print "" |
---|
127 | p = subprocess.call(cmd) |
---|
128 | if p: |
---|
129 | print 'subversion returned an error; Retrying with command for older version...' |
---|
130 | cmd = [svn, 'co', home+ 'trunk/', gsaspath] |
---|
131 | if proxycmds: cmd += proxycmds |
---|
132 | for item in cmd: print item, |
---|
133 | print "" |
---|
134 | p = subprocess.call(cmd) |
---|
135 | |
---|
136 | #=========================================================================== |
---|
137 | # install OpenGL, if needed. |
---|
138 | if install_with_easyinstall: |
---|
139 | print '\nInstalling PyOpenGL. Lots of warnings will follow... ', |
---|
140 | install_with_easyinstall('PyOpenGl') |
---|
141 | print 'done.' |
---|
142 | #=========================================================================== |
---|
143 | # import all .py files so that .pyc files get created |
---|
144 | print 'Byte-compiling all .py files...', |
---|
145 | import compileall |
---|
146 | compileall.compile_dir(gsaspath,quiet=True) |
---|
147 | print 'done' |
---|
148 | #=========================================================================== |
---|
149 | # platform-dependent stuff |
---|
150 | #=========================================================================== |
---|
151 | # on Windows, |
---|
152 | if sys.platform.startswith('win') and os.path.exists( |
---|
153 | os.path.join(gsaspath,"makeBat.py")): |
---|
154 | execfile(os.path.join(gsaspath,"makeBat.py")) |
---|
155 | #=========================================================================== |
---|
156 | # on a Mac, make an applescript |
---|
157 | elif sys.platform.startswith('darwin') and os.path.exists( |
---|
158 | os.path.join(gsaspath,"makeMacApp.py")): |
---|
159 | execfile(os.path.join(gsaspath,"makeMacApp.py")) |
---|
160 | #=========================================================================== |
---|
161 | # On linux, make desktop icon |
---|
162 | elif sys.platform.startswith('linux'): |
---|
163 | desktop_template = """ |
---|
164 | [Desktop Entry] |
---|
165 | Encoding=UTF-8 |
---|
166 | Version=1.0 |
---|
167 | Type=Application |
---|
168 | Terminal=false |
---|
169 | Exec=xterm -hold -e %s |
---|
170 | Name=GSAS-II |
---|
171 | Icon=%s |
---|
172 | """ |
---|
173 | loc = '~/Desktop/' |
---|
174 | eloc = os.path.expanduser(loc) |
---|
175 | dfile = os.path.join(eloc,'GSASII.desktop') |
---|
176 | icon = os.path.join(gsaspath, 'gsas2.png') |
---|
177 | script = os.path.join(gsaspath, 'GSASII.py') |
---|
178 | os.chmod(script, # make the .py file executable and readable |
---|
179 | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) |
---|
180 | if os.path.exists(eloc): |
---|
181 | open(dfile,'w').write(desktop_template % (script,icon)) |
---|
182 | os.chmod( |
---|
183 | dfile, |
---|
184 | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) |
---|
185 | print("created GNOME desktop shortcut "+dfile) |
---|
186 | |
---|