1 | #!/usr/bin/env python |
---|
2 | import os, stat, sys, platform, subprocess |
---|
3 | home = 'https://subversion.xray.aps.anl.gov/EXPGUI/' |
---|
4 | proxycmds = [] |
---|
5 | if os.path.exists("proxyinfo.txt"): |
---|
6 | os.remove("proxyinfo.txt") |
---|
7 | print(70*"=") |
---|
8 | print(70*"=") |
---|
9 | ans = raw_input("Enter the proxy address [none needed]: ") |
---|
10 | if 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() |
---|
21 | gsaspath = os.path.split(sys.argv[0])[0] |
---|
22 | gsaspath = os.path.abspath(os.path.expanduser(gsaspath)) |
---|
23 | print 'GSAS is being bootstrapped from repository to '+gsaspath |
---|
24 | print 'Determining system type...', |
---|
25 | if 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' |
---|
32 | elif sys.platform == "darwin" and platform.processor() == 'i386': |
---|
33 | repos = 'osxi86' |
---|
34 | print 'Mac OS X, Intel-compatible' |
---|
35 | elif sys.platform == "darwin": |
---|
36 | repos = 'osxppc' |
---|
37 | print 'Mac OS X, PowerPC' |
---|
38 | else: |
---|
39 | raise Exception('Undefined system type') |
---|
40 | print 'OK' |
---|
41 | |
---|
42 | print 'Checking for subversion...', |
---|
43 | try: |
---|
44 | p = subprocess.Popen(['svn','help','switch'],stdout=subprocess.PIPE) |
---|
45 | except: |
---|
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') |
---|
51 | res = p.stdout.read() |
---|
52 | if res.find('--ignore-ancestry') == -1: |
---|
53 | print ' svn <=1.6 OK' |
---|
54 | svnopt = '' |
---|
55 | else: |
---|
56 | svnopt = '--ignore-ancestry' |
---|
57 | print ' svn >=1.7 OK' |
---|
58 | |
---|
59 | if os.path.exists(os.path.join(gsaspath,'.svn')): |
---|
60 | p = subprocess.Popen(['svn','info',gsaspath],stdout=subprocess.PIPE) |
---|
61 | res = p.stdout.read() |
---|
62 | else: |
---|
63 | res = '' |
---|
64 | |
---|
65 | cmds = [ |
---|
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 | |
---|
72 | if 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 | |
---|
79 | for 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 | |
---|
88 | if 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 | |
---|
95 | elif 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_linux.png'), |
---|
101 | os.path.join(gsaspath,'EXPGUI.png')) |
---|
102 | shutil.copy(os.path.join(gsaspath,'GSAS_linux.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] |
---|
107 | Encoding=UTF-8 |
---|
108 | Version=1.0 |
---|
109 | Type=Application |
---|
110 | Terminal=false |
---|
111 | Exec=%s/expgui/expgui |
---|
112 | Name=EXPGUI |
---|
113 | Icon=%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] |
---|
119 | Encoding=UTF-8 |
---|
120 | Version=1.0 |
---|
121 | Type=Application |
---|
122 | Terminal=true |
---|
123 | Exec=%s/GSAS |
---|
124 | Name=GSAS |
---|
125 | Icon=%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)' |
---|