forked from OpenTechSchool/python-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfabfile.py
More file actions
51 lines (41 loc) · 1.39 KB
/
fabfile.py
File metadata and controls
51 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from fabric.api import local
from fabric.context_managers import lcd
import os
BASE_DIR = os.path.realpath(os.path.dirname(__file__))
BUILD_DIR = os.path.join(BASE_DIR, '_build')
LANGUAGES = ['en']
MAIN_TARGET = 'html'
REPOSITORY = 'git@github.com:OpenTechSchool/python-beginners.git'
def setup():
clean()
target_dir = os.path.join(BUILD_DIR, MAIN_TARGET)
with lcd(BASE_DIR):
local('mkdir -p %s' % target_dir)
local('git clone %s %s' % (REPOSITORY, target_dir))
with lcd(target_dir):
local('git symbolic-ref HEAD refs/heads/gh-pages')
local('rm -rf .git/index')
local('git clean -fdx')
local('git pull origin gh-pages')
local('touch .nojekyll')
def build(target='html'):
for language in LANGUAGES:
build_language(language, target)
if 'html' in target:
static_files = os.path.join(BASE_DIR, '_static', '*')
target_dir = os.path.join(BUILD_DIR, target)
local('cp %s %s' % (static_files, target_dir))
def build_language(language, target='html'):
args = [
'sphinx-build',
'-b',
target,
'-d',
os.path.join(BUILD_DIR, 'doctrees', language),
os.path.join(BASE_DIR, language),
os.path.join(BUILD_DIR, target, language),
]
command = ' '.join(args)
local(command)
def clean():
local('rm -rf %s' % os.path.join(BUILD_DIR, '*', '*'))