source: gsas/linux/dist/bootstrap.py

Last change on this file was 1244, checked in by toby, 9 years ago

more linux fixes

  • Property svn:executable set to *
File size: 4.8 KB
Line 
1#!/usr/bin/env python
2import os, stat, sys, platform, subprocess
3home = 'https://subversion.xray.aps.anl.gov/EXPGUI/'
4proxycmds = []
5if os.path.exists("proxyinfo.txt"):
6    os.remove("proxyinfo.txt")
7print(70*"=")
8print(70*"=")
9ans = raw_input("Enter the proxy address [none needed]: ")
10if ans.strip() != "":
11    proxycmds.append('--config-option')
12    proxycmds.append('servers:global:http-proxy-host='+ans.strip())
13    fp = open("proxyinfo.txt",'w')
14    fp.write(ans.strip()+'\n')
15    ans = raw_input("Enter the proxy port [8080]: ")
16    if ans.strip() == "": ans="8080"
17    proxycmds.append('--config-option')
18    proxycmds.append('servers:global:http-proxy-port='+ans.strip())
19    fp.write(ans.strip()+'\n')
20    fp.close()
21gsaspath = os.path.split(sys.argv[0])[0]
22gsaspath = os.path.abspath(os.path.expanduser(gsaspath))
23print 'GSAS is being bootstrapped from repository to '+gsaspath
24print 'Determining system type...',
25if sys.platform.startswith('linux'):
26    if platform.processor().find('86') <= -1:
27        ans = raw_input("Note, GSAS requires an Intel-compatible processor and 32-bit"
28                        "libraries.\nAre you sure want to continue? [Yes]/no: ")
29        if ans.lower().find('no') > -1: sys.exit()
30    repos = 'linux'
31    print 'Linux, Intel-compatible'
32elif sys.platform == "darwin" and platform.processor() == 'i386':
33    repos = 'osxi86'
34    print 'Mac OS X, Intel-compatible'
35elif sys.platform == "darwin":
36    repos = 'osxppc'
37    print 'Mac OS X, PowerPC'
38else:
39    raise Exception('Undefined system type')
40print 'OK'
41
42print 'Checking for subversion...',
43try: 
44    p = subprocess.Popen(['svn','help','switch'],stdout=subprocess.PIPE)
45except:
46    if sys.platform.startswith('linux'):
47        print('Use "yum install svn" or "dpkg",... to install svn/subversion')
48    elif sys.platform == "darwin":
49        print('See https://subversion.xray.aps.anl.gov/trac/EXPGUI/wiki/InstallOSX for info on installing svn/subversion')
50    raise Exception('Subversion (svn) not found')
51res = p.stdout.read()
52if res.find('--ignore-ancestry') == -1:
53    print ' svn <=1.6 OK'
54    svnopt = ''
55else:
56    svnopt = '--ignore-ancestry'
57    print ' svn >=1.7 OK'
58
59if os.path.exists(os.path.join(gsaspath,'.svn')):
60    p = subprocess.Popen(['svn','info',gsaspath],stdout=subprocess.PIPE)
61    res = p.stdout.read()
62else:
63    res = ''
64
65cmds = [
66    (['svn', 'co', home+ 'gsas/all', gsaspath],'loading GSAS common'),
67    (['svn', 'switch', home+ 'trunk/', gsaspath+'/expgui'],'loading EXPGUI'),
68    (['svn', 'switch', home+ 'gsas/' + repos+ '/exe/', gsaspath+'/exe'],'loading GSAS programs'),
69    (['svn', 'switch', home+ 'gsas/' + repos+ '/pgl/', gsaspath+'/pgl'],'loading PGPLOT files'),
70]
71
72if res.find('.xor.aps.') != -1:
73    cmds.insert(0,
74               (['svn', 'switch', '--relocate',
75                 'https://subversion.xor.aps.anl.gov/EXPGUI', home, gsaspath],
76                'Switching EXPGUI repository to xray.aps')
77               )
78
79for cmd,msg in cmds: 
80    print 70*'*'
81    print msg
82    if proxycmds: cmd += proxycmds
83    if svnopt and cmd[1] == 'switch': cmd += [svnopt]
84    for item in cmd: print item,
85    print ""
86    p = subprocess.call(cmd)
87
88if sys.platform.startswith('darwin'):
89    appmaker = os.path.join(gsaspath,'expgui','makeMacApp.py')
90    if os.path.exists(appmaker):
91        execfile(appmaker)
92    else:
93        print("file "+str(appmaker)+" not found")
94
95elif sys.platform.startswith('linux'):
96    os.chmod(gsaspath + "/expgui/expgui", 
97             stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) 
98    if not os.path.exists(os.path.join(gsaspath,'EXPGUI.png')):
99        import shutil
100        shutil.copy(os.path.join(gsaspath,'expgui','EXPGUI.png'),
101                    os.path.join(gsaspath,'EXPGUI.png'))
102        shutil.copy(os.path.join(gsaspath,'expgui','GSAS.png'),
103                    os.path.join(gsaspath,'GSAS.png'))
104    if os.path.exists(os.path.expanduser('~/Desktop/')):
105        open(os.path.expanduser('~/Desktop/EXPGUI.desktop'),'w').write('''
106[Desktop Entry]
107Encoding=UTF-8
108Version=1.0
109Type=Application
110Terminal=false
111Exec=%s/expgui/expgui
112Name=EXPGUI
113Icon=%s/EXPGUI.png
114''' % (gsaspath,gsaspath))
115        os.chmod(os.path.expanduser('~/Desktop/EXPGUI.desktop'),
116                 stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH) 
117        open(os.path.expanduser('~/Desktop/GSAS.desktop'),'w').write('''
118[Desktop Entry]
119Encoding=UTF-8
120Version=1.0
121Type=Application
122Terminal=true
123Exec=%s/GSAS
124Name=GSAS
125Icon=%s/GSAS.png
126''' % (gsaspath,gsaspath))
127        os.chmod(os.path.expanduser('~/Desktop/GSAS.desktop'),
128                 stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH)
129    else:
130        print 'No Desktop directory found, are you running this as root?'
131        #print 'Run '+str(os.path.join(gsaspath,'mkGnomeIcon.py'))+' from your user account(s)'
Note: See TracBrowser for help on using the repository browser.