From 6a5788a53e05912b9e3d7f17256267b4731726ea Mon Sep 17 00:00:00 2001
From: imcovangent <I.vanGent@tudelft.nl>
Date: Fri, 6 Apr 2018 13:22:56 +0200
Subject: [PATCH] Updated VISTOMS integration in KADMOS. Includes interactive
 VISTOMS now. Updated MANIFEST.in to include new VISTOMS file structure.

Former-commit-id: 7e0328195ad2b3528ddb85447ad4e2390ec4ef7b
---
 MANIFEST.in                   |  7 +++---
 kadmos/graph/mixin_vistoms.py | 38 +++++++++++++++-------------
 kadmos/vistoms/__init__.py    | 47 ++++++++++++++++-------------------
 3 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index 27cdbc2a9..74deebee0 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -10,10 +10,9 @@ graft kadmos/interface/templates
 graft kadmos/utilities/cmdows
 graft kadmos/cmdows/schemas
 
-# Include current vispack templates
-graft kadmos/vispack/VISTOMS_170817
-graft kadmos/vispack/VISTOMS_dev
-graft kadmos/vispack/VISTOMS_TreeViewer
+# Include vistoms templates and static files
+graft kadmos/vistoms/static
+graft kadmos/vispack/templates
 
 # Include XDSM templates
 include kadmos/external/XDSM_writer/*.tex
diff --git a/kadmos/graph/mixin_vistoms.py b/kadmos/graph/mixin_vistoms.py
index 0b75e9851..da22ef102 100644
--- a/kadmos/graph/mixin_vistoms.py
+++ b/kadmos/graph/mixin_vistoms.py
@@ -5,7 +5,6 @@ import re
 import shutil
 import linecache
 import logging
-# noinspection PyPackageRequirements
 import tempfile
 
 import progressbar
@@ -24,16 +23,21 @@ logger = logging.getLogger(__name__)
 
 THEDATA_PREFIX = '			theData = '
 VISTOMS_NAME = 'VISTOMS.html'
-VISTOMS_TV_NAME = 'VISTOMS_TreeViewer.html'
-LOCAL_FILE_REFS = dict(REP__Acknowledgements__REP="file:include/Acknowledgements.svg",
-                       REP__AGILE_Icon__REP="include/AGILE_Icon.png",
-                       REP__AGILE_Logo__REP="file:include/AGILE_Logo.png",
-                       REP__Contact__REP="file:include/Contact.svg",
-                       REP__Home__REP="file:include/Home.svg",
-                       REP__RWTH_Logo__REP="file:include/RWTH_Logo.svg",
-                       REP__TUDelft_Logo__REP="file:include/TUDelft_Logo.svg",
-                       REP__Tutorial__REP="file:include/Tutorial.svg",
-                       REP__VISTOMS_Label__REP="file:include/VISTOMS_Label.svg")
+VISTOMS_TV_NAME = 'VISTOMS_XMLviewer.html'
+
+VISTOMS_NAME_TEMP = 'VISTOMS_Static.html'
+VISTOMS_TV_NAME_TEMP = 'VISTOMS_TreeViewer.html'
+
+LOCAL_PATH_PICTURES = os.path.join("file:static", "pictures")
+LOCAL_FILE_REFS = dict(REP__Acknowledgements__REP=os.path.join(LOCAL_PATH_PICTURES, "Acknowledgements.svg"),
+                       REP__AGILE_Icon__REP=os.path.join(LOCAL_PATH_PICTURES, "AGILE_Icon.png"),
+                       REP__AGILE_Logo__REP=os.path.join(LOCAL_PATH_PICTURES, "AGILE_Logo.png"),
+                       REP__Contact__REP=os.path.join(LOCAL_PATH_PICTURES, "Contact.svg"),
+                       REP__Home__REP=os.path.join(LOCAL_PATH_PICTURES, "Home.svg"),
+                       REP__RWTH_Logo__REP=os.path.join(LOCAL_PATH_PICTURES, "RWTH_Logo.svg"),
+                       REP__TUDelft_Logo__REP=os.path.join(LOCAL_PATH_PICTURES, "TUDelft_Logo.svg"),
+                       REP__Tutorial__REP=os.path.join(LOCAL_PATH_PICTURES, "Tutorial.svg"),
+                       REP__VISTOMS_Label__REP=os.path.join(LOCAL_PATH_PICTURES, "VISTOMS_Label.svg"))
 
 class VistomsMixin(object):
 
@@ -79,7 +83,7 @@ class VistomsMixin(object):
         vistoms_dir = os.path.abspath(vistoms_dir)
 
         # Initiate VISTOMS instance
-        vistoms.copy(temp_dir, vispack_version=vistoms_version)
+        vistoms.copy(temp_dir, vistoms_version='Static')
 
         # Create dictionary for the data.json file
         data = dict(graphs=[], categories=[])
@@ -121,13 +125,13 @@ class VistomsMixin(object):
         # Perform the text replacement
         rep = dict((re.escape(k), v) for k, v in rep.iteritems())
         pattern = re.compile("|".join(rep.keys()))
-        with open(os.path.join(temp_dir, 'VISTOMS_datarepl.html'), "rt") as fin:
+        with open(os.path.join(temp_dir, VISTOMS_NAME_TEMP), "rt") as fin:
             with open(os.path.join(temp_dir, VISTOMS_NAME), "wt") as fout:
                 for line in fin:
                     fout.write(pattern.sub(lambda m: rep[re.escape(m.group(0))], line))
 
         # Remove the original VISTOMS file
-        os.remove(os.path.join(temp_dir, 'VISTOMS_datarepl.html'))
+        os.remove(os.path.join(temp_dir, VISTOMS_NAME_TEMP))
 
         # Copy temp directory to file path
         # Remove previous VISTOMS directory (if present)
@@ -1044,7 +1048,7 @@ def get_vistoms_tree_viewer(xml_file, vistoms_dir, use_png_figs=False, file_refs
     vistoms_dir = os.path.abspath(vistoms_dir)
 
     # Initiate VISTOMS instance
-    vistoms.copy(temp_dir, vispack_version="TreeViewer")
+    vistoms.copy(temp_dir, vistoms_version="TreeViewer")
 
     # Settings
     dummy_tool_name = '__dummy__'
@@ -1095,13 +1099,13 @@ def get_vistoms_tree_viewer(xml_file, vistoms_dir, use_png_figs=False, file_refs
     # Perform the text replacement
     rep = dict((re.escape(k), v) for k, v in rep.iteritems())
     pattern = re.compile("|".join(rep.keys()))
-    with open(os.path.join(temp_dir, "VISTOMS_TreeViewer_datarepl.html"), "rt") as fin:
+    with open(os.path.join(temp_dir, VISTOMS_TV_NAME_TEMP), "rt") as fin:
         with open(os.path.join(temp_dir, VISTOMS_TV_NAME), "wt") as fout:
             for line in fin:
                 fout.write(pattern.sub(lambda m: rep[re.escape(m.group(0))], line))
 
     # Remove the original VISTOMS file
-    os.remove(os.path.join(temp_dir, 'VISTOMS_TreeViewer_datarepl.html'))
+    os.remove(os.path.join(temp_dir, VISTOMS_TV_NAME_TEMP))
 
     # Remove the dummy files
     os.remove(dummy_cmdows_file)
diff --git a/kadmos/vistoms/__init__.py b/kadmos/vistoms/__init__.py
index 581420d3c..8a767e1d6 100644
--- a/kadmos/vistoms/__init__.py
+++ b/kadmos/vistoms/__init__.py
@@ -1,44 +1,41 @@
 import shutil
 import os
-import re
 
+VISTOMS_NAME_TEMP = 'VISTOMS_Static.html'
+VISTOMS_TV_NAME_TEMP = 'VISTOMS_TreeViewer.html'
 
-def version():
-    """Function returns most recent visualization package version"""
-
-    search_path = os.path.dirname(os.path.abspath(__file__))
-    subdirs = [name for name in os.listdir(search_path) if os.path.isdir(os.path.join(search_path, name))]
-    versions = [re.findall('\d+', subdir) for subdir in subdirs]
-
-    return str(max(versions)[0])
-
-
-def copy(vispack_destination, vispack_version=None):
+def copy(vistoms_destination, vistoms_version='Static'):
     """
     Function to copy a version of the visualization package to a new destination.
 
-    :param vispack_destination: name of the folder to put the visualization package
-    :type vispack_destination: basestring
-    :param vispack_version: version of the visualization package in yymmdd format
-    :type vispack_version: basestring, None
+    :param vistoms_destination: name of the folder to put the visualization package
+    :type vistoms_destination: basestring
+    :param vistoms_version: version of the visualization package ('Static' or 'TreeViewer')
+    :type vistoms_version: basestring
     :return: folder with visualization package
     :rtype: file
     """
 
-    # Get vispack version
-    if vispack_version is None:
-        vispack_version = version()
-
-    # Get directory name of the vispack
-    vispack_folder = 'VISTOMS_' + vispack_version
+    # Set directory and file name of the VISTOMS templates and static files
+    vistoms_folder = 'templates'
+    if vistoms_version == 'Static':
+        vistoms_file = VISTOMS_NAME_TEMP
+    elif vistoms_version == 'TreeViewer':
+        vistoms_file = VISTOMS_TV_NAME_TEMP
+    else:
+        raise IOError('Invalid vistoms_version {} provided. Expected Static or TreeViewer.'.format(vistoms_version))
+    static_folder = 'static'
 
     # Get path names
-    src = os.path.join(os.path.dirname(os.path.abspath(__file__)), vispack_folder)
-    dst = os.path.abspath(vispack_destination)
+    src_html = os.path.join(os.path.dirname(os.path.abspath(__file__)), vistoms_folder, vistoms_file)
+    src_static = os.path.join(os.path.dirname(os.path.abspath(__file__)), static_folder)
+
+    dst = os.path.abspath(vistoms_destination)
 
     # Remove destination directory and copy files
     if os.path.isdir(dst):
         shutil.rmtree(dst)
-    shutil.copytree(src, dst)
+    shutil.copytree(src_static, os.path.join(dst, 'static'))
+    shutil.copy2(src_html, os.path.join(dst, vistoms_file))
 
     return
-- 
GitLab