Commit 6b521f47 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

added clean cmake cache and small git features

parent ee268a9c
from subprocess import Popen, PIPE
import requests
import os
import re
import shutil
import socket
import re
import os
from subprocess import Popen, PIPE
class Mpp:
......@@ -22,34 +21,45 @@ class Mpp:
PROJECT_PY_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'py'))
def __init__(self):
self.silent = False
self.mute = False
self.executable = 'M++'
self.git_mpp_address = 'https://git.scc.kit.edu/yq8188/mpp.git'
self.git_project_address = None
@staticmethod
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],
def check_git_project(self):
return self.run_subprocess(['git', 'ls-remote', self.git_project_address],
self.PROJECT_ROOT_DIR)
def check_git_mpp(self):
return self.run_subprocess(['git', 'ls-remote', self.git_mpp_address],
self.MPP_DIR)
def git_pull_project(self, branch='master'):
rc_project = self.run_subprocess(['git', 'pull', 'origin', branch],
self.PROJECT_ROOT_DIR)
rc_mpp = self.git_pull_mpp()
rc_sub = self.run_subprocess(['git', 'submodule', 'update'],
self.PROJECT_ROOT_DIR)
if rc_project == 0 and rc_mpp == 0 and rc_sub == 0:
return 0
else:
return 1
def git_pull_mpp(self, branch='master'):
return self.run_subprocess(['git', 'pull', 'origin', branch],
self.MPP_DIR)
def run_subprocess(self, args, cwd):
if isinstance(args, list):
process = Popen(args, cwd=cwd, stdout=PIPE, stderr=PIPE)
if not self.silent:
if not self.mute:
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()
......@@ -60,30 +70,30 @@ class Mpp:
os.mkdir(self.PROJECT_BUILD_DIR)
def setup_cluster(self):
if not self.silent:
if not self.mute:
print('\n================ setup cluster ================\n')
if socket.gethostname().find('ma-pde') != -1:
return self.run_subprocess(['module', 'add', 'foss'],
cwd=self.PROJECT_ROOT_DIR)
def run_cmake(self):
if not self.silent:
if not self.mute:
print('\n================ running cmake ================\n')
return self.run_subprocess(['cmake', '..'], cwd=self.PROJECT_BUILD_DIR)
def run_make(self):
if not self.silent:
if not self.mute:
print('\n================ running make ================\n')
return self.run_subprocess(['make', '-j'], cwd=self.PROJECT_BUILD_DIR)
def kill(self):
if not self.silent:
if not self.mute:
print('\n================ kill every mpp ================\n')
return self.run_subprocess(['killall', self.executable],
cwd=self.PROJECT_BUILD_DIR)
def run_tests(self):
if not self.silent:
if not self.mute:
print('\n================ running tests ================\n')
files = os.listdir(self.PROJECT_BUILD_DIR)
for file in files:
......@@ -113,6 +123,14 @@ class Mpp:
else:
return 1
@staticmethod
def remove_file(file):
if os.path.isfile(file):
try:
os.unlink(file)
except Exception as e:
print(e)
@staticmethod
def clean_directory(directory, recursive):
for file in os.listdir(directory):
......@@ -143,6 +161,10 @@ class Mpp:
if os.path.isdir(self.PROJECT_BUILD_DIR):
self.clean_directory(self.PROJECT_BUILD_DIR, True)
def clean_cmake_cache(self):
cmake_cache = self.PROJECT_BUILD_DIR + 'CMakeCache.txt'
self.remove_file(cmake_cache)
def run(self, kernels, config=None, kwargs=None):
run_parameters = self.chain_run_parameters(kernels, config, kwargs)
return self.run_subprocess(run_parameters, cwd=self.PROJECT_BUILD_DIR)
......
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