moved scripts to bin/, added gulp tasks

This commit is contained in:
Bachir Soussi Chiadmi
2017-03-26 12:39:37 +02:00
parent 55c06ee81a
commit b68f53c0b0
7 changed files with 51 additions and 4 deletions
Executable
+126
View File
@@ -0,0 +1,126 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, os
import shutil
import markdown
# import mistune
from bs4 import BeautifulSoup
import pypandoc
import json
import re
# import json
# import getopt
# import urllib
BOOKS_SRC = 'book-src'
BUILD_d = "build"
CUR_PATH = os.path.dirname(os.path.abspath(__file__))
def main():
if not os.path.isdir(BUILD_d):
os.mkdir(BUILD_d)
for book in os.listdir(BOOKS_SRC):
if os.path.isdir(os.path.join(BOOKS_SRC, book)):
# print(book)
parse_book(book)
def parse_book(book):
book_name = book.replace('.git', '')
print("- - -")
print(book_name)
print("- - -")
# build destination
book_build_d = os.path.join(BUILD_d,book_name)
if os.path.isdir(book_build_d):
shutil.rmtree(book_build_d, ignore_errors=True)
os.mkdir(book_build_d)
# table of content (ordered list of markdown files)
sum_p = os.path.join(BOOKS_SRC, book, "SUMMARY.md")
if not os.path.isfile(sum_p):
print("No summary file, can't generate html")
return
sum_f = open(sum_p)
sum_str = sum_f.read()
# print(sum_str)
sum_html = markdown.markdown(sum_str)
# print(sum_html)
sum_dom = BeautifulSoup(sum_html, 'html.parser')
# print(sum_dom)
toc = parse_summary(sum_dom.ul, {})
# print(toc)
generate_html(book, toc, book_build_d)
def parse_summary(ul, toc):
i=0
for li in ul.find_all('li',recursive=False):
# print('li')
for a in li.find_all('a',recursive=False):
# print(a.get_text(strip=True))
# print(a['href'])
href = a['href']
href = re.sub(r'^/', '', href)
toc[i] = {
'label':a.get_text(strip=True),
'file':href
}
i = i+1
return toc
def generate_html(book, toc, book_build_d):
railway = []
for p in toc:
# print(toc[p]['file'])
# generate html with pandoc
# files
md_f = toc[p]['file']
html_f = md_f.replace('.md', '.html')
html_f = html_f.replace('README', 'index')
html_f = html_f.replace('/', '-')
in_f = os.path.join(BOOKS_SRC, book, md_f)
# print(in_f)
out_f = os.path.join(book_build_d,html_f)
# print(out_f)
# pandoc options
# filters = []
pdoc_args = ['-s',
'--mathjax',
'--smart',
'--css=assets/fonts/amiri/amiri.css',
'--css=assets/css/dist/styles.css',
'--include-before-body=templates/top.tpl.html',
'--include-after-body=templates/bot.tpl.html',
'--include-after-body=assets/js/jquery.min.js',
'--include-after-body=assets/js/script.js',
'--include-after-body=templates/end.tpl.html']
# pandoc command line
# print(pypandoc.get_pandoc_version())
output = pypandoc.convert_file(in_f,
to='html5',
format='md',
extra_args=pdoc_args,
# filters=filters,
outputfile=out_f)
# save reference in railway
railway.append({'label':toc[p]['label'], 'file':html_f})
# save railway as json file
with open(book_build_d+'/railway.json', 'w') as fp:
json.dump(railway, fp, ensure_ascii=False, indent="\t")
if __name__ == "__main__":
main()
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# install deps
sudo pacman -S --needed --noconfirm base-devel ninja qt5
mkdir ospkit.src
# installing qtwebkit ospkit branch
cd ospkit/
git clone -o github -b ospkit --single-branch github:aleray/webkit.git
cd webkit/
WEBKIT_OUTPUTDIR=`pwd`/build/qt Tools/Scripts/build-webkit --qt --release
cd build/qt/Release/
sudo ninja install
cd ../../../../
# installing ospkit
git clone -o constant-gitlab http://gitlab.constantvzw.org/osp/tools.ospkit.git
cd tools.ospkit/src/
qmake
make
cd ../../
ln -s /tools.ospkit/src/OSPKit OSPKit
View File
Executable
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
echo "Sync books"
# activate credential cache
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=7200'
folder='book-src'
host='https://figureslibres.io/gogs/bachir'
# echo "$host"
repos[0]='TDSM-oeuvres'
repos[1]='TDSM-notices'
repos[2]='TDSM-commissaires'
repos[3]='TDSM-english'
# echo $repos
for repo in "${repos[@]}"
do
echo ${repo}
if [ -d $folder/$repo.git ];
then
# if repos exists, pull
echo "Pull $repo"
git -C $folder/$repo.git pull origin master
else
# if repos does not exists, clone
echo "clone $repo"
git clone $host/$repo.git $folder/$repo.git
fi
done