pulling before building
This commit is contained in:
parent
e55fe41a6c
commit
8d06ac2e9a
@ -10,9 +10,13 @@ bp = Blueprint('document', __name__, url_prefix='/api/doc')
|
|||||||
def build():
|
def build():
|
||||||
doc_name = get_arg('doc')
|
doc_name = get_arg('doc')
|
||||||
branch = get_arg('branch', 'master')
|
branch = get_arg('branch', 'master')
|
||||||
|
|
||||||
doc = Document(doc_name, branch)
|
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/>')
|
return output.replace('\n', '<br/>')
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
from web_utils.run import run
|
||||||
|
|
||||||
document_root = None
|
document_root = None
|
||||||
|
|
||||||
@ -8,30 +8,22 @@ class Document:
|
|||||||
self.doc_name = doc_name
|
self.doc_name = doc_name
|
||||||
self.branch = branch
|
self.branch = branch
|
||||||
|
|
||||||
#print(get_document_root())
|
|
||||||
#print(doc_name)
|
|
||||||
#print(branch)
|
|
||||||
|
|
||||||
doc_path = os.path.realpath(get_document_root()+'/'+doc_name+'/'+branch)
|
doc_path = os.path.realpath(get_document_root()+'/'+doc_name+'/'+branch)
|
||||||
if not doc_path.startswith(get_document_root()):
|
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
|
self.doc_path = doc_path
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
#venv_path = os.getenv('VIRTUAL_ENV')
|
#venv_path = os.getenv('VIRTUAL_ENV')
|
||||||
cmd = "sphinx-build -M html \""+self.doc_path + "/source\" \""+self.doc_path+"/build\""
|
cmd = "sphinx-build -M html \""+self.doc_path + "/repo/source\" \""+self.doc_path+"/build\""
|
||||||
p = Popen(cmd, stdout = PIPE, stderr = STDOUT, shell = True)
|
return run(cmd)
|
||||||
outputStr = ""
|
|
||||||
for line in p.stdout:
|
def pull(self):
|
||||||
outputStr += line.decode()
|
return run("cd \"" + self.doc_path + "/repo\" && git pull")
|
||||||
|
|
||||||
p.wait()
|
|
||||||
|
|
||||||
if p.returncode != 0:
|
|
||||||
raise Exception("Build failed ("+str(p.returncode)+")\n"+outputStr)
|
|
||||||
|
|
||||||
return outputStr
|
|
||||||
|
|
||||||
def set_document_root(dir):
|
def set_document_root(dir):
|
||||||
global document_root
|
global document_root
|
||||||
|
14
src/web_utils/run.py
Normal file
14
src/web_utils/run.py
Normal 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
16
test-document-clone.sh
Executable 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
|
Loading…
Reference in New Issue
Block a user