Software Freedom Law Center

Changeset 10

Show
Ignore:
Timestamp:
12/09/07 21:54:47 (1 year ago)
Author:
bkuhn
Message:
  • Finished basic development work to make the svn -> hg file moving for
    the configs that are stored in SVN for loblaw, but need to show up in
    loblaw-test Mecurial repository.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r8 r10  
     12007-12-09  Bradley M. Kuhn  <bkuhn@softwarefreedom.org> 
     2 
     3        * dev-tools/post-hook-loblaw-test-feed.plx: Ported over from export-cal. 
     4 
     5        * dev-tools/update-loblaw-test.plx (ProcessRevision): Finished rewrites. 
     6 
     7        * dev-tools/svn-scripts-run-check.plx: Ported over from export-cal. 
     8 
     92007-12-07  Bradley M. Kuhn  <bkuhn@softwarefreedom.org> 
     10 
     11        * dev-tools/update-loblaw-test.plx (ProcessRevision): Rewrote to 
     12        handle loblaw-test Mercurial updates. 
     13 
  • trunk/dev-tools/update-loblaw-test.plx

    r9 r10  
    44# uid of the Mercurial repository.  It generally lives in ~svn/bin 
    55# and called from the repository post hooks 
     6 
     7# This program might be of interest to people who want to do some sort of 
     8# operation on files after an SVN commit that requires some set of 
     9# commands to be run on the repository's local system.  In other words, if 
     10# you really wish that when an SVN commit happened, you could log into the 
     11# server and run a bunch of commands against a local checkout of what was 
     12# just committed, then this script is for you. 
     13 
     14# The whole thing is a hack -- no question.  If there's a better way to do 
     15# this job, I'd love to hear about it. 
    616 
    717# The sub's "safe_read_from_pipe" and read_from_process are: 
     
    2333# The rest of the file is: 
    2434# 
    25 # Copyright (c) 2006 Software Freedom Law Center, Inc. 
     35# Copyright (c) 2006, 2007 Software Freedom Law Center, Inc. 
    2636# 
    2737# This software gives you freedom; it is licensed to you under version 3 
     
    4151use warnings; 
    4252 
    43 my $LOBLAW_TRUNK_CHECKOUT = "/home/hg/SVNCheckouts/loblaw-trunk"; 
    4453my $SVN = "/usr/bin/svn"; 
    4554my $SVNLOOK = "/usr/bin/svnlook"; 
     55my $HG = '/usr/bin/hg'; 
     56 
     57my $LOBLAW_TRUNK_CHECKOUT = "/home/hg/SVNCheckouts/loblaw-trunk"; 
     58my $LOBLAW_TEST_HG_CHECKOUT = "/home/hg/SVNCheckouts/loblaw-trunk"; 
     59 
    4660my $PIPE_FILE = "/home/svn/pipes/loblaw-update"; 
    4761 
     
    4963use Fcntl;             # for sysopen 
    5064use Carp; 
    51 use Data::ICal; 
    5265use File::Temp qw/:POSIX tempfile/; 
    53 use DateTime::TimeZone; 
    54 use Date::Manip; 
    55 use DateTime::Format::ICal; 
    56 use Date::ICal; 
     66use File::Path; 
     67use File::Basename; 
     68use File::Copy; 
    5769############################################################################### 
    5870use Unix::Syslog qw(:subs); 
     
    174186} 
    175187############################################################################### 
    176 my $CALENDAR_LOCK_FILE = "/home/hg/locks/update-loblaw-test-unpackaged-lock"; 
     188my $LOCK_FILE = "/home/hg/locks/update-loblaw-test-unpackaged-lock"; 
    177189 
    178190my $LOCK_CLEANUP_CODE = sub { 
    179   return (unlink($CALENDAR_LOCK_FILE) != 1) ? 
    180     "Failed unlink of $CALENDAR_LOCK_FILE.  Could cause trouble." : 
     191  return (unlink($LOCK_FILE) != 1) ? 
     192    "Failed unlink of $LOCK_FILE.  Could cause trouble." : 
    181193    ""; 
    182194}; 
     
    184196############################################################################### 
    185197############################################################################### 
    186 ############################################################################### 
    187 # Take a list of keys and a list of values and insersperse them and 
    188 # return the result 
    189 sub MergeLists { 
    190     my ($keys, $values) = @_; 
    191     DieLog("Length mismatch", $LOCK_CLEANUP_CODE) unless @$keys == @$values; 
    192     # Add the argument names to the values 
    193     my @result; 
    194     for (my $i = 0; $i < @$keys; $i++) { 
    195         push @result, $keys->[$i] => $values->[$i]; 
    196     } 
    197     return @result; 
    198 } 
    199198############################################################################### 
    200199sub DoUpdate ($) { 
     
    222221# Keep track of which revisions we've finished with. 
    223222my %CAUGHT_REVISIONS; 
    224  
     223my %DUAL_REVISIONED_FILE_LIST; 
     224my $LOBLAW_LIST_FILE = 'trunk/dev-tools/loblaw-unpackaged-files.dat'; 
     225############################################################################### 
     226sub BuildDualVersionFileList () { 
     227  %DUAL_REVISIONED_FILE_LIST = (); 
     228 
     229  open(FILE_LIST, "<$LOBLAW_LIST_FILE") 
     230    or DieLog("unable to open $LOBLAW_LIST_FILE: $!"); 
     231  while (my $line = <FILE_LIST>) { 
     232    next if /^\s*#/; 
     233    unless (m%^\s*([/a-zA-Z0-9\-\.\_]+)\s+\=\>\s+/([/a-zA-Z0-9\-\.\_]+)\s*$%) { 
     234      # I am extremely picky in this regex to be super-security concious 
     235      DieLog("Invalid line in $LOBLAW_LIST_FILE: $line"); 
     236    } 
     237    my($source, $destination) = ($1, $2); 
     238    $DUAL_REVISIONED_FILE_LIST{$source} = $destination; 
     239  } 
     240  close FILE_LIST; 
     241
     242############################################################################### 
    225243sub ProcessRevision ($$) { 
    226244  my($repository, $revision) = @_; 
    227245 
    228   return unless $repository =~ m|Repository/Calendars\s*$|; 
     246  return unless $repository =~ m|Repository/loblaw\s*$|; 
    229247 
    230248  chdir $LOBLAW_TRUNK_CHECKOUT or 
     
    236254  my @operateOnFiles; 
    237255 
     256  my $updateFileList = 0; 
     257  $updateFileList = 1 if (keys %DUAL_REVISIONED_FILE_LIST <= 0); 
     258 
    238259  foreach my $changeLine (@svnLookChangedLines) { 
    239260    chomp $changeLine; 
     261    # This script only keeps loblaw-test in sync with trunks' scripts and configs 
     262 
    240263    my(%vals); 
    241264    $vals{changeLine} = $changeLine; 
    242     if ($changeLine =~ m|^\s*(\S)\s+(\S+/Private/(\S+)\.ics)\s*$|) { 
    243       ($vals{operation}, $vals{file}, $vals{user}) = ($1, $2, $3); 
    244       $vals{type} = 'ics'; 
    245     } elsif ($changeLine =~ m|^\s*(\S)\s+(\S+/(\S+)\-public\.diary)\s*$| 
    246       or $changeLine =~ m|^\s*(\S)\s+(\S+/Private/(\S+)\-private\.diary)\s*$|) { 
    247       ($vals{operation}, $vals{file}, $vals{user}) = ($1, $2, $3); 
    248       if (not defined $EMACS_USER_KEY{$vals{user}}) { 
    249         DieLog("$vals{user} is not defined with an EMACS_USER_KEY"); 
    250       } 
    251       $vals{type} = 'emacs'; 
     265    if ($changeLine 
     266        =~ m|^\s*(\S)\s+($LOBLAW_LIST_FILE\s*$|) { 
     267      $updateFileList = 1; 
     268      next; 
     269    } elsif ($changeLine =~ m%^\s*(\S)\s+trunk/((scripts|configs)/\S+)\s*$%) { 
     270      ($vals{operation}, $vals{file}) = ($1, $2); 
    252271    } 
    253272    push(@operateOnFiles, \%vals) 
     
    255274       # skip those cases where we didn't want to do anything with the file 
    256275       # and those that we *would* do something but were ignored items 
    257  
    258   } 
    259   system("/usr/bin/lockfile -r 8 $CALENDAR_LOCK_FILE"); 
     276  } 
     277  read_from_process("/usr/bin/lockfile -r 8 $LOCK_FILE"); 
    260278 
    261279  DieLog("Failure to aquire lock in $repository for $revision. " . 
    262          "Calendar update aborted!") 
     280         "loblaw-test Mercurial update aborted!") 
    263281    unless ($? == 0); 
    264282 
    265283  DoUpdate($revision);  # Make sure we have the latest and the greatest 
     284 
     285  BuildDualVersionFileList() if $updateFileList; 
     286 
     287  # HG process will read this var. 
     288  $ENV{EMAIL} = 'svn@softwarefreedom.org'; 
     289 
    266290  foreach my $vals (@operateOnFiles) { 
    267     my($operation, $user, $file, $changeLine, $type) = 
    268       ($vals->{operation}, $vals->{user}, $vals->{file}, $vals->{changeLine}, 
    269        $vals->{type}); 
    270  
     291    my($operation, $file, $changeLine) = 
     292      ($vals->{operation}, $vals->{file}, $vals->{changeLine}); 
    271293 
    272294    # if we already, through some stretch, we've done this version already, 
    273295    #   then just skip this one. 
    274  
    275296    next if defined $CAUGHT_REVISIONS{"$repository,$revision"}; 
    276297 
    277     my $filteredFile; 
    278     if ($type eq "ics") { 
    279       my $dir = $file;  $dir =~ s|/Private/[^/]+\s*$||; 
    280       $filteredFile = "$LOBLAW_TRUNK_CHECKOUT/$dir/${user}.ics"; 
    281  
    282       PrivacyFilterICalFile("$LOBLAW_TRUNK_CHECKOUT/$file", $filteredFile); 
    283     } elsif ($type eq "emacs") { 
    284       my($publicFile, $privateFile) = 
    285       ("${user}/${user}-public.diary", "${user}/Private/${user}-private.diary"); 
    286       $filteredFile = "$LOBLAW_TRUNK_CHECKOUT/${user}/${user}.ics"; 
    287       FilterEmacsToICal("$LOBLAW_TRUNK_CHECKOUT/$publicFile", 
    288                         "$LOBLAW_TRUNK_CHECKOUT/$privateFile", $filteredFile,  
    289                        $EMACS_USER_KEY{$user}, $user); 
    290     } else { 
    291       DieLog("Unknown file type $type when handling $revision of $file") 
    292     } 
    293  
    294     if ($operation =~ /^\s*A\s*/) { 
    295       # Then we know this user has no published version. 
    296       my @addLines = read_from_process($SVN, 'add', $filteredFile); 
    297       DieLog("Expected \"A $filteredFile\" from $SVN add but got: " . 
    298              join("\n   ", @addLines), $LOCK_CLEANUP_CODE) 
    299         unless ($addLines[0] =~ /^\s*A\s+$filteredFile\s*$/); 
    300     } elsif ($operation =~ /^\s*D\s*/) { 
    301       my @deleteLines = read_from_process($SVN, '--force', 
    302                                           'rm', $filteredFile); 
    303       DieLog("Expected \"D $filteredFile\" from $SVN delete but got: " . 
    304              join("\n   ", @deleteLines), $LOCK_CLEANUP_CODE) 
    305         unless ($deleteLines[0] =~ /^\s*D\s+$filteredFile\s*$/); 
    306     } elsif ($operation =~ /^\s*(?:U|M|\~|L)\s*/) { 
    307       # Nothing specific we need to do 
     298    # See if this is a file we are actually processing over to the hg repository 
     299    next unless defined $DUAL_REVISIONED_FILE_LIST{$file}; 
     300 
     301    if ($operation =~ /^\s*(?:U|M|\~|L|A|D)\s*/) { 
     302      my($dir, $filename); 
     303      if (-d $file) { 
     304        ($dir, $filename) = ($file, ""); 
     305      } else { 
     306        ($dir, $filename) = fileparse($file); 
     307      } 
     308      eval { mkpath("$LOBLAW_TEST_HG_CHECKOUT/$dir", 0, 0755) }; 
     309      DieLog("Couldn't create $LOBLAW_TEST_HG_CHECKOUT/$dir: $@", 
     310             $LOCK_CLEANUP_CODE) if ($@); 
     311 
     312      # copy the actual file over, if it is a file and not a directory. 
     313      unless ($filename =~ /^\s*$/) { 
     314        copy($file, "$LOBLAW_TEST_HG_CHECKOUT/$file") 
     315          or DieLog("Couldn't copy into $LOBLAW_TEST_HG_CHECKOUT/$file: $!", 
     316             $LOCK_CLEANUP_CODE); 
     317      } 
     318      read_from_process($HG, 'add', "$LOBLAW_TEST_HG_CHECKOUT/$file") 
     319        if ($operation =~ /^\s*A\s*/); 
     320      read_from_process($HG, 'remove', "$LOBLAW_TEST_HG_CHECKOUT/$file") 
     321        if ($operation =~ /^\s*D\s*/); 
     322 
     323      my @svnLog = read_from_process($SVN, '-r', $revision, 'log', $file); 
     324      my($tempFH, $tempFile) = mkstemps( "hgcommitXXXXXX", ".log"); 
     325      foreach my $line (@svnLog) { 
     326        chomp $line; 
     327        next if $line =~ /^\s*\-+\s*$/; 
     328        $line =~ s/^(.*\|.*\|.*)(\|.*)$/$1/; 
     329        print $tempFH "$line\n"; 
     330      } 
     331      $tempFH->close(); 
     332      read_from_process($HG, '-l', $tempFile, 'commit', 
     333                        "$LOBLAW_TEST_HG_CHECKOUT/$file"); 
     334      unlink($tempFile); 
    308335    } else { 
    309336      DieLog("Invalid svnlook status, $operation, in $changeLine", 
    310337             $LOCK_CLEANUP_CODE); 
    311338    } 
    312     my @commitLines = read_from_process($SVN, 'commit', '-m', 
    313                           "Automated Public Export of calendar file for $user", 
    314                           $filteredFile); 
    315     DieLog("Expected \"Commited revision NUMBER.\" or no output at all " . 
    316            "from $SVN commit but got: " . 
    317            join("\n   ", @commitLines), $LOCK_CLEANUP_CODE) 
    318       unless (@commitLines <= 0 or $commitLines[$#commitLines] =~ 
    319               /^\s*Committed revision\s+(\d+)\s*\.\s*$/i); 
    320339  } 
    321340  &$LOCK_CLEANUP_CODE; 
     
    431450__END__ 
    432451# Local variables: 
    433 # compile-command: "perl -c export-public-cal.plx" 
     452# compile-command: "perl -c update-loblaw-test.plx" 
    434453# End: 

SFLC Main Page

[frdm] Support SFLC