Kindfield
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends Pages
run_app.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 import subprocess
3 import os
4 import os.path
5 import signal
6 import shutil
7 from sys import argv
8 from argparse import ArgumentParser
9 
10 
11 parser = ArgumentParser()
12 parser.add_argument("config_file")
13 parser.add_argument("--id", nargs='?', default="tmp")
14 args = parser.parse_args()
15 
16 output_dir = os.path.abspath("tmp")
17 
18 if args.id != "tmp":
19  try:
20  from sumatra.projects import load_project
21  output_dir = os.path.join(os.path.abspath(load_project().data_store.root), args.id)
22  except ImportError:
23  pass
24 
25 current_path = os.path.dirname(os.path.realpath(__file__))
26 
27 if not os.path.exists(output_dir):
28  os.makedirs(output_dir)
29 
30 config_file = os.path.abspath(argv[1])
31 
32 output_file = os.path.join(output_dir, os.path.split(config_file)[-1])
33 
34 build_path = os.path.abspath(os.path.join(current_path, "..", "..", "build-app"))
35 project_path = os.path.abspath(os.path.join(current_path, ".."))
36 
37 if not os.path.exists(build_path):
38  os.makedirs(build_path)
39 devnull = open('/dev/null', 'w')
40 subprocess.call(["qmake", project_path, "CONFIG+=nogui CONFIG+=notests CONFIG+=notools"], cwd=build_path, stdout=devnull)
41 subprocess.call(["make", "-j", "8"], cwd=build_path, stdout=devnull)
42 
43 app_path = os.path.join(build_path, "app")
44 lib_path = os.path.join(build_path, "src")
45 
46 env = dict(os.environ)
47 env['LD_LIBRARY_PATH'] = lib_path
48 #proc = subprocess.call(["./staterunner", states_file, output_file], cwd=staterunner_path, env=env)
49 run_argument = ["./hartree-fock", config_file, output_dir]
50 proc = subprocess.call(run_argument, cwd=app_path, env=env)
51 #shutil.copyfile(os.path.join(app_path, "results.h5"), os.path.join(output_dir, "results.h5"))