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