source: install/bootstrap.py @ 2424

Last change on this file since 2424 was 2410, checked in by toby, 5 years ago

update for new mac build

File size: 6.9 KB
Line 
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.
5import os, stat, sys, platform, subprocess
6home = 'https://subversion.xray.aps.anl.gov/pyGSAS/'
7print 70*'*'
8#testing for incorrect locale code'
9try:
10    import locale
11    locale.getdefaultlocale()
12except 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()
18print 'Preloading matplotlib to build fonts...'
19try:
20    import matplotlib
21except:
22    pass
23print 'Checking python packages...',
24missing = []
25for pkg in ['numpy','scipy','matplotlib','wx',]:
26    try:
27        exec('import '+pkg)
28    except:
29        missing.append(pkg)
30
31if missing:
32    print """Sorry, this version of Python cannot be used
33for 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()
43try:
44    import OpenGL
45except:
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
53gsaspath = os.path.split(sys.argv[0])[0]
54if not gsaspath: gsaspath = os.path.curdir
55gsaspath = os.path.abspath(os.path.expanduser(gsaspath))
56
57print '\nChecking for subversion...',
58if 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'))
62else:
63    pathlist = os.environ['PATH'].split(':')
64    # add the standard location for wandisco svn to the path
65    pathlist.append('/opt/subversion/bin')
66if sys.platform.startswith('win'):
67    svn = 'svn.exe'
68else:
69    svn = 'svn'
70# use svn installed via conda 1st (mac)
71if 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)
74if 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
77for 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
86else:
87    raise Exception('Subversion (svn) not found')
88print ' found svn image: '+svn
89
90print 'Ready to bootstrap GSAS-II from repository\n\t',home,'\nto '+gsaspath
91proxycmds = []
92if os.path.exists("proxyinfo.txt"):
93    fp = open("proxyinfo.txt",'r')
94    os.remove("proxyinfo.txt")
95print(70*"=")
96ans = raw_input("Enter the proxy address [none needed]: ")
97if 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
109print 'Determining system type...',
110if 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'
117elif sys.platform == "darwin" and platform.processor() == 'i386':
118    repos = 'osxi86'
119    print 'Mac OS X, Intel-compatible'
120elif sys.platform == "darwin":
121    repos = 'osxppc'
122    print 'Mac OS X, PowerPC -- you will need to run scons on fsource files'
123elif sys.platform.startswith('win'):
124    repos = 'win'
125    print 'Windows'
126else:
127    print 'Unidentifed platform -- you probably will need to run scons to compile the fsource files'
128
129cmd = [svn, 'co', home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert']
130if proxycmds: cmd += proxycmds
131msg = 'loading GSAS-II'
132   
133print 70*'*'
134print msg + ' from ' + cmd[2]
135print 'svn load command:'
136for item in cmd: print item,
137print ""
138p = subprocess.call(cmd)
139if 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
149print 'Byte-compiling all .py files...',
150import compileall
151compileall.compile_dir(gsaspath,quiet=True)
152print 'done'
153#===========================================================================
154# platform-dependent stuff
155#===========================================================================
156# on Windows,
157if 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
162elif 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
168elif sys.platform.startswith('linux'):
169    desktop_template = """
170[Desktop Entry]
171Encoding=UTF-8
172Version=1.0
173Type=Application
174Terminal=false
175Exec=xterm -hold -e %s
176Name=GSAS-II
177Icon=%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
Note: See TracBrowser for help on using the repository browser.