[Tools 1/2] winetest: Automatically detect the root of the website.

Francois Gouget fgouget at codeweavers.com
Wed Jul 30 11:37:32 CDT 2014


Note that the CGI scripts rely on the administrator to configure the web server so $::RootDir is set up for them.
---

For Apache this can be done with something like this:

  PerlOptions +Parent
  <Perl>
    use strict;
    BEGIN
    {
      $::RootDir = "/home/winehq/sites/winetest";
      unshift @INC, $::RootDir;
    }
  </Perl>

(Adjust $::RootDir as appropriate)

 winetest/build-index   | 14 ++++++++++
 winetest/dissect       | 14 ++++++++++
 winetest/gather        | 14 ++++++++++
 winetest/winetest.conf |  9 +++---
 winetest/winetest.cron | 75 +++++++++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 118 insertions(+), 8 deletions(-)

diff --git a/winetest/build-index b/winetest/build-index
index 900b144..da8ada2 100755
--- a/winetest/build-index
+++ b/winetest/build-index
@@ -24,6 +24,20 @@ use warnings;
 use open ':utf8';
 use CGI qw(:standard);
 
+BEGIN
+{
+  if ($0 !~ m=^/=)
+  {
+    # Turn $0 into an absolute path so it can safely be used in @INC
+    require Cwd;
+    $0 = Cwd::cwd() . "/$0";
+  }
+  if ($0 =~ m=^(/.*)/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, $::RootDir;
+  }
+}
 use vars qw/$gitdir $gitweb/;
 require "winetest.conf";
 
diff --git a/winetest/dissect b/winetest/dissect
index 676f089..955dfd7 100755
--- a/winetest/dissect
+++ b/winetest/dissect
@@ -38,6 +38,20 @@ use open ':utf8';
 use CGI qw(:standard);
 charset("utf-8");
 
+BEGIN
+{
+  if ($0 !~ m=^/=)
+  {
+    # Turn $0 into an absolute path so it can safely be used in @INC
+    require Cwd;
+    $0 = Cwd::cwd() . "/$0";
+  }
+  if ($0 =~ m=^(/.*)/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, $::RootDir;
+  }
+}
 use vars qw/$gitdir $gitweb $queuedir $datadir $maxmult $maxuserskips $maxfailedtests $maxfilesize $acceptprediluvianwin/;
 require "winetest.conf";
 
diff --git a/winetest/gather b/winetest/gather
index 5b56b61..28f396c 100755
--- a/winetest/gather
+++ b/winetest/gather
@@ -35,6 +35,20 @@ use warnings;
 use CGI qw(:standard);
 charset("utf-8");
 
+BEGIN
+{
+  if ($0 !~ m=^/=)
+  {
+    # Turn $0 into an absolute path so it can safely be used in @INC
+    require Cwd;
+    $0 = Cwd::cwd() . "/$0";
+  }
+  if ($0 =~ m=^(/.*)/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, $::RootDir;
+  }
+}
 use vars qw/$datadir $gitweb/;
 require "winetest.conf";
 
diff --git a/winetest/winetest.conf b/winetest/winetest.conf
index d229c0a..a2cd004 100644
--- a/winetest/winetest.conf
+++ b/winetest/winetest.conf
@@ -1,11 +1,12 @@
 # Hey Emacs! This is a -*-cperl-*- file!
 
-$root = "/home/winehq/opt/winetest";
+# $::RootDir must already point to the web site's root directory.
+
 # These two below should be on the same filesystem
-$queuedir = "$root/queue";
-$datadir  = "$root/data";
+$queuedir = "$::RootDir/queue";
+$datadir  = "$::RootDir/data";
 
-$gitdir = "/home/winehq/opt/source/git/wine.git";
+$gitdir = "$::RootDir/wine.git";
 $gitweb = "//source.winehq.org/git/wine.git";
 
 # Maximum number of reports for one version and tag
diff --git a/winetest/winetest.cron b/winetest/winetest.cron
index eaacf4f..273c563 100755
--- a/winetest/winetest.cron
+++ b/winetest/winetest.cron
@@ -1,11 +1,78 @@
 #!/bin/sh
 #
 # Cron job for generating winetest reports.  Use it like
-# */5 * * * * apache winetest.cron
+# */5 * * * * winetest.cron /home/winehq/sites/winetest
+name0=`basename "$0"`
 
-tools=/home/winehq/opt/git-tools/winetest
-workdir=/home/winehq/opt/winetest
-lock=/tmp/winetest.lock
+error()
+{
+    echo "$name0:error:" "$@" >&2
+}
+
+workdir=""
+usage=""
+while [ $# -gt 0 ]
+do
+    arg="$1"
+    shift
+    case "$arg" in
+    -\?|-h|--help)
+        usage=0
+        ;;
+    -*)
+        error "unknown option '$arg'"
+        usage=2
+        break
+        ;;
+    *)
+        if [ -n "$workdir" ]
+        then
+            error "only one website directory can be specified"
+            usage=2
+        fi
+        workdir="$arg"
+        ;;
+    esac
+done
+
+if [ -z "$usage" ]
+then
+    if [ -z "$workdir" ]
+    then
+        error "you must specify the location of the website directory"
+        usage=2
+    elif [ ! -d "$workdir/data" ]
+    then
+        error "'$workdir/data' is not a directory: wrong website directory location"
+        usage=2
+    fi
+fi
+
+if [ -n "$usage" ]
+then
+    if [ "$usage" != "0" ]
+    then
+        error "try '$name0 --help' for more information"
+        exit $usage
+    fi
+    cat <<EOF
+Usage: $name0 [--help] WORKDIR
+
+Processes the reports in the queue, updates the website's pages and cleans up
+obsolete files.
+
+Where:
+  --help, -h   Shows this help message.
+EOF
+    exit 0
+fi
+
+tools=`dirname "$0"`
+case "$tools" in
+/*) ;; # Nothing to do
+*)  tools="`pwd`/$tools" ;;
+esac
+lock="/tmp/winetest.lock"
 
 # expiration age (in days) before results get archived
 expire=120
-- 
2.0.1




More information about the wine-patches mailing list