Skip to content

Commit a6e75f1

Browse files
committed
Update fabfile, quick serving function
Allow serving the project with a simple `fab serve` and tidy up some documentation
1 parent fa16899 commit a6e75f1

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

‎fabfile.py‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from fabric.api import local
22
from fabric.context_managers import lcd
33
import os
4+
try:
5+
import SimpleHTTPServer as httpserver
6+
import SocketServer as socketserver
7+
except ImportError:
8+
import http.server as httpserver
9+
import socketserver
410

511

612
BASE_DIR = os.path.realpath(os.path.dirname(__file__))
@@ -11,9 +17,11 @@
1117
LANGUAGES = {'en', 'de'}
1218
MAIN_TARGET = 'html'
1319
REPOSITORY = 'git@github.com:OpenTechSchool/python-beginners.git'
20+
SERVE_PORT = 8000
1421

1522

1623
def setup():
24+
"""Setup html build directory to push to repo"""
1725
clean()
1826
target_dir = os.path.join(BUILD_DIR, MAIN_TARGET)
1927
local('mkdir -p %s' % target_dir)
@@ -34,6 +42,19 @@ def build(target=MAIN_TARGET):
3442
local('cp %s %s' % (static_files, target_dir))
3543

3644

45+
def clean(target=MAIN_TARGET):
46+
local('rm -rf %s' % os.path.join(BUILD_DIR, target))
47+
48+
49+
def serve(serve_dir=BUILD_DIR+'/'+MAIN_TARGET):
50+
"""Run a web server to serve the built project"""
51+
os.chdir(serve_dir)
52+
handler = httpserver.SimpleHTTPRequestHandler
53+
httpd = socketserver.TCPServer(("", SERVE_PORT), handler)
54+
print("serving on http://%s:%s" % httpd.server_address)
55+
httpd.serve_forever()
56+
57+
3758
def build_language(language, target=MAIN_TARGET):
3859
if os.path.isdir(LOCALE_DIR % language):
3960
compile_pos(language)
@@ -52,7 +73,7 @@ def build_language(language, target=MAIN_TARGET):
5273

5374

5475
def update_pos(language=None):
55-
"""Update .po files if source has changed"""
76+
"""Update .po files if the source has changed"""
5677
gen_pots(language)
5778
if language is None:
5879
lang_set = LANGUAGES - {'en'}
@@ -71,7 +92,7 @@ def update_pos(language=None):
7192

7293

7394
def compile_pos(language):
74-
"""Compile .pos into .mos"""
95+
"""Compile .po files into .mo files"""
7596
args = [
7697
'sphinx-intl build',
7798
'-l %s' % language,
@@ -82,7 +103,7 @@ def compile_pos(language):
82103

83104

84105
def gen_pots(language=None):
85-
"""Generate .pots from sphinx source files"""
106+
"""Generate .pot templates from sphinx source files"""
86107
if language is None:
87108
lang_set = LANGUAGES - {'en'}
88109
else:
@@ -96,7 +117,3 @@ def gen_pots(language=None):
96117
os.path.join(BUILD_DIR, 'locale', language),
97118
]
98119
local(' '.join(args))
99-
100-
101-
def clean(target=MAIN_TARGET):
102-
local('rm -rf %s' % os.path.join(BUILD_DIR, target))

0 commit comments

Comments
 (0)