From e15f2620ea4861bb20515b6b94fbd93fb62a8b18 Mon Sep 17 00:00:00 2001
From: Victor Poughon <victor.poughon@cnes.fr>
Date: Wed, 24 Apr 2019 14:15:51 +0200
Subject: [PATCH] DOC: sort examples by tag and fix data handling

---
 Documentation/Cookbook/Scripts/RunExamples.py             | 8 ++++----
 .../Cookbook/Scripts/otbGenerateExamplesRstDoc.py         | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Documentation/Cookbook/Scripts/RunExamples.py b/Documentation/Cookbook/Scripts/RunExamples.py
index e04ea62e62..41cb849897 100755
--- a/Documentation/Cookbook/Scripts/RunExamples.py
+++ b/Documentation/Cookbook/Scripts/RunExamples.py
@@ -33,7 +33,7 @@ blacklist = [
         "LAIAndPROSAILToSensorResponse" # does not run, wrong arguments
     ]
 
-def run_example(otb_root, otb_data, name, dry_run):
+def run_example(otb_root, name, dry_run):
     """
     Run an example by name
     Assumes the current working directory is an OTB build
@@ -71,6 +71,7 @@ def run_example(otb_root, otb_data, name, dry_run):
         print("$ " + binary + " " + " ".join(example_args))
 
         if not dry_run:
+            otb_data = join(otb_root, "Data")
             # Make sure Output dir exists
             os.makedirs(join(otb_data, "Output"), exist_ok=True)
 
@@ -81,19 +82,18 @@ def run_example(otb_root, otb_data, name, dry_run):
 def main():
     parser = argparse.ArgumentParser(usage="Run one or all OTB cxx examples")
     parser.add_argument("otb_root", help="Path to otb repository")
-    parser.add_argument("otb_data", help="Path to otb-data repository")
     parser.add_argument("--name", type=str, help="Run only one example with then given name")
     parser.add_argument("-n", "--dry-run", action='store_true', help="Dry run, only print commands")
     parser.add_argument("-k", "--keep-going", action='store_true', help="Keep going after failing examples")
     args = parser.parse_args()
 
     if args.name:
-        run_example(args.otb_root, args.otb_data, args.name, dry_run=args.dry_run)
+        run_example(args.otb_root, args.name, dry_run=args.dry_run)
     else:
         list_of_examples =[os.path.splitext(os.path.basename(f))[0] for f in glob.glob(join(args.otb_root, "Examples/*/*.cxx"))]
         for name in list_of_examples:
             try:
-                run_example(args.otb_root, args.otb_data, name, dry_run=args.dry_run)
+                run_example(args.otb_root, name, dry_run=args.dry_run)
             except Exception as e:
                 if args.keep_going:
                     print("Warning:", e)
diff --git a/Documentation/Cookbook/Scripts/otbGenerateExamplesRstDoc.py b/Documentation/Cookbook/Scripts/otbGenerateExamplesRstDoc.py
index 95463f1191..f534a97dcb 100644
--- a/Documentation/Cookbook/Scripts/otbGenerateExamplesRstDoc.py
+++ b/Documentation/Cookbook/Scripts/otbGenerateExamplesRstDoc.py
@@ -44,7 +44,7 @@ def generate_examples_index(rst_dir, list_of_examples):
     index_f = open(join(rst_dir, "Examples.rst"), "w")
     index_f.write(RstPageHeading("C++ Examples", 3, ref="cpp-examples"))
 
-    for tag, examples_filenames in tag_files.items():
+    for tag, examples_filenames in sorted(tag_files.items()):
         tag_filename = join("Examples", tag + ".rst")
         index_f.write("\t" + tag_filename + "\n")
 
-- 
GitLab