pulling before building

This commit is contained in:
Youen 2022-08-13 12:38:25 +02:00
parent e55fe41a6c
commit 8d06ac2e9a
4 changed files with 47 additions and 21 deletions

View File

@ -10,9 +10,13 @@ bp = Blueprint('document', __name__, url_prefix='/api/doc')
def build():
doc_name = get_arg('doc')
branch = get_arg('branch', 'master')
doc = Document(doc_name, branch)
output = doc.build()
output = ""
output += "\n# Pulling source...\n"
output += doc.pull()
output += "\n# Compiling...\n"
output += doc.build()
return output.replace('\n', '<br/>')

View File

@ -1,5 +1,5 @@
import os
from subprocess import Popen, PIPE, STDOUT
from web_utils.run import run
document_root = None
@ -8,30 +8,22 @@ class Document:
self.doc_name = doc_name
self.branch = branch
#print(get_document_root())
#print(doc_name)
#print(branch)
doc_path = os.path.realpath(get_document_root()+'/'+doc_name+'/'+branch)
if not doc_path.startswith(get_document_root()):
raise Exception("Invalid document path for '"+doc_name+"'@'"+branch)
raise Exception("Invalid document path for "+doc_name+"@"+branch)
if not os.path.isdir(doc_path + "/repo/.git"):
raise Exception("This document does not exist: "+doc_name+"@"+branch)
self.doc_path = doc_path
def build(self):
#venv_path = os.getenv('VIRTUAL_ENV')
cmd = "sphinx-build -M html \""+self.doc_path + "/source\" \""+self.doc_path+"/build\""
p = Popen(cmd, stdout = PIPE, stderr = STDOUT, shell = True)
outputStr = ""
for line in p.stdout:
outputStr += line.decode()
p.wait()
if p.returncode != 0:
raise Exception("Build failed ("+str(p.returncode)+")\n"+outputStr)
return outputStr
cmd = "sphinx-build -M html \""+self.doc_path + "/repo/source\" \""+self.doc_path+"/build\""
return run(cmd)
def pull(self):
return run("cd \"" + self.doc_path + "/repo\" && git pull")
def set_document_root(dir):
global document_root

14
src/web_utils/run.py Normal file
View File

@ -0,0 +1,14 @@
from subprocess import Popen, PIPE, STDOUT
def run(cmd):
p = Popen(cmd, stdout = PIPE, stderr = STDOUT, shell = True)
outputStr = ""
for line in p.stdout:
outputStr += line.decode()
p.wait()
if p.returncode != 0:
raise Exception("Command failed ("+str(p.returncode)+")\n"+cmd+"\n"+outputStr)
return outputStr

16
test-document-clone.sh Executable file
View File

@ -0,0 +1,16 @@
TARGET_DIR=data/doc/test/master/repo
REPO_ORIGIN=https://git.vhelio.org/vhelio/vheliotech-guide-de-montage.git
REPO_BRANCH=main
REPO_SOURCE_DIR=source
[ -e $TARGET_DIR ] && rm -rf $TARGET_DIR
mkdir -p $TARGET_DIR
cd $TARGET_DIR
git init --initial-branch=$REPO_BRANCH
git remote add -f origin $REPO_ORIGIN
git sparse-checkout init
git sparse-checkout set "$REPO_SOURCE_DIR"
git pull origin $REPO_BRANCH
git branch --set-upstream-to=origin/$REPO_BRANCH $REPO_BRANCH