diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fb1161945928e1e1b396e7678624bdac3b626cb4..df5a69bd8fe55bca7300560cb6e960951010ffd2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,6 +25,8 @@ stages: - cmake --version - ccache --version - mpirun --version + - python3 --version + - python3 python/mesa_pd.py -y .. - export CCACHE_BASEDIR=$CI_PROJECT_DIR - mkdir $CI_PROJECT_DIR/build - cd $CI_PROJECT_DIR/build diff --git a/python/mesa_pd.py b/python/mesa_pd.py index a6d7fa151dbde6177ae28c2324fff3e2d6ae93ef..bb3cb83c6279ccbd2e356747199045996afcebf6 100755 --- a/python/mesa_pd.py +++ b/python/mesa_pd.py @@ -11,6 +11,7 @@ import argparse if __name__ == '__main__': parser = argparse.ArgumentParser(description='Generate all necessary files for the waLBerla mesa_pd module.') parser.add_argument('path', help='Where should the files be created?') + parser.add_argument('-y', action='store_true', help='Silent mode. Accept all questions with yes.') args = parser.parse_args() mpd = Module(args.path) @@ -122,4 +123,4 @@ if __name__ == '__main__': mpd.add(mpi.SyncNextNeighbors(ps)) mpd.add(mpi.SyncNextNeighborsNoGhosts(ps)) - mpd.generate() + mpd.generate(not args.y) diff --git a/python/mesa_pd/Module.py b/python/mesa_pd/Module.py index eec965f3ec53835682bb2037f245ea59c29e9465..64c307c4674d04524377e1f05df4fb5024626a11 100644 --- a/python/mesa_pd/Module.py +++ b/python/mesa_pd/Module.py @@ -30,21 +30,20 @@ class Module: return component def rename(self): - for root, dirnames, filenames in os.walk(self.context['module_path']): - for filename in filenames: - filedata = None - # print(f'renaming module name: {root}/{filename}') - with open(f'{root}/{filename}', 'r') as file: - filedata = file.read() + for filename in (f for f in self.context['module_path'].glob('**/*') if f.is_file()): + filedata = None + #print(f'renaming module name: {filename}') + with open(filename, encoding="utf-8") as fin: + filedata = fin.read() - filedata = filedata.replace('mesa_pd', self.context['name']) + filedata = filedata.replace('mesa_pd', self.context['name']) - with open(f'{root}/{filename}', 'w') as file: - file.write(filedata) + with open(filename, 'w', encoding="utf-8") as fout: + fout.write(filedata) def generate(self, folder_check=True): + print(f"This operation will overwrite the content of: {self.context['module_path']}") if (folder_check): - print(f"This operation will overwrite the content of: {self.context['module_path']}") answer = input("Continue? (y to confirm)") if (answer != "y"): return @@ -52,11 +51,11 @@ class Module: mesa_pd_folder = (Path(__file__).parents[2] / 'src' / 'mesa_pd').resolve() if (mesa_pd_folder != self.context['module_path']): if not self.context['module_path'].exists(): - self.context['module_path'].mkdir() + self.context['module_path'].mkdir(parents=True) shutil.rmtree(self.context['module_path']) shutil.copytree(mesa_pd_folder, self.context['module_path']) for d in self.components: d.generate(self.context) - self.rename() \ No newline at end of file + self.rename()