Commit 70dd3df1 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

worked on python structure

parent b17598d5
from mpp.python.project_dirs import *
from subprocess import Popen, PIPE
import requests
import shutil
import socket
import re
import os
class Mpp:
PY_FILE_DIR = os.path.dirname(os.path.realpath(__file__))
MPP_DIR = os.path.abspath(os.path.join(PY_FILE_DIR, '..'))
MPP_BUILD_DIR = os.path.abspath(os.path.join(MPP_DIR, 'build'))
MPP_LOG_DIR = os.path.abspath(os.path.join(MPP_BUILD_DIR, 'log'))
MPP_DATA_DIR = os.path.abspath(os.path.join(MPP_BUILD_DIR, 'data'))
MPP_VTK_DATA_DIR = os.path.abspath(os.path.join(MPP_DATA_DIR, 'vtk'))
MPP_PY_DATA_DIR = os.path.abspath(os.path.join(MPP_DATA_DIR, 'py'))
PROJECT_ROOT_DIR = os.path.abspath(os.path.join(MPP_DIR, '..'))
PROJECT_BUILD_DIR = os.path.abspath(os.path.join(PROJECT_ROOT_DIR, 'build'))
PROJECT_LOG_DIR = os.path.abspath(os.path.join(PROJECT_BUILD_DIR, 'log'))
PROJECT_DATA_DIR = os.path.abspath(os.path.join(PROJECT_BUILD_DIR, 'data'))
PROJECT_VTK_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'vtk'))
PROJECT_PY_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'py'))
def __init__(self):
self.silent = False
self.executable = 'M++'
......@@ -23,7 +37,8 @@ class Mpp:
return 0
def git_pull(self, branch='master'):
return self.run_subprocess(['git', 'pull', 'origin', branch], PROJECT_ROOT_DIR)
return self.run_subprocess(['git', 'pull', 'origin', branch],
self.PROJECT_ROOT_DIR)
def run_subprocess(self, args, cwd):
if isinstance(args, list):
......@@ -40,40 +55,41 @@ class Mpp:
process.stderr.close()
return process.poll()
@staticmethod
def create_working_dir():
if not os.path.isdir(PROJECT_BUILD_DIR):
os.mkdir(PROJECT_BUILD_DIR)
def create_working_dir(self):
if not os.path.isdir(self.PROJECT_BUILD_DIR):
os.mkdir(self.PROJECT_BUILD_DIR)
def setup_cluster(self):
if not self.silent:
print('\n================ setup cluster ================\n')
if socket.gethostname().find('ma-pde') != -1:
return self.run_subprocess(['module', 'add', 'foss'], cwd=PROJECT_ROOT_DIR)
return self.run_subprocess(['module', 'add', 'foss'],
cwd=self.PROJECT_ROOT_DIR)
def run_cmake(self):
if not self.silent:
print('\n================ running cmake ================\n')
return self.run_subprocess(['cmake', '..'], cwd=PROJECT_BUILD_DIR)
return self.run_subprocess(['cmake', '..'], cwd=self.PROJECT_BUILD_DIR)
def run_make(self):
if not self.silent:
print('\n================ running make ================\n')
return self.run_subprocess(['make', '-j'], cwd=PROJECT_BUILD_DIR)
return self.run_subprocess(['make', '-j'], cwd=self.PROJECT_BUILD_DIR)
def kill(self):
if not self.silent:
print('\n================ kill every mpp ================\n')
return self.run_subprocess(['killall', self.executable], cwd=PROJECT_BUILD_DIR)
return self.run_subprocess(['killall', self.executable],
cwd=self.PROJECT_BUILD_DIR)
def run_tests(self):
if not self.silent:
print('\n================ running tests ================\n')
files = os.listdir(PROJECT_BUILD_DIR)
files = os.listdir(self.PROJECT_BUILD_DIR)
for file in files:
if file.find("Test") != -1:
run_parameters = self.chain_run_parameters(1, None, executable=file)
return self.run_subprocess(run_parameters, cwd=PROJECT_BUILD_DIR)
run_parameters = self.chain_run_parameters(1, None, None, executable=file)
return self.run_subprocess(run_parameters, cwd=self.PROJECT_BUILD_DIR)
def chain_run_parameters(self, kernels, config, kwargs, executable=None):
executable = self.executable if executable is None else executable
......@@ -110,13 +126,13 @@ class Mpp:
print(e)
def clean_vtk(self):
self.clean_directory(PROJECT_VTK_DATA_DIR, True)
self.clean_directory(self.PROJECT_VTK_DATA_DIR, True)
def clean_log(self):
self.clean_directory(PROJECT_LOG_DIR, False)
self.clean_directory(self.PROJECT_LOG_DIR, False)
def clean_python_plots(self):
self.clean_directory(PROJECT_PY_DATA_DIR, False)
self.clean_directory(self.PROJECT_PY_DATA_DIR, False)
def clean_data(self):
self.clean_vtk()
......@@ -124,17 +140,16 @@ class Mpp:
self.clean_python_plots()
def clean_build(self):
if os.path.isdir(PROJECT_BUILD_DIR):
self.clean_directory(PROJECT_BUILD_DIR, True)
if os.path.isdir(self.PROJECT_BUILD_DIR):
self.clean_directory(self.PROJECT_BUILD_DIR, True)
def run(self, kernels, config=None, kwargs=None):
run_parameters = self.chain_run_parameters(kernels, config, kwargs)
return self.run_subprocess(run_parameters, cwd=PROJECT_BUILD_DIR)
return self.run_subprocess(run_parameters, cwd=self.PROJECT_BUILD_DIR)
@staticmethod
def read_log(log_file=None):
log_file = PROJECT_LOG_DIR + '/log' if log_file is None else \
PROJECT_LOG_DIR + log_file
def read_log(self, log_file=None):
log_file = self.PROJECT_LOG_DIR + '/log' if log_file is None else \
self.PROJECT_LOG_DIR + log_file
if os.path.isfile(log_file):
with open(log_file) as file:
content = file.readlines()
......@@ -151,14 +166,4 @@ class Mpp:
mpp = Mpp()
if __name__ == "__main__":
# mpp.run_subprocess(['asdasfaf'], PROJECT_ROOT_DIR)
# mpp.setup_cluster()
# mpp.create_working_dir()
# mpp.run_cmake()
# mpp.run_make()
# mpp.clean_build()
# mpp.setup_cluster()
# mpp.kill()
# mpp.build()
# mpp.run_tests()
mpp.check_git()
import os
PY_FILE_DIR = os.path.dirname(os.path.realpath(__file__))
MPP_DIR = os.path.abspath(os.path.join(PY_FILE_DIR, '..'))
MPP_BUILD_DIR = os.path.abspath(os.path.join(MPP_DIR, 'build'))
MPP_LOG_DIR = os.path.abspath(os.path.join(MPP_BUILD_DIR, 'log'))
MPP_DATA_DIR = os.path.abspath(os.path.join(MPP_BUILD_DIR, 'data'))
MPP_VTK_DATA_DIR = os.path.abspath(os.path.join(MPP_DATA_DIR, 'vtk'))
MPP_PY_DATA_DIR = os.path.abspath(os.path.join(MPP_DATA_DIR, 'py'))
PROJECT_ROOT_DIR = os.path.abspath(os.path.join(MPP_DIR, '..'))
PROJECT_BUILD_DIR = os.path.abspath(os.path.join(PROJECT_ROOT_DIR, 'build'))
PROJECT_LOG_DIR = os.path.abspath(os.path.join(PROJECT_BUILD_DIR, 'log'))
PROJECT_DATA_DIR = os.path.abspath(os.path.join(PROJECT_BUILD_DIR, 'data'))
PROJECT_VTK_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'vtk'))
PROJECT_PY_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'py'))
\ No newline at end of file
Supports Markdown
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