From 00d063fac46b280b737dd7fbef58aa54d8281ec2 Mon Sep 17 00:00:00 2001
From: Pietro Incardona <incardon@mpi-cbg.de>
Date: Thu, 17 Sep 2015 01:28:41 +0200
Subject: [PATCH] Fixing install script

---
 script/py/pack_examples.py    | 93 +++++++++++++++++++++++++++++++++++
 script/py/process_examples.py | 20 ++++++++
 src/Makefile.am               |  2 +-
 3 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 script/py/pack_examples.py
 create mode 100644 script/py/process_examples.py

diff --git a/script/py/pack_examples.py b/script/py/pack_examples.py
new file mode 100644
index 00000000..d482a055
--- /dev/null
+++ b/script/py/pack_examples.py
@@ -0,0 +1,93 @@
+__author__ = 'i-bird'
+
+import os
+import shutil, errno
+import configparser
+from os import listdir
+from os.path import isdir, join
+
+class pack_example:
+    temporary=os.sep + "tmp" + os.sep + "pack_example"
+    base_dir=""
+
+    # Get the files to copy
+    def get_files(self,dir):
+        config = configparser.ConfigParser()
+        config.read(dir+os.sep+"config.cfg")
+        files = []
+        if "pack" in config:
+            if "files" in config["pack"]:
+                files = config["pack"]["files"]
+                files = str.split(files)
+                # for each filr add the prefix
+                for i in range(0,len(files)):
+                    files[i] = dir+os.sep+files[i]
+        return files
+
+    # If the directory is an example
+    def is_example(self,dir):
+        return os.path.isfile(dir+os.sep+"config.cfg")
+
+    # Get the files to pack
+    def copy_example(self,dir):
+        print("Processing: " + dir)
+        files=self.get_files(dir)
+
+        try:
+            # Create the temporary folder
+            os.makedirs(self.temporary)
+        except FileExistsError:
+            pass
+
+        # make the example directory
+
+        if len(files) != 0:
+            head, tail = os.path.split(files[0])
+            try:
+                os.makedirs(self.temporary+os.sep+head[len(self.base_dir):])
+            except FileExistsError:
+                pass
+
+        for file in files:
+            print("copy src:"+file+"    dst:"+self.temporary+os.sep+file[len(self.base_dir):])
+            shutil.copy(file,self.temporary+os.sep+file[len(self.base_dir):])
+
+
+    # Add examples in a recursive way
+    def add_r(self, dir):
+        if self.is_example(dir):
+            self.copy_example(dir)
+
+        # copy Makefile
+        print("copy src:"+dir+os.sep+"Makefile"+"    dst:"+self.temporary+os.sep+"Makefile")
+        shutil.copy(dir+os.sep+"Makefile",self.temporary+os.sep+"Makefile")
+
+        # List all the folder in the directory
+        onlydir = [ f for f in listdir(dir) if isdir(join(dir,f)) ]
+        for example_dir in onlydir:
+            self.add_r(dir+os.sep+example_dir)
+
+    # Add an example path
+    def pack(self, dir, file):
+
+        # Remove temporary folders and recreate it
+        if os.path.exists(self.temporary):
+            shutil.rmtree(self.temporary)
+        os.makedirs(self.temporary)
+
+        if self.is_example(dir):
+            self.copy_example(dir)
+
+        self.base_dir = dir
+
+        # copy Makefile
+        print("copy src:"+dir+os.sep+"Makefile"+"    dst:"+self.temporary+os.sep+"Makefile")
+        shutil.copy(dir+os.sep+"Makefile",self.temporary+os.sep+"Makefile")
+
+        # List all the folder in the directory
+        onlydir = [ f for f in listdir(dir) if isdir(join(dir,f)) ]
+        for example_dir in onlydir:
+            self.add_r(dir+os.sep+example_dir)
+
+        # make an archive
+        shutil.make_archive(file,"bztar",self.base_dir)
diff --git a/script/py/process_examples.py b/script/py/process_examples.py
new file mode 100644
index 00000000..a77878e5
--- /dev/null
+++ b/script/py/process_examples.py
@@ -0,0 +1,20 @@
+# python script that process the examples in particular it pack the examples, it generates the vtk files,
+# the images out of the vtk files, the mardown wiki pages
+
+import argparse
+import os
+from os import listdir
+from os.path import isdir, join
+from pack_examples import pack_example
+
+parser = argparse.ArgumentParser(description='Pack the examples, generate the vtk files to generate images, create the markdown pages for the wiki')
+parser.add_argument('directory', help='directory where are located the examples')
+args = parser.parse_args()
+
+# List all the folder in the directory
+
+onlydir = [ f for f in listdir(args.directory) if isdir(join(args.directory,f)) ]
+
+p = pack_example()
+p.pack(args.directory,args.directory+os.sep+"examples")
+
diff --git a/src/Makefile.am b/src/Makefile.am
index e6d11499..ca6f045b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,7 +11,7 @@ nobase_include_HEADERS = Decomposition/CartDecomposition.hpp Decomposition/commo
          Grid/grid_dist_id.hpp Grid/grid_dist_id_iterator.hpp Grid/grid_dist_key.hpp \
          Vector/vector_dist.hpp Vector/vector_dist_iterator.hpp Vector/vector_dist_key.hpp \
          config/config.h \
-         SubdomainGraphNodes.hpp
+         metis_util.hpp dec_optimizer.hpp SubdomainGraphNodes.hpp
 
 .cu.o :
 	$(NVCC) $(NVCCFLAGS) -o $@ -c $<
-- 
GitLab