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