Added first admin page and possibility to consult built documents
This commit is contained in:
parent
5432669dff
commit
3a3edd3651
src
@ -6,7 +6,7 @@ import os
|
|||||||
|
|
||||||
from data.document import Document
|
from data.document import Document
|
||||||
|
|
||||||
bp = Blueprint('document', __name__, url_prefix='/api/doc')
|
bp = Blueprint('api_document', __name__, url_prefix='/api/doc')
|
||||||
|
|
||||||
@bp.route('/build')
|
@bp.route('/build')
|
||||||
def build():
|
def build():
|
12
src/app.py
12
src/app.py
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
import data.document
|
import data.document
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
@ -8,8 +9,13 @@ def create_app():
|
|||||||
src_path = os.path.dirname(os.path.realpath(__file__))
|
src_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
data.document.set_document_root(os.path.realpath(src_path+'/../data/doc'))
|
data.document.set_document_root(os.path.realpath(src_path+'/../data/doc'))
|
||||||
|
|
||||||
from api import document
|
from api import api_document
|
||||||
app.register_blueprint(document.bp)
|
app.register_blueprint(api_document.bp)
|
||||||
|
|
||||||
|
from web import web_admin
|
||||||
|
app.register_blueprint(web_admin.bp)
|
||||||
|
|
||||||
|
from web import web_document
|
||||||
|
app.register_blueprint(web_document.bp)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from types import SimpleNamespace
|
||||||
from web_utils.run import run
|
from web_utils.run import run
|
||||||
import shutil
|
import shutil
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
@ -28,15 +29,20 @@ def sanitize_name(initial_name):
|
|||||||
return name
|
return name
|
||||||
|
|
||||||
class Document:
|
class Document:
|
||||||
def __init__(self, doc_name, branch = 'master'):
|
def __init__(self, doc_name, branch = 'master', allow_invalid = False):
|
||||||
self.doc_name = doc_name
|
self.doc_name = doc_name
|
||||||
self.branch = branch
|
self.branch = branch
|
||||||
|
|
||||||
doc_path = Document.make_doc_path(doc_name, branch)
|
doc_path = Document.make_doc_path(doc_name, branch)
|
||||||
if not os.path.isdir(doc_path + "/repo/.git"):
|
if not os.path.isdir(doc_path + "/repo/.git"):
|
||||||
raise Exception("This document does not exist: "+doc_name+"@"+branch)
|
if allow_invalid:
|
||||||
|
self.valid = False
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise Exception("This document does not exist: "+doc_name+"@"+branch)
|
||||||
|
|
||||||
self.doc_path = doc_path
|
self.doc_path = doc_path
|
||||||
|
self.valid = True
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
#venv_path = os.getenv('VIRTUAL_ENV')
|
#venv_path = os.getenv('VIRTUAL_ENV')
|
||||||
@ -46,6 +52,9 @@ class Document:
|
|||||||
def pull(self):
|
def pull(self):
|
||||||
return run("cd \"" + self.doc_path + "/repo\" && git pull")
|
return run("cd \"" + self.doc_path + "/repo\" && git pull")
|
||||||
|
|
||||||
|
def get_url(self):
|
||||||
|
return "/doc/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/index.html"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_doc_path(doc_name, branch):
|
def make_doc_path(doc_name, branch):
|
||||||
doc_path = os.path.realpath(get_document_root()+'/'+sanitize_name(doc_name)+'/'+sanitize_name(branch))
|
doc_path = os.path.realpath(get_document_root()+'/'+sanitize_name(doc_name)+'/'+sanitize_name(branch))
|
||||||
@ -85,6 +94,15 @@ class Document:
|
|||||||
# cloning failed, clean up and raise the same exception again
|
# cloning failed, clean up and raise the same exception again
|
||||||
shutil.rmtree(doc_path)
|
shutil.rmtree(doc_path)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def list():
|
||||||
|
result = []
|
||||||
|
for doc_name in os.listdir(get_document_root()):
|
||||||
|
for branch in os.listdir(get_document_root() + "/" + doc_name):
|
||||||
|
doc = Document(doc_name, branch, allow_invalid = True)
|
||||||
|
result.append(doc)
|
||||||
|
return result
|
||||||
|
|
||||||
def set_document_root(dir):
|
def set_document_root(dir):
|
||||||
global document_root
|
global document_root
|
||||||
|
24
src/templates/index.html
Normal file
24
src/templates/index.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Documentation (admin)</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Administration des documents</h1>
|
||||||
|
<a href="">Nouveau document...</a>
|
||||||
|
<h2>Liste des documents</h2>
|
||||||
|
<ul>
|
||||||
|
{% for doc in documents %}
|
||||||
|
{% if doc.valid %}
|
||||||
|
<li>{{ doc.doc_name }} / {{ doc.branch }} <a href="{{ doc.get_url() }}">Consulter</a></li>
|
||||||
|
{% else %}
|
||||||
|
<li>{{ doc.doc_name }} / {{ doc.branch }} (document invalide)</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="/static/index.js"></script>
|
||||||
|
</body>
|
9
src/web/web_admin.py
Normal file
9
src/web/web_admin.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from flask import Blueprint, render_template
|
||||||
|
|
||||||
|
from data.document import Document
|
||||||
|
|
||||||
|
bp = Blueprint('web_admin', __name__, url_prefix='/admin')
|
||||||
|
|
||||||
|
@bp.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template("index.html", documents=Document.list())
|
12
src/web/web_document.py
Normal file
12
src/web/web_document.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import os
|
||||||
|
from flask import Blueprint, render_template, send_from_directory
|
||||||
|
from data.document import get_document_root
|
||||||
|
|
||||||
|
from data.document import Document
|
||||||
|
|
||||||
|
bp = Blueprint('web_document', __name__, url_prefix='/doc')
|
||||||
|
|
||||||
|
@bp.route('/<doc_name>/<branch>/<path:path>')
|
||||||
|
def index(doc_name, branch, path):
|
||||||
|
doc = Document(doc_name, branch)
|
||||||
|
return send_from_directory(doc.doc_path + "/build/html", path)
|
Loading…
Reference in New Issue
Block a user