source: install/g2pkg/bootstrap.py @ 2171

Last change on this file since 2171 was 2171, checked in by toby, 7 years ago

single-step installer, as implemented for Mac

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