Author: henkp
Date: Tue Apr 24 13:15:22 2018
New Revision: 1829995

URL: http://svn.apache.org/viewvc?rev=1829995&view=rev
Log:
+= docs/gen-flags

Added:
    attic/site-lua/docs/gen-flags   (with props)

Added: attic/site-lua/docs/gen-flags
URL: 
http://svn.apache.org/viewvc/attic/site-lua/docs/gen-flags?rev=1829995&view=auto
==============================================================================
--- attic/site-lua/docs/gen-flags (added)
+++ attic/site-lua/docs/gen-flags Tue Apr 24 13:15:22 2018
@@ -0,0 +1,162 @@
+#! /usr/bin/perl
+
+use strict ;
+use warnings ;
+use JSON ;
+
+my $DEF_JSON_FILE = '_data/projects.json' ;
+my $DEF_FLAGS_DIR = 'flags' ;
+my $BANNER_FILE   = 'banners' ;
+
+my $prog = substr $0, rindex ( $0, '/' ) + 1 ;
+my $Usage = <<USAGE ;
+Usage: $prog [-v] [-q] [-d] [-f] [json [flags]]
+option v : be verbose
+option q : be quiet
+option d : show debug info
+option f : action ; otherwise dry-run
+argument json  : JSON file ; default $DEF_JSON_FILE
+argument flags : flag directory ; default $DEF_FLAGS_DIR
+----------------------------------------------------------
+$prog generates flag files in directory \$flags/ ;
+-- these flags are used in the httpd config of www.a.o ;
+-- the presence of directory flags/\$tag.apache.org/
+   triggers a redirect for www.a.o/dist/\$tag ;
+-- the presence of file flags/\$tag.apache.org/$BANNER_FILE
+   triggers banners to be added to site \$tag.apache.org.
+----------------------------------------------------------
+USAGE
+sub Usage { die "$_[0]$Usage" ; }
+sub Error { die "[error] $prog: $_[0]\n" ; }
+sub Warn  { warn "[warn] $prog: $_[0]\n" ; }
+
+# usage: &GetOptions(ARG,ARG,..) defines $opt_ID as 1 or user spec'ed value
+# usage: &GetOptions(\%opt,ARG,ARG,..) defines $opt{ID} as 1 or user value
+# ARG = 'ID' | 'ID=SPC' | 'ID:SPC' for no-arg, required-arg or optional-arg
+# ID  = perl identifier
+# SPC = i|f|s for integer, fixedpoint real or string argument
+
+use Getopt::Long ;
+Getopt::Long::config ( 'no_ignore_case' ) ;
+my %opt = () ; Usage '' unless GetOptions
+  ( \%opt, qw(v q d f) ) ;
+Usage "Arg count\n" if @ARGV > 2 ;
+
+$opt{v} ||= $opt{d} ;
+
+my $TAG  = $opt{f} ? 'DID' : 'WOULD' ;
+my $mods = 0 ;
+
+my $JSON_FILE = shift || $DEF_JSON_FILE ;
+my $FLAGS_DIR = shift || $DEF_FLAGS_DIR ;
+chop $FLAGS_DIR while $FLAGS_DIR =~ m!/$! ;
+
+if ( $opt{v} )
+  { print "using json file '$JSON_FILE'\n" ;
+    print "using flags dir '$FLAGS_DIR'\n" ;
+  }
+
+Error "no json file ($JSON_FILE)" unless -f $JSON_FILE ;
+Error "no flags dir ($FLAGS_DIR)" unless -d $FLAGS_DIR ;
+
+sub mk_tag
+  { my $hash = shift ;
+    my $res = $hash -> {id} ;
+    unless ( $res )
+      { $res = lc $hash -> {name} ;
+        $res =~ s![/\s]!-!g ;
+      }
+    $res ;
+  }
+
+sub get_json
+  { open JSON, '<', $JSON_FILE or Error "can't open $JSON_FILE ($!)" ;
+    my $json = from_json join '', <JSON> ;
+    close JSON ;
+    my $res = {} ;
+    for my $hash ( @$json )
+      { next if exists $hash -> {subproject} ;
+        my $tag = mk_tag $hash ;
+        $res -> { $tag } = $hash ;
+      }
+    $res ;
+  }
+
+sub banners
+  { my $hash = shift ;
+    my $date = $hash -> {retired} ;
+    ( split ' ', $date ) [ 1 ] >= 2018 ;
+  }
+
+sub touch
+  { my $file = shift ;
+    my $res  = 1 ;
+    if ( open FILE, '>', $file )
+      { close FILE ; }
+    else
+      { $res = 0 ; }
+    $res ;
+  }
+
+sub mk_flags
+  { my $JSON = shift ;
+    my $res  = {} ;
+    for my $tag ( sort keys %$JSON )
+      { my $hash = $JSON -> { $tag } ;
+        my $fdir = sprintf "%s/%s.apache.org", $FLAGS_DIR, $tag ;
+        $res -> { $fdir } ++ ;
+        unless ( -d $fdir )
+          { printf "$TAG mkdir $fdir\n" unless $opt{q} ;
+            $mods ++ ;
+            if ( $opt{f} )
+              { mkdir $fdir, 0755 or Error "can't mkdir $fdir ($!)" ; }
+          }
+        if ( banners $hash )
+          { my $file = "$fdir/$BANNER_FILE" ;
+            $res -> { $file } ++ ;
+            unless ( -f $file )
+              { printf "$TAG touch $file\n" unless $opt{q} ;
+                $mods ++ ;
+                if ( $opt{f} )
+                  { touch $file or Error "can't touch $file ($!)" ; }
+              }
+          }
+      }
+    $res ;
+  }
+
+sub get_have
+  { opendir FDIR, $FLAGS_DIR or Error "can't opendir $FLAGS_DIR ($!)" ;
+    my @fdir = map "$FLAGS_DIR/$_", grep ! /^\./, readdir FDIR ;
+    closedir FDIR ;
+    my $res = {} ;
+    for my $fdir ( @fdir )
+      { my $file = "$fdir/$BANNER_FILE" ;
+        $res -> { $fdir } ++ ;
+        $res -> { $file } ++ if -f $file ;
+      }
+    $res ;
+  }
+
+sub cleanup
+  { my $want = shift ;
+    my $have = get_have ;
+    for my $item ( reverse sort keys %$have )
+      { if ( $want -> { $item } )
+          { print "we do want $item\n" if $opt{d} ; }
+        else
+          { print "$TAG remove $item\n" ;
+            $mods ++ ;
+            if ( $opt{f} )
+              { if ( -d $item )
+                  { rmdir $item or Error "can't rmdir $item ($!)" ; }
+                else
+                  { unlink "$item" or Error "can't unlink $item ($!)" ; }
+              }
+          }
+      }
+  }
+
+cleanup mk_flags get_json ;
+
+printf "$prog : no change\n" unless $opt{q} or $mods ;

Propchange: attic/site-lua/docs/gen-flags
------------------------------------------------------------------------------
    svn:executable = *


Reply via email to