Browse Source

Added support for multiversion build (wip)

master
Youen 2 years ago
parent
commit
7be5ec701d
  1. 47
      src/data/document.py
  2. 2
      src/web/web_document.py

47
src/data/document.py

@ -53,22 +53,45 @@ class Document:
self.doc_path = doc_path self.doc_path = doc_path
self.valid = True self.valid = True
# TODO: actually read document settings
self.settings = {
'multiversion': False,
'default_version': 'main'
}
def build(self): def build(self):
#venv_path = os.getenv('VIRTUAL_ENV') multiversion_build = self.settings['multiversion']
cmd = [] cmd = []
# update source files from git # update source files from git
cmd.append(['git', 'pull']) cmd.append(['git', 'pull'])
# build the HTML version if multiversion_build:
cmd.append(['make', 'html', 'BUILDDIR=../build']) # also fetch all branches and tags, so that sphinx-multiversion knows what versions exist and can pull them
cmd.append(['bash', '-c', 'for BRANCH in $(git branch -a | grep remotes | grep -v HEAD | grep -v master); do git branch --track "${BRANCH#remotes/origin/}" "${BRANCH}" || echo "(ignored)"; done'])
# build the HTML version
cmd.append(['make', 'html_versions', 'BUILDDIR=../build'])
# TODO: build PDF(s) version(s)
else:
# build the HTML version
cmd.append(['make', 'html', 'BUILDDIR=../build'])
# build the PDF version
cmd.append(['make', 'pdf', 'BUILDDIR=../build'])
# build the PDF version # Copy the generated PDF file to the HTML directory, so that it is accessible for download by users
cmd.append(['make', 'pdf', 'BUILDDIR=../build']) cmd.append(['cp', self.doc_path + '/build/weasyprint/vheliotech.pdf', self.doc_path + '/build/html/' + self.doc_name + '.pdf'])
# Copy the generated PDF file to the HTML directory, so that it is accessible for download by users # Now that the build is successfull, move it to the deployment directory (replacing any existing content)
cmd.append(['cp', self.doc_path + '/build/weasyprint/vheliotech.pdf', self.doc_path + '/build/html/' + self.doc_name + '.pdf']) cmd.append(['rm', '-rf', self.doc_path + '/dist'])
if multiversion_build:
cmd.append(['mv', self.doc_path + '/build/html_versions/', self.doc_path + '/dist/'])
else:
cmd.append(['mv', self.doc_path + '/build/html/', self.doc_path + '/dist/'])
task = ProcessTask(cmd, cwd = self.doc_path + "/repo") task = ProcessTask(cmd, cwd = self.doc_path + "/repo")
task.start() task.start()
@ -91,10 +114,16 @@ class Document:
os.rmdir(origin_root) os.rmdir(origin_root)
def get_url(self): def get_url(self):
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/index.html" if self.settings['multiversion']:
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/" + self.settings['default_version'] + "/index.html"
else:
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/index.html"
def get_pdf_url(self): def get_pdf_url(self):
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/" + self.doc_name + ".pdf" if self.settings['multiversion']:
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/" + self.settings['default_version'] + "/" + self.doc_name + ".pdf"
else:
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/" + self.doc_name + ".pdf"
def get_api_key(self): def get_api_key(self):
with open(self.doc_path + "/apikey") as f: with open(self.doc_path + "/apikey") as f:

2
src/web/web_document.py

@ -9,4 +9,4 @@ bp = Blueprint('web_document', __name__, url_prefix='/doc')
@bp.route('/<origin>/<doc_name>/<branch>/<path:path>') @bp.route('/<origin>/<doc_name>/<branch>/<path:path>')
def index(origin, doc_name, branch, path): def index(origin, doc_name, branch, path):
doc = Document(origin, doc_name, branch) doc = Document(origin, doc_name, branch)
return send_from_directory(doc.doc_path + "/build/html", path) return send_from_directory(doc.doc_path + "/dist", path)

Loading…
Cancel
Save