source: install/bootstrap.py @ 2128

Last change on this file since 2128 was 2128, checked in by toby, 6 years ago

fix quotes on install error

File size: 6.6 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*'*'
8print 'Checking python packages...',
9missing = []
10for 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
16try:
17    import OpenGL as ogl
18    install_with_easyinstall = None
19except 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
42if missing:
43    print """Sorry, this version of Python cannot be used
44for 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
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')
66for 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
75else:
76    raise Exception('Subversion (svn) not found')
77print ' found svn in',svn
78
79print 'Ready to bootstrap GSAS-II from repository\n\t',home,'\nto '+gsaspath
80proxycmds = []
81if os.path.exists("proxyinfo.txt"):
82    fp = open("proxyinfo.txt",'r')
83    os.remove("proxyinfo.txt")
84print(70*"=")
85ans = raw_input("Enter the proxy address [none needed]: ")
86if 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
98print 'Determining system type...',
99if 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'
106elif sys.platform == "darwin" and platform.processor() == 'i386':
107    repos = 'osxi86'
108    print 'Mac OS X, Intel-compatible'
109elif sys.platform == "darwin":
110    repos = 'osxppc'
111    print 'Mac OS X, PowerPC -- you will need to run scons on fsource files'
112elif sys.platform.startswith('win'):
113    repos = 'win'
114    print 'Windows'
115else:
116    print 'Unidentifed platform -- you probably will need to run scons to compile the fsource files'
117
118cmd = [svn, 'co', home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert']
119if proxycmds: cmd += proxycmds
120msg = 'loading GSAS-II'
121   
122print 70*'*'
123print msg + ' from ' + cmd[2]
124print 'svn load command:'
125for item in cmd: print item,
126print ""
127p = subprocess.call(cmd)
128if 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.
138if 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
144print 'Byte-compiling all .py files...',
145import compileall
146compileall.compile_dir(gsaspath,quiet=True)
147print 'done'
148#===========================================================================
149# platform-dependent stuff
150#===========================================================================
151# on Windows,
152if 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
157elif 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
162elif sys.platform.startswith('linux'):
163    desktop_template = """
164[Desktop Entry]
165Encoding=UTF-8
166Version=1.0
167Type=Application
168Terminal=false
169Exec=xterm -hold -e %s
170Name=GSAS-II
171Icon=%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
Note: See TracBrowser for help on using the repository browser.