forked from OSCAAR/OSCAAR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_setup.py
136 lines (114 loc) · 4.57 KB
/
post_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import sys
import time
import atexit
time.sleep(1.0)
""" Loading the just installed oscaar package to test if import is working,
and get the path of the pacakge to complete the installation. """
if not hasattr(sys, 'real_prefix'):
save_path = sys.path[:]
sys.path.remove(os.path.dirname(os.path.abspath(__file__)))
import oscaar
sys.path = save_path
oscaardir = os.path.dirname(os.path.abspath(oscaar.__file__))
print oscaardir
""" Function to download the ds9 version for current platform.
URLs are tested working on 5-29-2013 """
def download_ds9():
sysplf = sys.platform
oscaardirds9 = os.path.join(oscaardir,'extras','ds9',sysplf)
if os.path.exists(os.path.dirname(oscaardirds9)) == True:
print "It seems like DS9 is already installed in the OSCAAR directory."
import urllib2
print 'Downloading platform specific DS9:'
if sysplf == 'darwin':
url = "http://hea-www.harvard.edu/RD/ds9/download/darwinsnowleopard/ds9.darwinsnowleopard.7.2.tar.gz"
elif sysplf == 'linux2':
# url = "http://hea-www.harvard.edu/RD/ds9/download/linux/ds9.linux.7.2.tar.gz" This 32-bit download seems problematic
url = 'http://hea-www.harvard.edu/RD/ds9/download/linux64/ds9.linux64.7.2.tar.gz'
elif sysplf == 'win32':
url = "http://hea-www.harvard.edu/RD/ds9/download/windows/SAOImage%20DS9%207.2%20Install.exe"
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"%10d bytes [%3.2f%%]" % \
(file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()
print
fh = open(file_name, 'rb')
if sys.platform == 'win32':
import zipfile
z = zipfile.ZipFile(fh)
else:
import tarfile
z = tarfile.open(file_name)
if os.path.exists(os.path.dirname(oscaardirds9)) == False:
os.mkdir(os.path.dirname(oscaardirds9))
if os.path.exists(oscaardirds9) == False:
os.mkdir(oscaardirds9)
olddir = os.getcwd()
os.chdir(oscaardirds9)
z.extractall()
fh.close()
if sys.platform != "win32":
os.chmod('ds9',0o777)
os.chdir(olddir)
os.remove(file_name)
print 'DS9 installed in oscaar directory!'
""" Compile C files in c dir of oscaar"""
def complile_C():
print
if sys.platform == 'win32':
import shutil
""" If running Windows, use the precompiled C binary """
print 'copying precompiled C code for light curve modeling..',
shutil.copy2(os.path.join(oscaardir,'c', 'windowsBinaries', \
'analyticalTransitModel.so'), os.path.join(oscaardir,'c', \
'analyticalTransitModel.so'))
print 'done!'
else:
import subprocess
""" Otherwise use python setup to compile a shared library
(works on unix based machines) """
print 'compiling C code for light curve modeling..'
oscaardirC = os.path.join(oscaardir,'c')
olddir = os.getcwd()
os.chdir(oscaardirC)
""" Build the c-library in place """
subprocess.Popen(['python', 'setup.py','build_ext', \
'--inplace']).wait()
os.chdir(olddir)
def to_do_at_exit():
if not hasattr(sys, 'real_prefix'):
#import subprocess
#subprocess.check_call(['python', 'registration.py'])
import re
import urllib2
url = urllib2.urlopen("https://github.com/OSCAAR/OSCAAR/commits/" \
"master").read()
sha = re.search('href="/OSCAAR/OSCAAR/commit/[a-z0-9]*"',
str(url)).group(0).rpartition("/")[2]
with open(os.path.join(os.path.dirname(oscaar.__file__),'__init__.py'),
"a") as myfile:
myfile.write("\n__sha__ = \"%s" % sha)
from oscaar import registration
""" Set function to be executed at exit of code (when script is finished) """
atexit.register(to_do_at_exit)
if __name__ == '__main__':
if not hasattr(sys, 'real_prefix'):
complile_C()
download_ds9()