From d8fcd34fb8fe9ccc4afbf7ecac11cd0e0a24ca7c Mon Sep 17 00:00:00 2001
From: Constantin Pape <c.pape@gmx.net>
Date: Fri, 21 Jun 2019 10:40:15 +0200
Subject: [PATCH] Add bigdataserver file

---
 make_initial_version.py     |  7 ++++++-
 scripts/files/__init__.py   |  1 +
 scripts/files/bdv_server.py | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 scripts/files/bdv_server.py

diff --git a/make_initial_version.py b/make_initial_version.py
index 8bf33d5..ec1a8bc 100755
--- a/make_initial_version.py
+++ b/make_initial_version.py
@@ -6,7 +6,7 @@ from shutil import copyfile
 from scripts.files import make_folder_structure
 from scripts.export import export_segmentation
 from scripts.files import copy_xml_with_abspath, write_simple_xml
-from scripts.files import copy_files_with_pattern
+from scripts.files import copy_files_with_pattern, make_bdv_server_file
 from scripts.attributes import make_nucleus_tables, make_cell_tables
 
 
@@ -108,6 +108,11 @@ def make_initial_version():
 
     make_tables(folder)
 
+    # make the bdv server file
+    make_bdv_server_file([os.path.join(folder, 'images'),
+                          os.path.join(folder, 'segmentations')],
+                         os.path.join(folder, 'misc', 'bdvserver.txt'))
+
 
 if __name__ == '__main__':
     make_initial_version()
diff --git a/scripts/files/__init__.py b/scripts/files/__init__.py
index 5088d2a..111cf66 100644
--- a/scripts/files/__init__.py
+++ b/scripts/files/__init__.py
@@ -2,3 +2,4 @@ from .copy_helper import copy_tables, copy_segmentation, copy_static_files
 from .copy_helper import copy_files_with_pattern
 from .folders import make_folder_structure
 from .xml_utils import get_h5_path_from_xml, copy_xml_with_abspath, write_simple_xml
+from .bdv_server import make_bdv_server_file
diff --git a/scripts/files/bdv_server.py b/scripts/files/bdv_server.py
new file mode 100644
index 0000000..dbb63ac
--- /dev/null
+++ b/scripts/files/bdv_server.py
@@ -0,0 +1,35 @@
+import os
+from .xml_utils import get_h5_path_from_xml
+
+
+# TODO enable filtering for files by some patter.
+# e.g. if we don't want to expose the fib dataset to the public yet
+def make_bdv_server_file(folders, out_path):
+    """ Make the bigserver config file from
+    all xmls in folders.
+    """
+    file_list = {}
+    for folder in folders:
+        files = os.listdir(folders)
+        for ff in files:
+            path = os.path.join(folder, ff)
+
+            # only add xmls
+            ext = os.path.splitext(path)[1]
+            if ext != '.xml':
+                continue
+
+            # make sure that the h5path linked in the xml exists
+            h5path = get_h5_path_from_xml(path, return_absolute_path=True)
+            if not os.path.exists(h5path):
+                msg = 'Path to h5-file in xml does not exist - %s, %s' % (path,
+                                                                          h5path)
+                return RuntimeError(msg)
+
+            name = os.path.splitext(ff)[0]
+            file_list[name] = path
+
+    with open(out_path, 'w') as f:
+        for name, path in file_list.items():
+            line = '%s\t%s\n' % (name, path)
+            f.write(line)
-- 
GitLab