Browse Source

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

mxmehl 3 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 @@
1 1
 config.cfg
2 2
 lighttpd-fsfe.conf
3
+pywebserver-fsfe.log

+ 3
- 1
README.md View File

@@ -1,3 +1,5 @@
1 1
 # FSFE Local Build
2 2
 
3
-FUll instructions can be found in an extensive blog post: https://blog.mehl.mx/2016/build-fsfe-websites-locally/
3
+This is a collection of scripts and configuration files necessary to build fsfe.org websites locally. 
4
+
5
+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 @@
1
+### BUILD DIRECTORIES ###
2
+
1 3
 # SVN trunk directory (repository with XHTML source files)
2 4
 LOC_trunk=~/subversion/fsfe/fsfe-web/trunk
3 5
 
4 6
 # Directory in which the result of the build process (html files) will be saved
5 7
 LOC_out=~/subversion/fsfe/local-build/fsfe.org
6 8
 
7
-# Path to lighttpd config file (default: points to a file in the same directory as the script)
8
-HTTPD_conf=$ROOT/lighttpd-fsfe.conf
9
-
10 9
 # Directory of the secondary SVN directory with which you made a first full build. 
11 10
 # Avoids having some generated files in your clean trunk. 
12
-# Default: Leave empty if you just want to use one SVN source directory
11
+# Default: Leave empty if you just want to use one SVN source directory (recommended)
13 12
 LOC_trunk_dev=
13
+
14
+
15
+### LOCAL WEBSERVER ###
16
+
17
+# Choose your local webserver. 
18
+# Default is "python" which is python's inbuilt http server that is available on most distributions
19
+# Use "lighttpd" if you want to use the Lighttpd webserver. This has to be configured manually (see guide)
20
+HTTPD=python
21
+
22
+# Choose on which port the webserver runs. This has no effect for "lighttpd". 
23
+HTTPD_port=5080
24
+
25
+# If you use other webservers like "lighttpd", this is the path to its config file 
26
+# Default: points to a lighttpd config file in the same directory as the script
27
+# Has no effect if you use the "python" webserver
28
+HTTPD_conf=$ROOT/lighttpd-fsfe.conf
29
+

+ 19
- 5
fsfe-preview.sh View File

@@ -110,11 +110,25 @@ fi
110 110
 
111 111
 
112 112
 ### START WEBSERVER if necessary
113
-if [ ! $(pgrep lighttpd) ]; then
114
-  echo "[INFO] Starting webserver"
115
-  /usr/sbin/lighttpd -f $HTTPD_conf
116
-else
117
-  echo "[INFO] Webserver already seems to be running."
113
+if [ "$HTTPD" == "python" ]; then   # python
114
+  if [ ! $(pgrep -f "pywebserver-fsfe.py $LOC_out") ]; then
115
+    echo "[INFO] Starting $HTTPD webserver"
116
+    nohup "$ROOT/pywebserver-fsfe.py" "$LOC_out" "$HTTPD_port" > "$ROOT"/pywebserver-fsfe.log 2>&1 &
117
+  else
118
+    echo "[INFO] $HTTPD webserver already seems to be running."
119
+  fi
120
+elif [ "$HTTPD" == "lighttpd" ]; then
121
+  if [ ! $(pgrep lighttpd) ]; then   # lighttpd
122
+    echo "[INFO] Starting $HTTPD webserver"
123
+    /usr/sbin/lighttpd -f "$HTTPD_conf"
124
+  else
125
+    echo "[INFO] $HTTPD webserver already seems to be running."
126
+  fi
127
+elif [ "$HTTPD" == "" ]; then   # empty variable
128
+  echo "[ERROR] No webserver specified. Please define variable HTTPD in config.cfg. Aborting now."
129
+  exit 1
130
+else    # something custom
131
+  echo "[WARNING] Unknown webserver defined. Please check variable HTTPD in config.cfg." 
118 132
 fi
119 133
 
120 134
 ### SHOW RESULTS

+ 15
- 0
pywebserver-fsfe.py View File

@@ -0,0 +1,15 @@
1
+#!/usr/bin/env python3
2
+
3
+import http.server
4
+import socketserver
5
+import os
6
+import sys
7
+
8
+WEB_DIR = sys.argv[1]
9
+WEB_PORT = int(sys.argv[2])
10
+
11
+os.chdir(WEB_DIR)
12
+
13
+Handler = http.server.SimpleHTTPRequestHandler
14
+httpd = socketserver.TCPServer(("", WEB_PORT), Handler)
15
+httpd.serve_forever()

Loading…
Cancel
Save