-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathadd_new_effect.py
executable file
·62 lines (52 loc) · 1.86 KB
/
add_new_effect.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
#!/usr/bin/python
# Call this after adding a new effect source file, e.g., effect.c. It takes all the .c files in reboundx/src and adds them to all the Makefiles where needed
import glob
import os
import sys
sources = [each for each in os.listdir('../src/') if each.endswith('.c')]
print("Adding {0}".format(sources))
sourcestring = "SOURCES="
sourcesExamples = "SOURCES="
sourcesSetup = " sources = ["
for source in sources:
sourcestring += source + " "
sourcesExamples += "$(REBOUNDXDIR)" + source + " "
sourcesSetup += ' \'src/' + source + '\','
sourcestring += "\n"
sourcesExamples += "\n"
sourcesSetup = sourcesSetup[:-1] + '],\n' # remove comma after last source
with open("../src/Makefile") as f:
lines = f.readlines()
for i,l in enumerate(lines):
if "modify_orbits_direct.c" in l:
lines[i] = sourcestring
with open("../src/Makefile", "w") as f:
f.writelines(lines)
with open("../examples/Makefile") as f:
lines = f.readlines()
for i,l in enumerate(lines):
if "modify_orbits_direct.c" in l:
lines[i] = sourcesExamples
with open("../examples/Makefile", "w") as f:
f.writelines(lines)
'''
for example in os.listdir('../examples/'):
try:
with open("../examples/" + example + "/Makefile") as f:
lines = f.readlines()
for i,l in enumerate(lines):
if "modify_orbits_direct.c" in l:
print('here')
lines[i] = sourcesExamples
with open("../examples/" + example + "/Makefile", "w") as f:
f.writelines(lines)
except:
pass
'''
with open("../setup.py") as f:
setuplines = f.readlines()
for i,l in enumerate(setuplines):
if 'src/' in l:
setuplines[i] = sourcesSetup
with open("../setup.py", "w") as f:
f.writelines(setuplines)