svn-wiki.pl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #! /usr/bin/perl
  2. # Copyright (C) 2005 Alex Schroeder <alex@emacswiki.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. sub ParseData {
  17. my $data = shift;
  18. my %result;
  19. while ($data =~ /(\S+?): (.*?)(?=\n[^ \t]|\Z)/sg) {
  20. my ($key, $value) = ($1, $2);
  21. $value =~ s/\n\t/\n/g;
  22. $result{$key} = $value;
  23. }
  24. return %result;
  25. }
  26. # get this from $FullUrl in the current directory?
  27. my $url = "http://www.communitywiki.org/cgi-bin/cw-en.pl";
  28. my $PageDir = 'page';
  29. my $RawDir = 'raw/trunk';
  30. local $/ = undef; # Read complete files
  31. # include dotfiles!
  32. foreach my $file (glob("$PageDir/*/*.pg $PageDir/*/.*.pg")) {
  33. next unless $file =~ m|/.*/(.+)\.pg$|;
  34. my $page = $1;
  35. mkdir($RawDir) or die "Cannot create $RawDir directory: $!"
  36. unless -d $RawDir;
  37. open(F, $file) or die "Cannot read $page file: $!";
  38. my $data = <F>;
  39. close(F);
  40. my %result = ParseData($data);
  41. my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  42. $atime,$mtime,$ctime,$blksize,$blocks) = stat("$RawDir/$page");
  43. # winner takes all
  44. if ($mtime > $result{ts}) {
  45. print "Updating $page\n";
  46. system("curl",
  47. "-F", "title=$page",
  48. "-F", "text=<$RawDir/$page",
  49. $url);
  50. }
  51. };
  52. # look at svn status
  53. my $status = `svn status`;
  54. foreach my $line (split(/\n/, $status)) {
  55. if ($line =~ /([?ADM])\s+(\S+)/ and -f $2) {
  56. if ($1 eq '?') {
  57. system("svn", "add", $2);
  58. }
  59. # nothing to do for M!
  60. } else {
  61. print $line, "\n";
  62. }
  63. }
  64. system("svn", "commit", "-m", "Update", "-q");