svn-wiki.pl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 2 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, write to the
  16. # Free Software Foundation, Inc.
  17. # 59 Temple Place, Suite 330
  18. # Boston, MA 02111-1307 USA
  19. sub ParseData {
  20. my $data = shift;
  21. my %result;
  22. while ($data =~ /(\S+?): (.*?)(?=\n[^ \t]|\Z)/sg) {
  23. my ($key, $value) = ($1, $2);
  24. $value =~ s/\n\t/\n/g;
  25. $result{$key} = $value;
  26. }
  27. return %result;
  28. }
  29. # get this from $FullUrl in the current directory?
  30. my $url = "http://www.communitywiki.org/cgi-bin/cw-en.pl";
  31. my $PageDir = 'page';
  32. my $RawDir = 'raw/trunk';
  33. local $/ = undef; # Read complete files
  34. # include dotfiles!
  35. foreach my $file (glob("$PageDir/*/*.pg $PageDir/*/.*.pg")) {
  36. next unless $file =~ m|/.*/(.+)\.pg$|;
  37. my $page = $1;
  38. mkdir($RawDir) or die "Cannot create $RawDir directory: $!"
  39. unless -d $RawDir;
  40. open(F, $file) or die "Cannot read $page file: $!";
  41. my $data = <F>;
  42. close(F);
  43. my %result = ParseData($data);
  44. my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  45. $atime,$mtime,$ctime,$blksize,$blocks) = stat("$RawDir/$page");
  46. # winner takes all
  47. if ($mtime > $result{ts}) {
  48. print "Updating $page\n";
  49. system("curl",
  50. "-F", "title=$page",
  51. "-F", "text=<$RawDir/$page",
  52. $url);
  53. }
  54. };
  55. # look at svn status
  56. my $status = `svn status`;
  57. foreach my $line (split(/\n/, $status)) {
  58. if ($line =~ /([?ADM])\s+(\S+)/ and -f $2) {
  59. if ($1 eq '?') {
  60. system("svn", "add", $2);
  61. }
  62. # nothing to do for M!
  63. } else {
  64. print $line, "\n";
  65. }
  66. }
  67. system("svn", "commit", "-m", "Update", "-q");