From 6a2fb6cced98d79cd1ccbe6490a59393486fdf92 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 1 Dec 2020 23:34:36 +0300 Subject: Add new function to fetch md file from sys paths * wqflask/wqflask/markdown_routes.py: New imports. (get_file_from_python_search_path): New function. --- wqflask/wqflask/markdown_routes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 1e077dd1..e43b9860 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -4,6 +4,8 @@ Render pages from github, or if they are unavailable, look for it else where """ import requests import markdown +import os +import sys from flask import Blueprint from flask import render_template @@ -33,6 +35,14 @@ look for it inside the file system """ "Please reach out to the gn2 team to have a look at this") +def get_file_from_python_search_path(pathname_suffix): + cands = [os.path.join(d, pathname_suffix) for d in sys.path] + try: + return list(filter(os.path.exists, cands))[0] + except IndexError: + return None + + @glossary_blueprint.route('/') def glossary(): return render_template( -- cgit 1.4.1