From 621c4ebe15600635a2d085a55b521fe39cea2511 Mon Sep 17 00:00:00 2001 From: buengese Date: Wed, 15 Jun 2022 15:01:16 +0200 Subject: [PATCH] bin/make_backend_docs: allow generation of docs for just one backend --- bin/make_backend_docs.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/bin/make_backend_docs.py b/bin/make_backend_docs.py index 8753061f9..1871cc68b 100755 --- a/bin/make_backend_docs.py +++ b/bin/make_backend_docs.py @@ -3,9 +3,11 @@ Make backend documentation """ +import sys import os import io import subprocess +from pathlib import Path marker = "{{< rem autogenerated options" start = marker + " start" @@ -16,18 +18,19 @@ def find_backends(): """Return a list of all backends""" return [ x for x in os.listdir("backend") if x not in ("all",) ] -def output_docs(backend, out): +def output_docs(backend, out, cwd): """Output documentation for backend options to out""" out.flush() - subprocess.check_call(["rclone", "help", "backend", backend], stdout=out) + subprocess.check_call(["./rclone", "help", "backend", backend], stdout=out) -def output_backend_tool_docs(backend, out): +def output_backend_tool_docs(backend, out, cwd): """Output documentation for backend tool to out""" out.flush() - subprocess.call(["rclone", "backend", "help", backend], stdout=out, stderr=subprocess.DEVNULL) + subprocess.call(["./rclone", "backend", "help", backend], stdout=out, stderr=subprocess.DEVNULL) def alter_doc(backend): """Alter the documentation for backend""" + rclone_bin_dir = Path(sys.path[0]).parent.absolute() doc_file = "docs/content/"+backend+".md" if not os.path.exists(doc_file): raise ValueError("Didn't find doc file %s" % (doc_file,)) @@ -41,8 +44,8 @@ def alter_doc(backend): in_docs = True start_full = (start + "\" - DO NOT EDIT - instead edit fs.RegInfo in backend/%s/%s.go then run make backenddocs\" " + end + "\n") % (backend, backend) out_file.write(start_full) - output_docs(backend, out_file) - output_backend_tool_docs(backend, out_file) + output_docs(backend, out_file, rclone_bin_dir) + output_backend_tool_docs(backend, out_file, rclone_bin_dir) out_file.write(stop+" "+end+"\n") altered = True if not in_docs: @@ -55,7 +58,18 @@ def alter_doc(backend): if not altered: raise ValueError("Didn't find '%s' markers for in %s" % (start, doc_file)) -if __name__ == "__main__": + +def main(args): + # single backend + if (len(args) == 2): + try: + alter_doc(args[1]) + print("Added docs for %s backend" % args[1]) + except Exception as e: + print("Failed adding docs for %s backend: %s" % (args[1], e)) + return + + # all backends failed, success = 0, 0 for backend in find_backends(): try: @@ -66,3 +80,6 @@ if __name__ == "__main__": else: success += 1 print("Added docs for %d backends with %d failures" % (success, failed)) + +if __name__ == "__main__": + main(sys.argv)