From: Arti Zirk Date: Thu, 24 Jan 2019 16:13:31 GMT Subject: [PATCH v1] git-instaweb: Add Python builtin http.server support Message-ID: <20190124161331.25945-1-arti.zirk@gmail.com> With this patch it is possible to launch git-instaweb by using Python 3 http.server CGI handler via `-d python` option. git-instaweb generates a small wrapper around the http.server (in GIT_DIR/gitweb/) that address a limitation of the CGI handler where CGI scripts have to be in a cgi-bin subdirectory and directory index can't be easily changed. To keep the implementation small, gitweb is running on url `/cgi-bin/gitweb.cgi` and an automatic redirection is done when opening `/`. Python 3 is by default installed on most modern Linux distributions which enables running `git instaweb -d python` without needing anything else. Signed-off-by: Arti Zirk --- Notes: Base Ref: master Web-Diff: https://github.com/artizirk/git/commit/a40d28ca58 Checkout: git fetch https://github.com/artizirk/git instaweb-python-v1 && git checkout a40d28ca58 Documentation/git-instaweb.txt | 3 +- git-instaweb.sh | 114 ++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 2 deletions(-) diff --git a/Documentation/git-instaweb.txt b/Documentation/git-instaweb.txt index e8ecdbf927..a54fe4401b 100644 --- a/Documentation/git-instaweb.txt +++ b/Documentation/git-instaweb.txt @@ -29,7 +29,8 @@ OPTIONS The HTTP daemon command-line that will be executed. Command-line options may be specified here, and the configuration file will be added at the end of the command-line. - Currently apache2, lighttpd, mongoose, plackup and webrick are supported. + Currently apache2, lighttpd, mongoose, plackup, python and + webrick are supported. (Default: lighttpd) -m:: diff --git a/git-instaweb.sh b/git-instaweb.sh index eec264e630..c8f9f03447 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -67,6 +67,13 @@ resolve_full_httpd () { httpd_only="${httpd%% *}" # cut on first space return ;; + *python*) + # server is started by running via generated gitweb.py in + # $fqgitdir/gitweb + full_httpd="$fqgitdir/gitweb/gitweb.py" + httpd_only="${httpd%% *}" # cut on first space + return + ;; esac httpd_only="$(echo $httpd | cut -f1 -d' ')" @@ -110,7 +117,7 @@ start_httpd () { # don't quote $full_httpd, there can be arguments to it (-f) case "$httpd" in - *mongoose*|*plackup*) + *mongoose*|*plackup*|*python*) #These servers don't have a daemon mode so we'll have to fork it $full_httpd "$conf" & #Save the pid before doing anything else (we'll print it later) @@ -595,6 +602,108 @@ EOF rm -f "$conf" } +python_conf() { + # Python's builtin http.server and its CGI support is very limited. + # CGI handler is capable of running CGI script only from inside a directory. + # Trying to set cgi_directories=["/"] will add double slash to SCRIPT_NAME + # and that in turn breaks gitweb's relative link generation. + + # create a simple web root where $fqgitdir/gitweb/$httpd_only is our root + mkdir -p "$fqgitdir/gitweb/$httpd_only/cgi-bin" + # Python http.server follows the symlinks + ln -sf "$root/gitweb.cgi" "$fqgitdir/gitweb/$httpd_only/cgi-bin/gitweb.cgi" + ln -sf "$root/static" "$fqgitdir/gitweb/$httpd_only/" + + # generate a standalone 'python3 http.server' script in $fqgitdir/gitweb + # This asumes that python3 is in user's $PATH + cat > "$fqgitdir/gitweb/gitweb.py" < "$fqgitdir/gitweb/gitweb_config.perl" <