Commit 79a3cb0d authored by Lukas Riedel's avatar Lukas Riedel

Revert "Move 'dorie' wrapper into Python package."

This reverts commit 57729908.
parent 69eb43f5
......@@ -2,10 +2,8 @@
build-cmake/
# Exclude generated files
python/dorie/wrapper/dorie
python/dorie/wrapper/pf_from_file.py
python/dorie/wrapper/test_dorie.py
python/dorie/cli/cmds.py
# Ignore temporary and auto-generated files #
*~
......
......@@ -41,6 +41,7 @@ dune_enable_all_packages()
dune_require_cxx_standard(MODULE "dorie" VERSION 14)
# add subdirectories
add_subdirectory("bin")
add_subdirectory("m4")
add_subdirectory("cmake/modules")
add_subdirectory("python")
......
configure_file(dorie.in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dorie @ONLY)
# copy the temporary file into the final destination, setting the permissions
file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dorie
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/dorie DESTINATION ${CMAKE_INSTALL_BINDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
#!/usr/bin/env python3
import os
import sys
import shutil
import argparse
import warnings
import subprocess
import multiprocessing
try: # Python 2.x compatibility
input = raw_input
......@@ -14,10 +19,12 @@ MPIEXEC = "@MPIEXEC@"
MPIEXEC_NUMPROC_FLAG = "@MPIEXEC_NUMPROC_FLAG@"
MPIEXEC_PREFLAG = "@MPIEXEC_PREFLAG@"
MPIEXEC_POSTFLAGS = "@MPIEXEC_POSTFLAGS@"
#
# set some paths
DORIE_EXECUTABLE = os.path.join(DORIEDIR, "dune/dorie/dorie")
PARAMETERDIR = os.path.join(DORIEDIR, "doc/default_files")
DORIE_PYTHON = os.path.join(DORIEDIR, "run-in-dune-env")
def MPIRUN(nproc,exe,*args,**kwargs):
mpi_flags = kwargs.get("mpi_flags") or []
return [k for k in [MPIEXEC,MPIEXEC_NUMPROC_FLAG,str(nproc)] \
......@@ -52,13 +59,13 @@ def pfg(args):
raise IOError("Configuration file {} not found".format(args["config"]))
try:
if args["parallel"] == 1:
subprocess.check_call(["pf_from_file.py", args["config"]])
subprocess.check_call([DORIE_PYTHON, "pf_from_file.py", args["config"]])
else:
if args["mpi_flags"]:
mpi_flags = ["--mpi-flags=" + f for f in args["mpi_flags"]]
else:
mpi_flags = []
subprocess.check_call(["pf_from_file.py", args["config"],
subprocess.check_call([DORIE_PYTHON, "pf_from_file.py", args["config"],
"--parallel", str(args["parallel"])] + mpi_flags)
except subprocess.CalledProcessError:
print("Error while running DORiE")
......@@ -69,9 +76,69 @@ def plot(args):
raise IOError("File {} not found".format(args["vtk"]))
try:
if args["var"]:
subprocess.check_call(["plot_vtk.py", "-f", args["vtk"], "--var", args["var"]])
subprocess.check_call([DORIE_PYTHON, "plot_vtk.py", "-f", args["vtk"], "--var", args["var"]])
else:
subprocess.check_call(["plot_vtk.py", "-f", args["vtk"]])
subprocess.check_call([DORIE_PYTHON, "plot_vtk.py", "-f", args["vtk"]])
except subprocess.CalledProcessError:
print("Error while running DORiE")
sys.exit(1)
\ No newline at end of file
sys.exit(1)
if __name__ == "__main__": # parse command line and call command handler
try:
with warnings.catch_warnings(record=True) as warn:
parser = argparse.ArgumentParser(description="DORiE command line interface",
epilog="For more information check our online documentation: "
"http://dorie-docs.bitballoon.com (password: 'richards')."
)
subparsers = parser.add_subparsers(title="Commands",dest="command")
subparsers.required = True
parser_create = subparsers.add_parser('create',
description="Copy example configuration to current folder.",
help="Copy example configuration to current folder.")
parser_create.add_argument('-f','--force', help="Override existing files.", action="store_true")
parser_create.set_defaults(func=create)
parser_pfg = subparsers.add_parser('pfg', help="Start parameter field generator.",
description="Start parameter field generator.",
usage="%(prog)s <config> [-h] [-p [N]] [-m=MPI_FLAGS]")
parser_pfg.add_argument('config',
help="Configuration file for the parameter field generator. "
"Can be created with 'dorie create'.")
parser_pfg.add_argument('-p','--parallel', metavar='N', nargs='?', default=1,
const=multiprocessing.cpu_count(), type=int, required=False,
help="Run in parallel on N processes. "
"If N is not specified, run on all available CPU threads.")
parser_pfg.add_argument('-m','--mpi-flags', action="append", required=False,
help="Additional flags that are passed to mpirun when run in parallel. "
"May be specified multiple times.")
parser_pfg.set_defaults(func=pfg)
parser_run = subparsers.add_parser('run', help="Run DORiE.", description="Run DORiE.",
usage="%(prog)s <config> [-h] [-p [N]] [-m=MPI_FLAGS]")
parser_run.add_argument('config',help="DORiE configuration file. Can be created with 'dorie create'.")
parser_run.add_argument('-p','--parallel', metavar='N', nargs='?', default=1,
const=multiprocessing.cpu_count(), type=int, required=False,
help="Run in parallel on N processes. "
"If N is not specified, run on all available CPU threads.")
parser_run.add_argument('-m','--mpi-flags', action="append", required=False,
help="Additional flags that are passed to mpirun when run in parallel. "
"May be specified multiple times.")
parser_run.set_defaults(func=run)
parser_plot = subparsers.add_parser('plot', help="Plot a preview of a VTK file created by DORiE.",
description="Plot a preview of a VTK file created by DORiE.",
usage="%(prog)s <vtk> [-h] [--v [VAR [VAR ...]]]")
parser_plot.add_argument('vtk', help="Input VTK file.")
parser_plot.add_argument('-v','--var', nargs='*', required=False,
help="Plot only given variables. If not specified, all variables are plotted.")
parser_plot.set_defaults(func=plot)
try:
args = parser.parse_args()
except SystemExit:
sys.exit(1)
args.func(vars(args))
except Exception as e:
print("dorie failed with ({0}) warning(s) and ({1}) error(s)".format(len(warn),1))
raise
......@@ -3,7 +3,6 @@ set(DUNE_PYTHON_INSTALL_EDITABLE TRUE)
# install Python package
add_subdirectory(dorie/wrapper)
add_subdirectory(dorie/dorie/cli)
dune_python_install_package(PATH dorie)
# set cache variable
......
configure_file(cmds.py.in ${CMAKE_CURRENT_SOURCE_DIR}/cmds.py)
\ No newline at end of file
import os
import sys
import shutil
import subprocess
try: # Python 2.x compatibility
input = raw_input
except NameError:
pass
# paths set by cmake
DORIEDIR = "/Users/lriedel/dune/dorie/build-cmake"
MPIEXEC = "/usr/local/bin/mpiexec"
MPIEXEC_NUMPROC_FLAG = "-n"
MPIEXEC_PREFLAG = ""
MPIEXEC_POSTFLAGS = ""
# set some paths
DORIE_EXECUTABLE = os.path.join(DORIEDIR, "dune/dorie/dorie")
PARAMETERDIR = os.path.join(DORIEDIR, "doc/default_files")
def MPIRUN(nproc,exe,*args,**kwargs):
mpi_flags = kwargs.get("mpi_flags") or []
return [k for k in [MPIEXEC,MPIEXEC_NUMPROC_FLAG,str(nproc)] \
+ mpi_flags + [MPIEXEC_PREFLAG,str(exe),
MPIEXEC_POSTFLAGS] + list(args) if k]
def run(args):
if not os.path.isfile(args["config"]):
raise IOError("Configuration file {} not found".format(args["config"]))
try:
if args["parallel"] == 1:
subprocess.check_call([DORIE_EXECUTABLE, args["config"]])
else:
subprocess.check_call(MPIRUN(args["parallel"], DORIE_EXECUTABLE,
args["config"], mpi_flags=args["mpi_flags"]))
except subprocess.CalledProcessError:
print("Error while running DORiE")
sys.exit(1)
def create(args):
for f in ("config.ini", "parfield.ini", "2d_infiltr.bcdat", "3d_infiltr.bcdat"):
newfile = os.path.join(os.getcwd(),f)
if os.path.exists(newfile) and not args["force"]:
override = (input("File {} exists. Override? [Y/n] ".format(f)) or "Y") in ["Y","y"]
if not override:
continue
shutil.copyfile(os.path.join(PARAMETERDIR, f), newfile)
print("Folder initialized")
def pfg(args):
if not os.path.isfile(args["config"]):
raise IOError("Configuration file {} not found".format(args["config"]))
try:
if args["parallel"] == 1:
subprocess.check_call(["pf_from_file.py", args["config"]])
else:
if args["mpi_flags"]:
mpi_flags = ["--mpi-flags=" + f for f in args["mpi_flags"]]
else:
mpi_flags = []
subprocess.check_call(["pf_from_file.py", args["config"],
"--parallel", str(args["parallel"])] + mpi_flags)
except subprocess.CalledProcessError:
print("Error while running DORiE")
sys.exit(1)
def plot(args):
if not os.path.isfile(args["vtk"]):
raise IOError("File {} not found".format(args["vtk"]))
try:
if args["var"]:
subprocess.check_call(["plot_vtk.py", "-f", args["vtk"], "--var", args["var"]])
else:
subprocess.check_call(["plot_vtk.py", "-f", args["vtk"]])
except subprocess.CalledProcessError:
print("Error while running DORiE")
sys.exit(1)
import argparse
import multiprocessing
# import all commands
from .cmds import *
def create_cl_parser():
"""Create the command line parser for the DORiE CLI.
Returns:
ArgumentParser object for parsing the command line.
"""
parser = argparse.ArgumentParser(description="DORiE Command Line Interface",
epilog="For more information check our online documentation: "
"http://dorie-doc.netlify.com."
)
subparsers = parser.add_subparsers(title="Commands", dest="command")
subparsers.required = True
parser_create = subparsers.add_parser('create',
description="Copy example configuration to current folder.",
help="Copy example configuration to current folder.")
parser_create.add_argument('-f','--force',
action="store_true",
help="Override existing files.")
parser_create.set_defaults(func=create)
parser_pfg = subparsers.add_parser('pfg', help="Start parameter field generator.",
description="Start parameter field generator.")
parser_pfg.add_argument('config',
help="Configuration file for the parameter field generator. "
"A default version can be created with 'dorie create'.")
parser_pfg.add_argument('-p','--parallel',
metavar='N',
nargs='?',
default=1,
const=multiprocessing.cpu_count(),
type=int,
required=False,
help="Run in parallel on N processes. "
"If N is not specified, run on all available CPU threads.")
parser_pfg.add_argument('-m','--mpi-flags',
action="append",
required=False,
help="Additional flags that are passed to mpirun when run in parallel. "
"May be specified multiple times.")
parser_pfg.set_defaults(func=pfg)
parser_run = subparsers.add_parser('run', help="Run DORiE.", description="Run DORiE.")
parser_run.add_argument('config',
help="DORiE configuration file. "
"A default version can be created with 'dorie create'.")
parser_run.add_argument('-p','--parallel', metavar='N',
nargs='?',
default=1,
const=multiprocessing.cpu_count(),
type=int,
required=False,
help="Run in parallel on N processes. "
"If N is not specified, run on all available CPU threads.")
parser_run.add_argument('-m','--mpi-flags',
action="append",
required=False,
help="Additional flags that are passed to mpirun when run in parallel. "
"May be specified multiple times.")
parser_run.set_defaults(func=run)
parser_plot = subparsers.add_parser('plot', help="Plot a preview of a VTK file created by DORiE.",
description="Plot a preview of a VTK file created by DORiE.")
parser_plot.add_argument('vtk',
help="Input VTK file.")
parser_plot.add_argument('-v','--var',
nargs='*',
help="Plot only given variables. If not specified, all variables are plotted.")
parser_plot.set_defaults(func=plot)
return parser
\ No newline at end of file
......@@ -24,7 +24,6 @@ setup(name='dorie',
'wheel'
],
scripts=[
'wrapper/dorie',
'wrapper/pf_from_file.py',
'wrapper/plot_vtk.py',
'wrapper/scrape_folder.py',
......
configure_file(dorie.in ${CMAKE_CURRENT_SOURCE_DIR}/dorie)
configure_file(pf_from_file.py.in ${CMAKE_CURRENT_SOURCE_DIR}/pf_from_file.py)
configure_file(test_dorie.py.in ${CMAKE_CURRENT_SOURCE_DIR}/test_dorie.py)
\ No newline at end of file
#!/usr/bin/env python3
import sys
import warnings
from dorie.cli.parser import create_cl_parser
if __name__ == "__main__": # parse command line and call command handler
try:
with warnings.catch_warnings(record=True) as warn:
try:
parser = create_cl_parser()
args = parser.parse_args()
except SystemExit:
sys.exit(1)
args.func(vars(args))
except Exception as e:
print("dorie failed with ({0}) warning(s) and ({1}) error(s)".format(len(warn),1))
raise
......@@ -9,10 +9,14 @@ from dune.testtools.wrapper.argumentparser import get_args
from dune.testtools.parser import parse_ini_file
from dorie.testtools.wrapper import test_dorie
DORIE_WRAPPER = "dorie"
# paths set by cmake
DORIEDIR = "@CMAKE_BINARY_DIR@"
#
DORIE_WRAPPER = os.path.join(DORIEDIR, "bin/dorie")
if __name__ == "__main__":
args = get_args()
iniargument = args["ini"]
iniinfo = parse_ini_file(args["ini"])
sys.exit(test_dorie.test_dorie(iniinfo, iniargument, DORIE_WRAPPER))
sys.exit(test_dorie.test_dorie(iniinfo,iniargument,DORIE_WRAPPER))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment