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

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

seems to work, but problem in updating install.bat

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