[gegl] docs: make gegl usage generation more portable



commit 1094ebcdd5c029881692692b4b3435f677365e1f
Author: John <jtm home gmail com>
Date:   Tue Jul 14 21:25:17 2020 +0100

    docs: make gegl usage generation more portable

 docs/commandline.txt     |  2 +-
 docs/gegl-usage.py       | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 docs/meson.build         | 12 +++++++++
 docs/website/meson.build |  2 ++
 4 files changed, 83 insertions(+), 1 deletion(-)
---
diff --git a/docs/commandline.txt b/docs/commandline.txt
index e54726647..ab0db6f30 100644
--- a/docs/commandline.txt
+++ b/docs/commandline.txt
@@ -19,5 +19,5 @@ The following is the usage information of the gegl binary, this documentation
 might not be complete.
 
 -------
-sys::[bash -c './bin/gegl -h 2>&1']
+include::{gegl_usage}[gegl-usage.txt]
 -------
diff --git a/docs/gegl-usage.py b/docs/gegl-usage.py
new file mode 100644
index 000000000..11cc1fe01
--- /dev/null
+++ b/docs/gegl-usage.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+#
+# Copyright John Marshall 2021
+#
+import os
+import sys
+import argparse
+import subprocess
+
+class Args():
+    def __init__(self):
+        parser = argparse.ArgumentParser()
+        parser.add_argument(
+            '--gegl-exe',
+            metavar='GEGL',
+            help='gegl program'
+        )
+        parser.add_argument(
+            '--output',
+            metavar='OUTPUT_FILE',
+            help='output file - otherwise output to STDOUT'
+        )
+
+        # executables
+        if sys.platform == 'win32':
+            exe_ext = '.exe'
+        else:
+            exe_ext = ''
+
+        # gegl
+        if parser.parse_args().gegl_exe:
+            self.gegl_exe = parser.parse_args().gegl_exe
+        else:
+            self.gegl_exe = os.path.join(
+                self.build_root, 'bin', 'gegl' + exe_ext
+            )
+        self.gegl_exe = os.path.realpath(self.gegl_exe)
+        # output file
+        if parser.parse_args().output:
+            self.output = os.path.realpath(parser.parse_args().output)
+        else:
+            self.output = None
+
+
+def main():
+    args = Args()
+
+    if args.output:
+        try:
+            out_file = open(os.path.realpath(args.output), 'w')
+        except IOError:
+            print('cannot open output file %s' % args.output,
+                  sys.stderr)
+            sys.exit(1)
+    else:
+        out_file = sys.stdout
+
+    subprocess.call(
+        [args.gegl_exe, '--help'],
+        stderr = subprocess.STDOUT,
+        stdout = out_file
+    )
+
+    sys.exit(0)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/docs/meson.build b/docs/meson.build
index ce8e68ec5..e597e8927 100644
--- a/docs/meson.build
+++ b/docs/meson.build
@@ -80,6 +80,18 @@ else
 endif
 
 # website html files
+if can_run_host_binaries
+  gegl_usage = custom_target(
+    'gegl_usage_txt',
+    output: 'gegl-usage.txt',
+    command: [
+      find_program('gegl-usage.py'),
+      '--output', '@OUTPUT@',
+      '--gegl-exe', gegl_bin, 
+    ]
+  )
+endif
+
 website_asciidoc_files = files(
   'index.txt',
   'build.txt',
diff --git a/docs/website/meson.build b/docs/website/meson.build
index dd7a5f1b7..7fadb96fc 100644
--- a/docs/website/meson.build
+++ b/docs/website/meson.build
@@ -36,6 +36,7 @@ if asciidoc.found()
         asciidoc,
         '--unsafe',
         '-o', '@OUTPUT@',
+        '-a', 'gegl_usage=@0@'.format(gegl_usage.full_path()),
         '-a', 'stylesheet=@0@'.format(
             project_source_root / 'docs' / 'gegl.css'
           ),
@@ -43,6 +44,7 @@ if asciidoc.found()
         '@INPUT@',
       ],
       build_by_default : true,
+      depends: gegl_usage,
     )
   endforeach
   index_html = _tgt[0]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]