"""Automatically setup docs for a project Call from command line: bench frappe --setup_docs app docs_app path """ import os, json, frappe class setup_docs(object): def __init__(self, app, docs_app, path): """Generate source templates for models reference and module API. Must set globals `self.models_base_path`, `self.api_base_path` and `self.app_path`. """ self.app = app self.app_path = frappe.get_app_path(app) if path[0]=="/": path = path[1:] path = frappe.get_app_path(docs_app, path) self.models_base_path = os.path.join(path, "models") self.api_base_path = os.path.join(path, "api") for basepath, folders, files in os.walk(self.app_path): if "doctype" not in basepath: if "doctype" in folders: module = os.path.basename(basepath) module_folder = os.path.join(self.models_base_path, module) self.make_folder(module_folder) self.update_index_txt(module_folder) if "doctype" in basepath: parts = basepath.split("/") #print parts module, doctype = parts[-3], parts[-1] if doctype not in ("doctype", "boilerplate"): self.write_model_file(basepath, module, doctype) elif self.is_py_module(basepath, folders, files): self.write_modules(basepath, folders, files) def is_py_module(self, basepath, folders, files): return "__init__.py" in files \ and (not "/doctype" in basepath) \ and (not "/patches" in basepath) \ and (not "/change_log" in basepath) \ and (not "/report" in basepath) \ and (not "/page" in basepath) \ and (not "/templates" in basepath) \ and (not "/tests" in basepath) \ and (not "doctype" in folders) def write_modules(self, basepath, folders, files): module_folder = os.path.join(self.api_base_path, os.path.relpath(basepath, self.app_path)) self.make_folder(module_folder) for f in files: if f.endswith(".py"): module_name = os.path.relpath(os.path.join(basepath, f), self.app_path)[:-3].replace("/", ".").replace(".__init__", "") module_doc_path = os.path.join(module_folder, self.app + "." + module_name + ".html") self.make_folder(basepath) if not os.path.exists(module_doc_path): print "Writing " + module_doc_path with open(module_doc_path, "w") as f: f.write("""