|
|
|
@ -52,23 +52,46 @@ class Document:
|
|
|
|
|
|
|
|
|
|
self.doc_path = doc_path |
|
|
|
|
self.valid = True |
|
|
|
|
|
|
|
|
|
# TODO: actually read document settings |
|
|
|
|
self.settings = { |
|
|
|
|
'multiversion': False, |
|
|
|
|
'default_version': 'main' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
def build(self): |
|
|
|
|
#venv_path = os.getenv('VIRTUAL_ENV') |
|
|
|
|
multiversion_build = self.settings['multiversion'] |
|
|
|
|
|
|
|
|
|
cmd = [] |
|
|
|
|
|
|
|
|
|
# update source files from git |
|
|
|
|
cmd.append(['git', 'pull']) |
|
|
|
|
|
|
|
|
|
# build the HTML version |
|
|
|
|
cmd.append(['make', 'html', 'BUILDDIR=../build']) |
|
|
|
|
if multiversion_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 |
|
|
|
|
cmd.append(['make', 'pdf', 'BUILDDIR=../build']) |
|
|
|
|
# Copy the generated PDF file to the HTML directory, so that it is accessible for download by users |
|
|
|
|
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 |
|
|
|
|
cmd.append(['cp', self.doc_path + '/build/weasyprint/vheliotech.pdf', self.doc_path + '/build/html/' + self.doc_name + '.pdf']) |
|
|
|
|
# Now that the build is successfull, move it to the deployment directory (replacing any existing content) |
|
|
|
|
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.start() |
|
|
|
@ -91,10 +114,16 @@ class Document:
|
|
|
|
|
os.rmdir(origin_root) |
|
|
|
|
|
|
|
|
|
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): |
|
|
|
|
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): |
|
|
|
|
with open(self.doc_path + "/apikey") as f: |
|
|
|
|