source: install/g2pkg/src/bootstrap.py @ 2345

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

fix for Windows directories with spaces

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