PLUTO
setup.py
Go to the documentation of this file.
1 import os
2 import sys
3 import shutil
4 
5 try:
6  os.environ['PLUTO_DIR']
7 except KeyError:
8  print 'PLUTO_DIR not defined. Setting it to the Current Directory'
9  pluto_directory = os.getcwd()
10  pass
11 else:
12  pluto_directory = os.environ['PLUTO_DIR']
13 
14 sys.path.append(pluto_directory + '/Tools/Python/')
15 import menu
16 import configure
17 from make_problem import MakeProblem
18 
19 
20 def PlutoInterFace(pluto_dir, do_auto_update = False):
21  work_dir = os.getcwd()
22  interface_optval = ''
23  interface_opts = ['Setup problem', 'Change makefile',
24  'Auto-update','Save Setup','Quit']
25 
26  if do_auto_update:
27  MakeProblem(work_dir, pluto_dir, 1, 1)
28  interface_optval = interface_opts[-1] # set to "Quit" so it'll skip next loop
29 
30  while interface_optval != interface_opts[-1]:
31  menu.SetTitle("Python setup (Aug 2015)","Working dir: "+work_dir+"\nPLUTO dir : "+pluto_dir)
32 
33  interface_optval = menu.Browse(interface_opts)
34 
35  if interface_optval == interface_opts[0]:
36  if not os.path.exists(work_dir+'/init.c'):
37  shutil.copy(pluto_dir+'/Src/Templates/init.c',work_dir+'/init.c')
38 
39  if not os.path.exists(work_dir+'/pluto.ini'):
40  shutil.copy(pluto_dir+'/Src/Templates/pluto.ini',work_dir+'/pluto.ini')
41 
42  MakeProblem(work_dir, pluto_dir, 0, 1)
43 
44  if interface_optval == interface_opts[1]:
45  MakeProblem(work_dir, pluto_dir, 1, 0)
46 
47  if interface_optval == interface_opts[2]:
48  menu.Prompt('Press Enter to Update '+work_dir)
49  MakeProblem(work_dir, pluto_dir, 1, 1)
50  menu.Print ("Configuration up to date",sleep=0.75)
51  break
52 
53  if interface_optval == interface_opts[3]: #Save Setup
54  sys.exit()
55 
57  print "\n> Done."
58  sys.exit()
59 
60 if __name__ == "__main__": # starts from here
61  auto_update = 0
62  print "\n> Checking system architecture\n"
63  configure.check(pluto_directory, 1)
64  for x in sys.argv[1:]: # check argument list
65  if (x == "--get-arch"):
66  sys.exit(1)
67  break
68 
69  if (x == "--with-chombo" or x == "--with-chombo:"):
70  print "Enabling Chombo support for AMR"
71  cmset = set(['--with-fd','--with-sb','--with-fargo']) & set(sys.argv)
72  if len(cmset) != 0:
73  print '! Incompatible modules, ',x,' + '.join(y for y in cmset)
74  sys.exit(1)
75  break
76 
77  elif (x == "--with-sb"):
78  print "Enabling support for shearing box module"
79  if '--with-fd' in sys.argv:
80  print '! Incompatible modules, ',x,' + --with-fd'
81  sys.exit(1)
82 
83  elif (x == "--with-fd"):
84  print "Enabling support for finite difference module"
85 
86  elif (x == "--with-fargo"):
87  print "Enabling support for FARGO scheme"
88 
89  elif (x == "--no-curses"):
90  print ""
91 
92  elif (x == "--auto-update"):
93  auto_update = 1
94 
95  elif (x == "--help" or x == "-help"):
96  print "Usage: python $PLUTO_DIR/setup.py [options]\n"
97  print "Here [options] can be:\n"
98  print " --with-sb enable the shearing box module."
99  print " --with-fd enable the finite difference module."
100  print " --with-fargo enable the FARGO-MHD module"
101  print " --with-chombo enable support for adaptive mesh refinement."
102  print " (AMR) module using the Chombo library."
103  print " --no-curses disable ncurses library and use a"
104  print " simpler text-based menu."
105  sys.exit(1)
106 
107  else:
108  print "! Unrecognized option '",x,"'"
109  sys.exit(1)
110 
111  print '\n> Loading PLUTO Interface...'
112 
113  if auto_update == 1:
114  PlutoInterFace(pluto_directory,do_auto_update=True)
115  else:
116  PlutoInterFace(pluto_directory)
117 
118 
def RestoreScreen()
Restore screen back to shell functionality.
Definition: menu.py:287
def CursesIsActive()
Return 1 if curses have been activated.
Definition: menu.py:312
def PlutoInterFace
Definition: setup.py:20
def SetTitle
Definition: menu.py:50
def Browse
Browse a menu with entries (1st column) and default (2nd column, optional) Note: with Python > 2...
Definition: menu.py:181
def Prompt(message)
Prompt a message, wait for any key to be pressed.
Definition: menu.py:78
def check(pluto_dir, get_arch)
Definition: configure.py:6