1 from shutil
import move
7 DFNPARAMS =
'~/.dfnworksrc'
8 DFNPARAMS = os.path.expanduser(DFNPARAMS)
11 def valid(name, path, path_type):
12 """" Check that path is valid for a executable
16 Path to file or executable
18 Path type can either be an executable or a directory
26 If file is not found, file is not an executable, or directory does not exists then program exits
28 if path_type ==
"executable":
29 if not os.path.isfile(path):
30 error = f
"Error checking {name}\n{path} is not a valid path to a file name.\nPlease check the path in either pydfnworks/general/paths.py or .dfnworksrc.\nExiting\n"
31 sys.stderr.write(error)
34 if not os.access(path, os.X_OK):
35 error = f
"Error checking {name}\n{path} is not an executable.\nPlease check file permissions.\nExiting\n"
36 sys.stderr.write(error)
39 if path_type ==
"directory":
40 if not os.path.isdir(path):
41 error = f
"Error checking {name}\n{path} is not a directory.\nPlease check the path in either pydfnworks/general/paths.py or .dfnworksrc.\nExiting\n"
42 sys.stderr.write(error)
49 """Compile executables used in the DFN workflow including: DFNGen, DFNTrans, correct_uge, correct_stor, mesh_checking. The executables LaGriT, PFLOTRAN, and FEHM are not compiled in this function
53 Path to dfnWorks executable
60 This function is only called if an executable is not found.
63 print(f
"Compiling {path}")
66 subprocess.call(
"make", shell=
True)
72 """Defines environmental variables for use in dfnWorks. The user must change these to match their workspace.
81 Environmental variables are set to executables
89 if os.path.isfile(DFNPARAMS):
90 with open(DFNPARAMS,
'r')
as f:
91 env_paths = json.load(f)
105 os.environ[
'dfnworks_PATH'] = env_paths[
'dfnworks_PATH']
106 valid(
"dfnworks_PATH", os.environ[
'dfnworks_PATH'],
"directory")
109 os.environ[
'PETSC_DIR'] = env_paths[
'PETSC_DIR']
110 os.environ[
'PETSC_ARCH'] = env_paths[
'PETSC_ARCH']
111 valid(
'PETSC_DIR', os.environ[
'PETSC_DIR'],
"directory")
113 os.environ[
'PETSC_DIR'] + os.sep + os.environ[
'PETSC_ARCH'],
117 os.environ[
'PFLOTRAN_EXE'] = env_paths[
'PFLOTRAN_EXE']
118 valid(
'PFLOTRAN_EXE', os.environ[
'PFLOTRAN_EXE'],
"executable")
121 os.environ[
'PYTHON_EXE'] = env_paths[
'PYTHON_EXE']
122 valid(
'PYTHON_EXE', os.environ[
'PYTHON_EXE'],
"executable")
125 os.environ[
'LAGRIT_EXE'] = env_paths[
'LAGRIT_EXE']
126 valid(
'LAGRIT_EXE', os.environ[
'LAGRIT_EXE'],
"executable")
128 os.environ[
'FEHM_EXE'] = env_paths[
'FEHM_EXE']
129 valid(
'FEHM_EXE', os.environ[
'FEHM_EXE'],
"executable")
136 os.environ[
'DFNGEN_EXE'] = os.environ[
'dfnworks_PATH'] +
'DFNGen/DFNGen'
137 if not os.path.isfile(os.environ[
'DFNGEN_EXE']):
139 valid(
'DFNGen',os.environ[
'DFNGEN_EXE'],
"executable")
143 'DFNTRANS_EXE'] = os.environ[
'dfnworks_PATH'] +
'DFNTrans/DFNTrans'
144 if not os.path.isfile(os.environ[
'DFNTRANS_EXE']):
146 valid(
'DFNTrans',os.environ[
'DFNTRANS_EXE'],
"executable")
148 os.environ[
'CORRECT_UGE_EXE'] = os.environ[
149 'dfnworks_PATH'] +
'C_uge_correct/correct_uge'
150 if not os.path.isfile(os.environ[
'CORRECT_UGE_EXE']):
152 valid(
'CORRECT_UGE_EXE',os.environ[
'CORRECT_UGE_EXE'],
"executable")
155 os.environ[
'CORRECT_STOR_EXE'] = os.environ[
156 'dfnworks_PATH'] +
'C_stor_correct/correct_stor'
157 if not os.path.isfile(os.environ[
'CORRECT_STOR_EXE']):
159 valid(
'CORRECT_STOR_EXE',os.environ[
'CORRECT_STOR_EXE'],
"executable")
161 os.environ[
'CONNECT_TEST_EXE'] = os.environ[
162 'dfnworks_PATH'] +
'DFN_Mesh_Connectivity_Test/ConnectivityTest'
163 if not os.path.isfile(os.environ[
'CONNECT_TEST_EXE']):
165 'DFN_Mesh_Connectivity_Test/')
166 valid(
'CONNECT_TEST_EXE',os.environ[
'CONNECT_TEST_EXE'],
"executable")
def valid(name, path, path_type)
def compile_dfn_exe(path)