From 8e8f7fe2d912cd1de6dc0b51b0b672d6cf457ef7 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Sun, 22 Nov 2020 11:43:48 +0100
Subject: [PATCH] update_website: introduce verbose flag; migrate from click to
 argparse

Couldn't find out how to make flag work under click.
Anyway, we should use the same library everywhere.
---
 devtools/code-tools/print-includes.py |  2 +-
 devtools/code-tools/update-website.py | 65 +++++++++++++++------------
 2 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/devtools/code-tools/print-includes.py b/devtools/code-tools/print-includes.py
index 9dfa6c99e64..e2dd0135508 100755
--- a/devtools/code-tools/print-includes.py
+++ b/devtools/code-tools/print-includes.py
@@ -25,7 +25,7 @@ flist = sys.argv[1:]
 for fn in flist:
     inspect( fn )
 
-# remove duplicates and sort (how much more elegant would this be in Ruby...)
+# remove duplicates and sort
 tmp = set(result)
 result = list(tmp)
 result.sort()
diff --git a/devtools/code-tools/update-website.py b/devtools/code-tools/update-website.py
index e777fc3eaba..7890055dde9 100755
--- a/devtools/code-tools/update-website.py
+++ b/devtools/code-tools/update-website.py
@@ -8,13 +8,9 @@ This will run all existing examples and generate intensity images for web site.
 
 2) Run this script
 python update-examples.py <website-source-dir> <BornAgain-source-dir> <BornAgain-build-dir>
-
-TODO: move the script under ctest control
 """
-import os
-import shutil
-import click
 
+import argparse, os, shutil
 
 def find_files(dir_name):
     """
@@ -62,8 +58,6 @@ def copy_files(source_list, destination_list):
             print(len(found_source), "Problem with ", f)
             missed_files.append(f)
 
-    print("Summary:")
-
     print("Following files have been updated on website:")
     for f in updated_files:
         print(f)
@@ -74,18 +68,6 @@ def copy_files(source_list, destination_list):
             print(f)
 
 
-def update_example_images(website_dir, example_images):
-    """
-    Copies example images from BornAgain build directory to website.
-    """
-    website = os.path.join(website_dir, "content/documentation/examples")
-    source = example_images
-    website_files = get_files(website, ".png")
-    source_files = get_files(source, ".png")
-
-    copy_files(source_files, website_files)
-
-
 def update_example_scripts(website_dir, bornagain_source):
     """
     Copies example scripts from BornAgain to website.
@@ -94,15 +76,28 @@ def update_example_scripts(website_dir, bornagain_source):
     source = os.path.join(bornagain_source, "Examples/Python")
     website_files = get_files(website, ".py")
     source_files = get_files(source, ".py")
-    print(website_files)
+
+    print(f'Update {len(website_files)} scripts ...')
+
+    if verbose:
+        print(website_files)
 
     copy_files(source_files, website_files)
 
 
-@click.command()
-@click.argument("website_source_dir", required=True, type=str)
-@click.argument("ba_source_dir", required=True, type=str)
-@click.argument("ba_build_dir", required=True, type=str)
+def update_example_images(website_dir, example_images):
+    """
+    Copies example images from BornAgain build directory to website.
+    """
+    print("Update images ...")
+
+    website = os.path.join(website_dir, "content/documentation/examples")
+    source = example_images
+    website_files = get_files(website, ".png")
+    source_files = get_files(source, ".png")
+
+    copy_files(source_files, website_files)
+
 
 def update_website(website_source_dir, ba_source_dir, ba_build_dir):
     """
@@ -113,14 +108,26 @@ def update_website(website_source_dir, ba_source_dir, ba_build_dir):
     user_build_dir = os.path.expanduser(ba_build_dir)
     user_image_dir = os.path.join(user_build_dir, "test_output/Functional/PyExamples")
 
-    print("website_dir    : '{}'".format(user_website_dir))
-    print("source_dir     : '{}'".format(user_source_dir))
-    print("build_dir      : '{}'".format(user_build_dir))
-    print("image_dir      : '{}'".format(user_image_dir))
+    if verbose:
+        print("Directories:")
+        print("  website_dir    : '{}'".format(user_website_dir))
+        print("  source_dir     : '{}'".format(user_source_dir))
+        print("  build_dir      : '{}'".format(user_build_dir))
+        print("  image_dir      : '{}'".format(user_image_dir))
 
     update_example_scripts(user_website_dir, user_source_dir)
     update_example_images(user_website_dir, user_image_dir)
 
 
 if __name__ == '__main__':
-    update_website()
+
+    parser = argparse.ArgumentParser()
+    parser.add_argument("-v", "--verbose", action="store_true")
+    parser.add_argument("website_source_dir", type=str)
+    parser.add_argument("ba_source_dir", type=str)
+    parser.add_argument("ba_build_dir", type=str)
+    args = parser.parse_args()
+
+    verbose = args.verbose
+
+    update_website(args.website_source_dir, args.ba_source_dir, args.ba_build_dir)
-- 
GitLab