Browse Source

adding option to use python simplehttp webserver module which doesn't require users to install lighttpd

tags/v1.0
Max Mehl 2 years ago
parent
commit
121dbd003b
5 changed files with 58 additions and 10 deletions
  1. 1
    0
      .gitignore
  2. 3
    1
      README.md
  3. 20
    4
      config.cfg.sample
  4. 19
    5
      fsfe-preview.sh
  5. 15
    0
      pywebserver-fsfe.py

+ 1
- 0
.gitignore View File

@@ -1,2 +1,3 @@
config.cfg
lighttpd-fsfe.conf
pywebserver-fsfe.log

+ 3
- 1
README.md View File

@@ -1,3 +1,5 @@
# FSFE Local Build

FUll instructions can be found in an extensive blog post: https://blog.mehl.mx/2016/build-fsfe-websites-locally/
This is a collection of scripts and configuration files necessary to build fsfe.org websites locally.

Full instructions can be found in an extensive blog post: https://blog.mehl.mx/2016/build-fsfe-websites-locally/

+ 20
- 4
config.cfg.sample View File

@@ -1,13 +1,29 @@
### BUILD DIRECTORIES ###

# SVN trunk directory (repository with XHTML source files)
LOC_trunk=~/subversion/fsfe/fsfe-web/trunk

# Directory in which the result of the build process (html files) will be saved
LOC_out=~/subversion/fsfe/local-build/fsfe.org

# Path to lighttpd config file (default: points to a file in the same directory as the script)
HTTPD_conf=$ROOT/lighttpd-fsfe.conf

# Directory of the secondary SVN directory with which you made a first full build.
# Avoids having some generated files in your clean trunk.
# Default: Leave empty if you just want to use one SVN source directory
# Default: Leave empty if you just want to use one SVN source directory (recommended)
LOC_trunk_dev=


### LOCAL WEBSERVER ###

# Choose your local webserver.
# Default is "python" which is python's inbuilt http server that is available on most distributions
# Use "lighttpd" if you want to use the Lighttpd webserver. This has to be configured manually (see guide)
HTTPD=python

# Choose on which port the webserver runs. This has no effect for "lighttpd".
HTTPD_port=5080

# If you use other webservers like "lighttpd", this is the path to its config file
# Default: points to a lighttpd config file in the same directory as the script
# Has no effect if you use the "python" webserver
HTTPD_conf=$ROOT/lighttpd-fsfe.conf


+ 19
- 5
fsfe-preview.sh View File

@@ -110,11 +110,25 @@ fi


### START WEBSERVER if necessary
if [ ! $(pgrep lighttpd) ]; then
echo "[INFO] Starting webserver"
/usr/sbin/lighttpd -f $HTTPD_conf
else
echo "[INFO] Webserver already seems to be running."
if [ "$HTTPD" == "python" ]; then # python
if [ ! $(pgrep -f "pywebserver-fsfe.py $LOC_out") ]; then
echo "[INFO] Starting $HTTPD webserver"
nohup "$ROOT/pywebserver-fsfe.py" "$LOC_out" "$HTTPD_port" > "$ROOT"/pywebserver-fsfe.log 2>&1 &
else
echo "[INFO] $HTTPD webserver already seems to be running."
fi
elif [ "$HTTPD" == "lighttpd" ]; then
if [ ! $(pgrep lighttpd) ]; then # lighttpd
echo "[INFO] Starting $HTTPD webserver"
/usr/sbin/lighttpd -f "$HTTPD_conf"
else
echo "[INFO] $HTTPD webserver already seems to be running."
fi
elif [ "$HTTPD" == "" ]; then # empty variable
echo "[ERROR] No webserver specified. Please define variable HTTPD in config.cfg. Aborting now."
exit 1
else # something custom
echo "[WARNING] Unknown webserver defined. Please check variable HTTPD in config.cfg."
fi

### SHOW RESULTS

+ 15
- 0
pywebserver-fsfe.py View File

@@ -0,0 +1,15 @@
#!/usr/bin/env python3

import http.server
import socketserver
import os
import sys

WEB_DIR = sys.argv[1]
WEB_PORT = int(sys.argv[2])

os.chdir(WEB_DIR)

Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", WEB_PORT), Handler)
httpd.serve_forever()

Loading…
Cancel
Save