source: install/bootstrap.py @ 2535

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

remove g2conda-specific stuff from stand-alone bootstrap

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