Commit 1d0e055f authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

moved paths to other file and added silent instance variable

parent fa562487
from mpp.python.project_dirs import *
from subprocess import Popen, PIPE
import requests
import shutil
import socket
import sys
import os
import re
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'))
class Mpp:
def __init__(self):
self.silent = False
self.executable = 'M++'
@staticmethod
def run_subprocess(args, cwd):
def check_git():
# git ls-remote https://github.com/git/git
# https://www.youtube.com/watch?v=tb8gHvYlCFs
response = requests.get(f'https://git.scc.kit.edu/yq8188/mpp.git')
# if response.ok:
# print(response.text)
# else:
# pass
return 0
def git_pull(self, branch='master'):
return self.run_subprocess(['git', 'pull', 'origin', branch], PROJECT_ROOT_DIR)
def run_subprocess(self, args, cwd):
if isinstance(args, list):
process = Popen(args, cwd=cwd, stdout=PIPE, stderr=PIPE)
while True:
stdout = process.stdout.readline()
if stdout == b'' and process.poll() is not None:
break
if stdout:
print(stdout.decode('utf-8').strip('\n'))
if not self.silent:
while True:
stdout = process.stdout.readline()
if stdout == b'' and process.poll() is not None:
break
if stdout:
print(stdout.decode('utf-8').strip('\n'))
process.wait()
process.stdout.close()
process.stderr.close()
return process.poll()
@staticmethod
......@@ -42,29 +46,34 @@ class Mpp:
os.mkdir(PROJECT_BUILD_DIR)
def setup_cluster(self):
print('\n================ setup cluster ================\n')
if not self.silent:
print('\n================ setup cluster ================\n')
if socket.gethostname().find('ma-pde') != -1:
rc = self.run_subprocess(['module', 'add', 'foss'], cwd=PROJECT_ROOT_DIR)
return self.run_subprocess(['module', 'add', 'foss'], cwd=PROJECT_ROOT_DIR)
def run_cmake(self):
print('\n================ running cmake ================\n')
rc = self.run_subprocess(['cmake', '..'], cwd=PROJECT_BUILD_DIR)
if not self.silent:
print('\n================ running cmake ================\n')
return self.run_subprocess(['cmake', '..'], cwd=PROJECT_BUILD_DIR)
def run_make(self):
print('\n================ running make ================\n')
self.run_subprocess(['make', '-j'], cwd=PROJECT_BUILD_DIR)
if not self.silent:
print('\n================ running make ================\n')
return self.run_subprocess(['make', '-j'], cwd=PROJECT_BUILD_DIR)
def kill(self):
print('\n================ kill every mpp ================\n')
self.run_subprocess(['killall', self.executable], cwd=PROJECT_BUILD_DIR)
if not self.silent:
print('\n================ kill every mpp ================\n')
return self.run_subprocess(['killall', self.executable], cwd=PROJECT_BUILD_DIR)
def run_tests(self):
print('\n================ running tests ================\n')
if not self.silent:
print('\n================ running tests ================\n')
files = os.listdir(PROJECT_BUILD_DIR)
for file in files:
if file.find("Test") != -1:
run_parameters = self.chain_run_parameters(1, None, executable=file)
self.run_subprocess(run_parameters, cwd=PROJECT_BUILD_DIR)
return self.run_subprocess(run_parameters, cwd=PROJECT_BUILD_DIR)
def chain_run_parameters(self, kernels, args, executable=None):
executable = self.executable if executable is None else executable
......@@ -77,8 +86,12 @@ class Mpp:
def build(self):
self.create_working_dir()
self.run_cmake()
self.run_make()
rc_cmake = self.run_cmake()
rc_make = self.run_make()
if rc_cmake == 0 and rc_make == 0:
return 0
else:
return 1
@staticmethod
def clean_directory(directory, recursive):
......@@ -112,7 +125,7 @@ class Mpp:
def run(self, kernels, args=None):
run_parameters = self.chain_run_parameters(kernels, args)
self.run_subprocess(run_parameters, cwd=PROJECT_BUILD_DIR)
return self.run_subprocess(run_parameters, cwd=PROJECT_BUILD_DIR)
@staticmethod
def read_log(log_file=None):
......@@ -133,12 +146,14 @@ 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.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