Changeset 10
- Timestamp:
- 12/09/07 21:54:47 (1 year ago)
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/dev-tools/post-hook-loblaw-test-feed.plx (added)
- trunk/dev-tools/svn-scripts-run-check.plx (added)
- trunk/dev-tools/update-loblaw-test.plx (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r8 r10 1 2007-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 9 2007-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 4 4 # uid of the Mercurial repository. It generally lives in ~svn/bin 5 5 # 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. 6 16 7 17 # The sub's "safe_read_from_pipe" and read_from_process are: … … 23 33 # The rest of the file is: 24 34 # 25 # Copyright (c) 2006 Software Freedom Law Center, Inc.35 # Copyright (c) 2006, 2007 Software Freedom Law Center, Inc. 26 36 # 27 37 # This software gives you freedom; it is licensed to you under version 3 … … 41 51 use warnings; 42 52 43 my $LOBLAW_TRUNK_CHECKOUT = "/home/hg/SVNCheckouts/loblaw-trunk";44 53 my $SVN = "/usr/bin/svn"; 45 54 my $SVNLOOK = "/usr/bin/svnlook"; 55 my $HG = '/usr/bin/hg'; 56 57 my $LOBLAW_TRUNK_CHECKOUT = "/home/hg/SVNCheckouts/loblaw-trunk"; 58 my $LOBLAW_TEST_HG_CHECKOUT = "/home/hg/SVNCheckouts/loblaw-trunk"; 59 46 60 my $PIPE_FILE = "/home/svn/pipes/loblaw-update"; 47 61 … … 49 63 use Fcntl; # for sysopen 50 64 use Carp; 51 use Data::ICal;52 65 use File::Temp qw/:POSIX tempfile/; 53 use DateTime::TimeZone; 54 use Date::Manip; 55 use DateTime::Format::ICal; 56 use Date::ICal; 66 use File::Path; 67 use File::Basename; 68 use File::Copy; 57 69 ############################################################################### 58 70 use Unix::Syslog qw(:subs); … … 174 186 } 175 187 ############################################################################### 176 my $ CALENDAR_LOCK_FILE = "/home/hg/locks/update-loblaw-test-unpackaged-lock";188 my $LOCK_FILE = "/home/hg/locks/update-loblaw-test-unpackaged-lock"; 177 189 178 190 my $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." : 181 193 ""; 182 194 }; … … 184 196 ############################################################################### 185 197 ############################################################################### 186 ###############################################################################187 # Take a list of keys and a list of values and insersperse them and188 # return the result189 sub MergeLists {190 my ($keys, $values) = @_;191 DieLog("Length mismatch", $LOCK_CLEANUP_CODE) unless @$keys == @$values;192 # Add the argument names to the values193 my @result;194 for (my $i = 0; $i < @$keys; $i++) {195 push @result, $keys->[$i] => $values->[$i];196 }197 return @result;198 }199 198 ############################################################################### 200 199 sub DoUpdate ($) { … … 222 221 # Keep track of which revisions we've finished with. 223 222 my %CAUGHT_REVISIONS; 224 223 my %DUAL_REVISIONED_FILE_LIST; 224 my $LOBLAW_LIST_FILE = 'trunk/dev-tools/loblaw-unpackaged-files.dat'; 225 ############################################################################### 226 sub 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 ############################################################################### 225 243 sub ProcessRevision ($$) { 226 244 my($repository, $revision) = @_; 227 245 228 return unless $repository =~ m|Repository/ Calendars\s*$|;246 return unless $repository =~ m|Repository/loblaw\s*$|; 229 247 230 248 chdir $LOBLAW_TRUNK_CHECKOUT or … … 236 254 my @operateOnFiles; 237 255 256 my $updateFileList = 0; 257 $updateFileList = 1 if (keys %DUAL_REVISIONED_FILE_LIST <= 0); 258 238 259 foreach my $changeLine (@svnLookChangedLines) { 239 260 chomp $changeLine; 261 # This script only keeps loblaw-test in sync with trunks' scripts and configs 262 240 263 my(%vals); 241 264 $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); 252 271 } 253 272 push(@operateOnFiles, \%vals) … … 255 274 # skip those cases where we didn't want to do anything with the file 256 275 # 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"); 260 278 261 279 DieLog("Failure to aquire lock in $repository for $revision. " . 262 " Calendarupdate aborted!")280 "loblaw-test Mercurial update aborted!") 263 281 unless ($? == 0); 264 282 265 283 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 266 290 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}); 271 293 272 294 # if we already, through some stretch, we've done this version already, 273 295 # then just skip this one. 274 275 296 next if defined $CAUGHT_REVISIONS{"$repository,$revision"}; 276 297 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); 308 335 } else { 309 336 DieLog("Invalid svnlook status, $operation, in $changeLine", 310 337 $LOCK_CLEANUP_CODE); 311 338 } 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);320 339 } 321 340 &$LOCK_CLEANUP_CODE; … … 431 450 __END__ 432 451 # Local variables: 433 # compile-command: "perl -c export-public-cal.plx"452 # compile-command: "perl -c update-loblaw-test.plx" 434 453 # End: