mirror of
				https://github.com/rclone/rclone.git
				synced 2025-10-30 23:17:59 +02:00 
			
		
		
		
	bin/make_backend_docs: allow generation of docs for just one backend
This commit is contained in:
		
				
					committed by
					
						 Sebastian Bünger
						Sebastian Bünger
					
				
			
			
				
	
			
			
			
						parent
						
							0279bf3abb
						
					
				
				
					commit
					621c4ebe15
				
			| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user