Skip to content

Commit

Permalink
bin/make_backend_docs: allow generation of docs for just one backend
Browse files Browse the repository at this point in the history
  • Loading branch information
buengese committed Jun 16, 2022
1 parent 0279bf3 commit 621c4eb
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions bin/make_backend_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,))
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -66,3 +80,6 @@ def alter_doc(backend):
else:
success += 1
print("Added docs for %d backends with %d failures" % (success, failed))

if __name__ == "__main__":
main(sys.argv)

0 comments on commit 621c4eb

Please sign in to comment.