Debian package updates by Jochen Kunkel
[openxpki.git] / www.openxpki.org / trunk / src / generate_html.pl
blob2a33b0b4ab01a7df3f9bcd1cf72a6f9e0c1200e2
1 #!/usr/bin/perl -w
3 use strict;
5 use Cwd;
6 use File::Basename;
7 use File::Find;
8 use File::Path;
9 use File::Spec;
10 use HTML::Mason;
11 use URI;
13 use Getopt::Long;
14 #use Smart::Comments;
16 my $force;
17 GetOptions('force' => \$force);
19 # These are directories. The canonpath method removes any cruft
20 # like doubled slashes.
21 my ($source, $target) = map { File::Spec->canonpath($_) } @ARGV;
23 die "Need a source and target\n"
24 unless defined $source && defined $target;
26 my $usr_file;
27 my $usr_file_name = '.svn_user_name';
28 my $usr_name = '';
29 my %possible_names = map { $_ => 1 } qw(
30 alech
31 bellmich
32 djulia
33 mbartosch
34 oliwel
35 svysh
36 pgrig
37 flowmar
40 if (-e($usr_file_name) && -s _) {
41 open($usr_file,$usr_file_name);
42 $usr_name = <$usr_file>;
43 close($usr_file);
44 chomp($usr_name);
45 $usr_name = '' if (!exists($possible_names{$usr_name}));
48 if ($usr_name eq '') {
49 do {
50 print "Enter your username for SourceForge (to be used in footers of html docs): ";
51 $usr_name = <STDIN>;
52 chomp($usr_name);
53 } until ($usr_name =~ m{ \A [a-zA-Z0-9]+ [-\w]* \Z }xms);
55 if (exists($possible_names{$usr_name})) {
56 open($usr_file,">",$usr_file_name);
57 print $usr_file "$usr_name";
58 close($usr_file);
59 print "Your username for SourceForge is kept in file src/.svn_user_name as $usr_name\n";
61 else {
62 print "Supplied username for SourceForge does not match a list of OpenXPKI developers. \n";
63 print " If you are a new developer then: \n";
64 print " edit src/generate_html.pl, \n";
65 print " rerun gmake from src directory, \n";
66 print " commit src/generate_html.pl. \n";
67 exit 0;
71 $ENV{'SVN_USER_NAME'} = $usr_name;
73 my %files_status;
74 my @svn_output = `svn status`;
75 my $mason_files_changed = 0;
76 foreach my $line (@svn_output) {
77 chomp($line);
78 $line =~ m/ \A \s* ([ACDIMRX?!~]) \s* ([^\s]+?) \s* \Z /xms;
79 $files_status{$2} = $1;
80 $mason_files_changed = 1 if ($2 =~ m/ \A lib\/.*\.mas \Z /xms);
83 # Make target absolute because File::Find changes the current working
84 # directory as it runs.
85 $target = File::Spec->rel2abs($target);
87 my $interp =
88 HTML::Mason::Interp->new( comp_root => File::Spec->rel2abs(cwd) );
90 find( \&convert, $source );
92 sub convert {
93 # We want to split the path to the file into its components and
94 # join them back together with a forward slash in order to make
95 # a component path for Mason
97 # $File::Find::name has the path to the file we are looking at,
98 # relative to the starting directory
99 my $comp_path = join '/', File::Spec->splitdir($File::Find::name);
101 # Strip off leading part of path that matches source directory
102 my $name = $File::Find::name;
103 my $name_with_source = $name;
104 $name =~ s/^$source//;
106 # We dont want to copy subversion dirs
107 if ($name =~ /\.svn/) {
108 return;
111 # Generate absolute path to output file
112 my $out_file = File::Spec->catfile( $target, $name );
114 my $buffer;
115 # We don't want to try to convert our autohandler or .mas
116 # components. $_ contains the filename
117 # old: if (/(\.html|\.css)$/) {
118 if (/(\.html)$/) {
120 # This will save the component's output in $buffer
121 if ((exists($files_status{$name_with_source}) || $force || $mason_files_changed )) {
122 if ((exists($files_status{$name_with_source})) && ($files_status{$name_with_source} =~ m/ \A \? \Z /xms)) {
123 # file is not under version control
124 print STDERR "WARNING: $name_with_source ignored (not under version control)\n";
125 return;
127 else {
128 $interp->out_method(\$buffer);
129 $interp->exec("/$comp_path");
132 else { # file was not changed
133 return;
136 # old: } elsif (/(\.png|\.txt)$/) {
137 } elsif (/(\.png|\.txt|\.css)$/) {
138 # don't process, just copy
139 $buffer = do { local $/;
140 open my $FH, "<$_" or die "Could not open $_. Stopped";
141 <$FH>;
143 } else {
144 # ignore mason components et al.
145 return;
148 # In case the directory doesn't exist, we make it
149 mkpath(dirname($out_file));
151 ### $out_file
152 open my $RESULT, "> $out_file" or die "Cannot write to $out_file: $!";
153 print $RESULT $buffer or die "Cannot write to $out_file: $!";
154 close $RESULT or die "Cannot close $out_file: $!";