1 | #!/usr/bin/env python |
---|
2 | import os, stat, sys, platform, subprocess |
---|
3 | home = 'https://subversion.xray.aps.anl.gov/pyGSAS/' |
---|
4 | print 70*'*' |
---|
5 | print 'Checking python packages...', |
---|
6 | missing = [] |
---|
7 | for pkg in ['numpy','scipy','matplotlib','wx']: |
---|
8 | try: |
---|
9 | exec('import '+pkg) |
---|
10 | except: |
---|
11 | missing.append(pkg) |
---|
12 | |
---|
13 | if missing: |
---|
14 | print """Sorry, this version of Python cannot be used |
---|
15 | for GSAS-II. It is missing the following package(s): |
---|
16 | \t""", |
---|
17 | for pkg in missing: print " ",pkg, |
---|
18 | print |
---|
19 | if sys.platform.startswith('darwin'): |
---|
20 | print "We suggest installing the EPD Free Python package (epd_free-7.3-2-macosx-i386.dmg)\nat https://www.enthought.com/repo/free/\nor the 64-bit Canopy Express package at http://www.enthought.com/downloads" |
---|
21 | else: |
---|
22 | print "We suggest installing the Canopy Express package at http://www.enthought.com/downloads" |
---|
23 | sys.exit() |
---|
24 | |
---|
25 | gsaspath = os.path.split(sys.argv[0])[0] |
---|
26 | gsaspath = os.path.abspath(os.path.expanduser(gsaspath)) |
---|
27 | |
---|
28 | print 'Checking for subversion...', |
---|
29 | # add the standard location for wandisco svn to the path |
---|
30 | for path in os.environ['PATH'].split(':')+['/opt/subversion/bin',]: |
---|
31 | svn = os.path.join(path,'svn') |
---|
32 | try: |
---|
33 | p = subprocess.Popen([svn,'help'],stdout=subprocess.PIPE) |
---|
34 | res = p.stdout.read() |
---|
35 | p.communicate() |
---|
36 | break |
---|
37 | except: |
---|
38 | pass |
---|
39 | else: |
---|
40 | raise Exception('Subversion (svn) not found') |
---|
41 | print ' found svn in',svn |
---|
42 | print 'OK' |
---|
43 | |
---|
44 | print 'GSAS-II is being bootstrapped from repository\n\t',home,'\nto '+gsaspath |
---|
45 | |
---|
46 | print 'Determining system type...', |
---|
47 | if sys.platform.startswith('linux'): |
---|
48 | #if platform.processor().find('86') <= -1: |
---|
49 | # ans = raw_input("Note, GSAS requires an Intel-compatible processor and 32-bit" |
---|
50 | # "libraries.\nAre you sure want to continue? [Yes]/no: ") |
---|
51 | # if ans.lower().find('no') > -1: sys.exit() |
---|
52 | repos = 'linux' |
---|
53 | print 'Linux, assuming Intel-compatible' |
---|
54 | elif sys.platform == "darwin" and platform.processor() == 'i386': |
---|
55 | repos = 'osxi86' |
---|
56 | print 'Mac OS X, Intel-compatible' |
---|
57 | elif sys.platform == "darwin": |
---|
58 | repos = 'osxppc' |
---|
59 | print 'Mac OS X, PowerPC -- you will need to run scons on fsource files' |
---|
60 | else: |
---|
61 | print 'Unidentifed platform -- you may need to run scons on fsource files' |
---|
62 | |
---|
63 | cmd = [svn, 'co', home+ 'trunk/', gsaspath, '--non-interactive', '--trust-server-cert'] |
---|
64 | msg = 'loading GSAS-II' |
---|
65 | |
---|
66 | print 70*'*' |
---|
67 | print msg + ' from ' + cmd[2] |
---|
68 | for item in cmd: print item, |
---|
69 | print "" |
---|
70 | p = subprocess.call(cmd) |
---|
71 | if p: |
---|
72 | print 'subversion returned an error; Retrying...' |
---|
73 | cmd = [svn, 'co', home+ 'trunk/', gsaspath] |
---|
74 | p = subprocess.call(cmd) |
---|
75 | |
---|
76 | #=========================================================================== |
---|
77 | # could try to load .so files here and run scons if needed. |
---|
78 | |
---|
79 | #=========================================================================== |
---|
80 | # on a Mac, make an applescript |
---|
81 | if sys.platform.startswith('darwin') and os.path.exists( |
---|
82 | os.path.join(gsaspath,"makeMacApp.py")): |
---|
83 | execfile(os.path.join(gsaspath,"makeMacApp.py")) |
---|
84 | #=========================================================================== |
---|
85 | # On linux, make desktop icon |
---|
86 | if sys.platform.startswith('linux'): |
---|
87 | desktop_template = """ |
---|
88 | [Desktop Entry] |
---|
89 | Encoding=UTF-8 |
---|
90 | Version=1.0 |
---|
91 | Type=Application |
---|
92 | Terminal=false |
---|
93 | Exec=xterm -hold -e %s |
---|
94 | Name=GSAS-II |
---|
95 | Icon=%s |
---|
96 | """ |
---|
97 | loc = '~/Desktop/' |
---|
98 | eloc = os.path.expanduser(loc) |
---|
99 | dfile = os.path.join(eloc,'GSASII.desktop') |
---|
100 | icon = os.path.join(gsaspath, 'gsas2.png') |
---|
101 | script = os.path.join(gsaspath, 'GSASII.py') |
---|
102 | os.chmod(script, # make the .py file executable and readable |
---|
103 | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) |
---|
104 | if os.path.exists(eloc): |
---|
105 | open(dfile,'w').write(desktop_template % (script,icon)) |
---|
106 | os.chmod( |
---|
107 | dfile, |
---|
108 | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) |
---|
109 | print("created GNOME desktop shortcut "+dfile) |
---|