forked from black-hole-group/pluto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·127 lines (97 loc) · 3.96 KB
/
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
import os
import sys
import shutil
try:
os.environ['PLUTO_DIR']
except KeyError:
print('PLUTO_DIR not defined. Setting it to the Current Directory')
pluto_directory = os.getcwd()
pass
else:
pluto_directory = os.environ['PLUTO_DIR']
sys.path.append(pluto_directory + '/Tools/Python/')
import menu
import configure
from make_problem import MakeProblem
def PlutoInterface(pluto_dir, do_auto_update = False):
work_dir = os.getcwd()
interface_optval = ''
interface_opts = ['Setup problem', 'Change makefile',
'Auto-update','Save Setup','Quit']
if do_auto_update:
MakeProblem(work_dir, pluto_dir, 1, 1)
interface_optval = interface_opts[-1] # set to "Quit" so it'll skip next loop
while interface_optval != interface_opts[-1]:
menu.SetTitle("Python setup (May 2018)","Working dir: "+work_dir+"\nPLUTO dir : "+pluto_dir)
interface_optval = menu.Browse(interface_opts)
if interface_optval == interface_opts[0]:
if not os.path.exists(work_dir+'/init.c'):
shutil.copy(pluto_dir+'/Src/Templates/init.c',work_dir+'/init.c')
if not os.path.exists(work_dir+'/pluto.ini'):
shutil.copy(pluto_dir+'/Src/Templates/pluto.ini',work_dir+'/pluto.ini')
MakeProblem(work_dir, pluto_dir, 0, 1)
if interface_optval == interface_opts[1]:
MakeProblem(work_dir, pluto_dir, 1, 0)
if interface_optval == interface_opts[2]:
menu.Prompt('Press Enter to Update '+work_dir)
MakeProblem(work_dir, pluto_dir, 1, 1)
menu.Print ("Configuration up to date",sleep=0.75)
break
if interface_optval == interface_opts[3]: #Save Setup
sys.exit()
if (menu.CursesIsActive()): menu.RestoreScreen()
print("\n> Done.")
sys.exit()
if __name__ == "__main__": # starts from here
auto_update = 0
print("\n> Checking system architecture\n")
configure.check(pluto_directory, 1)
for x in sys.argv[1:]: # check argument list
if (x == "--auto-update"):
auto_update = 1
elif (x == "--get-arch"):
sys.exit(1)
break
elif (x == "--help" or x == "-help"):
print ("Usage: python $PLUTO_DIR/setup.py [options]\n")
print ("Here [options] can be:\n")
print (" --auto-update Run the python script in background.")
print (" --no-curses Disable ncurses library and use a")
print (" simpler text-based menu.")
print (" --with-chombo Enable support for adaptive mesh refinement.")
print (" (AMR) module using the Chombo library.")
print (" --with-fargo Enable the FARGO-MHD module.")
print (" --with-fd Enable the finite difference module.")
print (" --with-particles Enable the particle module.")
print (" --with-sb Enable the shearing box module.")
sys.exit(1)
elif (x == "--no-curses"):
print("")
elif (x == "--with-chombo" or x == "--with-chombo:"):
print ("Enabling Chombo support for AMR")
cmset = set(['--with-fd','--with-sb','--with-fargo','--with-particles']) & set(sys.argv)
if len(cmset) != 0:
print('! Incompatible modules, ',x,' + '.join(y for y in cmset))
sys.exit(1)
break
elif (x == "--with-fargo"):
print ("Enabling support for FARGO scheme")
elif (x == "--with-fd"):
print ("Enabling support for finite difference module")
elif (x == "--with-particles"):
print ("Enabling support for particles")
elif (x == "--with-sb"):
print ("Enabling support for shearing box module")
if '--with-fd' in sys.argv:
print('! Incompatible modules, ',x,' + --with-fd')
sys.exit(1)
elif (x == "--with-cr_transport"):
print ("Enabling support for cr_transport module")
else:
print ("! Unrecognized option '",x,"'")
sys.exit(1)
print('\n> Loading PLUTO Interface...')
if auto_update == 1:
PlutoInterface(pluto_directory,do_auto_update=True)
else:
PlutoInterface(pluto_directory)