From d837db015d9d83740e612763b55c45f166e56141 Mon Sep 17 00:00:00 2001
From: Sebastian Eibl <sebastian.eibl@fau.de>
Date: Thu, 18 Jun 2020 09:18:21 +0200
Subject: [PATCH] enable mesa_pd codegen for ci

---
 .gitlab-ci.yml           |  4 +++-
 python/mesa_pd.py        |  3 ++-
 python/mesa_pd/Module.py | 23 +++++++++++------------
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0387e0998..09e4f7731 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
@@ -2073,4 +2075,4 @@ benchmark_ClangBuildAnalyzer:
     - ClangBuildAnalyzer --analyze CBA
   image: i10git.cs.fau.de:5005/walberla/buildenvs/clang:9.0
   tags:
-    - docker-benchmark
\ No newline at end of file
+    - docker-benchmark
diff --git a/python/mesa_pd.py b/python/mesa_pd.py
index 785d9a4ff..70ad9cf08 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)
@@ -120,4 +121,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 eec965f3e..64c307c46 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()
-- 
GitLab