-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·163 lines (126 loc) · 5.25 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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]: # Setup problem
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]: # Change makefile
MakeProblem(work_dir, pluto_dir, 1, 0)
if interface_optval == interface_opts[2]: # Auto-update
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
# ------------------------------------
# get the path basename and make
# a tar archive
# ------------------------------------
menu.RestoreScreen()
os.chdir(work_dir)
default_name = os.path.basename(work_dir)
os.system("clear")
setup_name = input(" > Archive name ("+default_name+"): ")
complete_backup = 0
scrh = input(" > Backup source files ? (n): ")
if (setup_name == ''):
setup_name = default_name
if (scrh == "y"):
complete_backup = 1
setup_name = setup_name+".tar"
ifail = os.system ("tar cvf "+setup_name+" *.c *.ini *.h")
# -------------------------------
# back up source tree
# -------------------------------
if (complete_backup):
ifail = ifail or os.system("tar rvf "+setup_name+" --directory="+pluto_dir+"/ Src/ ")
ifail = ifail or os.system("tar rvf "+setup_name+" --directory="+pluto_dir+"/ Config/")
ifail = ifail or os.system("tar rvf "+setup_name+" makefile")
ifail = ifail or os.system ("gzip -f "+setup_name)
if (ifail == 0):
print (" > "+setup_name+".gz successfully created\n")
else:
print (" ! Error creating "+setup_name+".gz\n")
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 (" --no-interactive Read input from stdin (use with --no-curses)")
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-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']) & 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-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")
elif (x == "--no-interactive"):
print ("No Interactive")
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)