Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.pl.test.patch 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. --- build.pl 2011-08-17 12:54:16.000000000 +0200
  2. +++ build-test.pl 2011-08-17 12:54:47.000000000 +0200
  3. @@ -1,6 +1,6 @@
  4. #! /usr/bin/perl
  5. #
  6. -# build.pl - a tool for building FSFE web pages
  7. +# build.pl - a tool for building FSF Europe web pages
  8. #
  9. # Copyright (C) 2003 Jonas Öberg
  10. #
  11. @@ -32,6 +32,12 @@
  12. use Socket;
  13. use Fcntl ':flock';
  14. +use FindBin;
  15. +use lib "$FindBin::Bin";
  16. +
  17. +
  18. +require "comptree.pl";
  19. +
  20. # This defines the focuses and their respective preferred / original
  21. # language. For example, it says that we should have a focus called
  22. # "se" (Sweden) which has the preferred language "sv" (Swedish).
  23. @@ -95,8 +101,7 @@
  24. # This static array contains files that can't be out of date
  25. our %cant_be_outdated = (
  26. - "news/news" => 1,
  27. - "index" => 1
  28. + "news/news" => 1
  29. );
  30. @@ -319,6 +324,8 @@
  31. sub process {
  32. my ($file, $langs) = @_;
  33. + #print "$file\n";
  34. +
  35. print STDERR "Building $file.. \n" unless $opts{q};
  36. # Create the root note for the above mentioned XML file (used to feed the XSL
  37. # transformation).
  38. @@ -387,9 +394,9 @@
  39. # Transform it, once for every focus!
  40. #
  41. while (my ($dir, undef) = each %countries) {
  42. +
  43. # If we handle a focus specific file, only process it in that focus
  44. - # -> we don't handle focus-specific files anymore, commenting next line out, since it's causing errors
  45. - #next if (("$srcfocus" ne "global") && ("$dir" ne "$srcfocus"));
  46. + next if (("$srcfocus" ne "global") && ("$dir" ne "$srcfocus"));
  47. print STDERR "$dir " unless $opts{q};
  48. @@ -587,16 +594,65 @@
  49. # with the original (but maybe a second earlier) isn't marked outdated.
  50. #
  51. my $originalsource = "$file.".$root->getAttribute("original").".xhtml";
  52. +
  53. + my $comment;
  54. +
  55. + my $old_outdated = 0;
  56. if (( stat("$opts{i}/$originalsource"))[9] > (stat($source))[9] + 7200
  57. and not $cant_be_outdated{$file} ) {
  58. +
  59. + $old_outdated = 1;
  60. +
  61. + } else {
  62. +
  63. + }
  64. +
  65. + my $new_outdated = 0;
  66. + if ( not -e "$opts{i}/$originalsource" ) {
  67. +
  68. + # TODO: do something
  69. +
  70. + } else {
  71. +
  72. + my ($equal, $err) = areEqual( "$opts{i}/$originalsource", $source );
  73. + if ( not $equal and not $cant_be_outdated{$file} ) {
  74. + #print "$err\n";
  75. $root->setAttribute("outdated", "yes");
  76. - if ($dir eq "global") {
  77. - lock(*TRANSLATIONS);
  78. - print TRANSLATIONS "$lang $source $originalsource\n";
  79. - unlock(*TRANSLATIONS);
  80. + $new_outdated = 1;
  81. +
  82. + # register information about the outdated status
  83. + my $info = $dom->createElement("outdated-info");
  84. + my $code = $dom->createElement("code");
  85. + $code->appendChild($dom->createElement("br"));
  86. + foreach $line (split(/\n/, $err)) {
  87. + $code->appendText($line);
  88. + $code->appendChild($dom->createElement("br"));
  89. }
  90. + $info->appendChild($code);
  91. + $document->appendChild($info);
  92. +
  93. } else {
  94. +
  95. $root->setAttribute("outdated", "no");
  96. +
  97. + }
  98. +
  99. + }
  100. +
  101. + if ($dir eq "global" and $new_outdated != $old_outdated ) {
  102. +
  103. + if ( $new_outdated == 0 and $old_outdated == 1 ) {
  104. + $comment = "timestamp-OUT,structure-OK";
  105. + } elsif ( $new_outdated == 1 and $old_outdated == 0 ) {
  106. + $comment = "timestamp-OK,structure-OUT";
  107. + } else {
  108. + $comment = "-";
  109. + }
  110. +
  111. + lock(*TRANSLATIONS);
  112. + print TRANSLATIONS "$lang $source $originalsource $comment\n";
  113. + unlock(*TRANSLATIONS);
  114. +
  115. }
  116. #
  117. @@ -652,8 +708,84 @@
  118. }
  119. $root->appendChild($menuroot);
  120. +
  121. + # <start addendum> (TODO: transform this into a function)
  122. +
  123. #
  124. - # Do the actual transformation.
  125. + # Get the list of sources and create the files hash. The files
  126. + # hash contains the base name for each file we want to use, and
  127. + # then the language for it as a value. It prefers a file in the
  128. + # language we're building into, but will accept an English file as
  129. + # a substitute.
  130. + #
  131. + # "Learn all that is learnable and return that information
  132. + # to the Creator."
  133. + #
  134. + open(IN, '<', "$opts{i}/fsfe.sources");
  135. + my @auto_sources = <IN>;
  136. + close IN;
  137. + my %files;
  138. + foreach (@auto_sources) {
  139. + if (/(.*):[a-z,]*global/ || /(.*):[a-z,]*$dir/) {
  140. + foreach my $f (glob("$1*")) {
  141. + if ($f =~ /(.*)\.([a-z][a-z])\.xml$/) {
  142. + if (!$files{$1}) {
  143. + $files{$1} = $2;
  144. + } elsif ($2 eq $lang) {
  145. + $files{$1} = $2;
  146. + } elsif (($2 eq "en") &&
  147. + ($files{$1} ne $lang)) {
  148. + $files{$1} = $2;
  149. + }
  150. + }
  151. + }
  152. + }
  153. + }
  154. +
  155. + #
  156. + # With that information, we load the source document and create
  157. + # a new element in it, called <set>, which will hold the combined
  158. + # knowledge of all the sets in the source files.
  159. + #
  160. + foreach ($root->getElementsByTagName("set")) {
  161. + $root->removeChild($_);
  162. + }
  163. + my $auto_data = $dom->createElement("set");
  164. +
  165. + while (my ($base, $l) = each %files) {
  166. + if (($dir eq "global") && ($l ne $lang)) {
  167. + lock(*TRANSLATIONS);
  168. + print TRANSLATIONS "$lang $base.$lang.xml $base.$l.xml\n";
  169. + unlock(*TRANSLATIONS);
  170. + }
  171. + print STDERR "Loading $base.$l.xml\n" if $opts{d};
  172. + my $source_data = $parser->parse_file("$base.$l.xml");
  173. + foreach ($source_data->documentElement->childNodes) {
  174. + my $c = $_->cloneNode(1);
  175. + # add the filename to nodes (news, events, …) so that we can use it as an identifier (e.g. for RSS)
  176. + if (ref($c) eq "XML::LibXML::Element") {
  177. + $base =~ /.*[\/_]([^\/_]*$)/;
  178. + $c->setAttribute( "filename", $1 );
  179. + }
  180. + $auto_data->appendChild($c);
  181. + }
  182. + }
  183. + $root->appendChild($auto_data);
  184. +
  185. + # <end addendum>
  186. +
  187. +
  188. + if ( $lang eq "fr" and $file eq $file_to_treat ) {
  189. +
  190. + print "--->outputting test2.xml\n";
  191. + open (TEST, '>', "/home/nicolas/FSFE/fsfe-web-out/test2.xml");
  192. + print TEST $dom->toString();
  193. + close (TEST);
  194. +
  195. + }
  196. +
  197. + #
  198. + # Do the actual transformation. (through fsfe.xsl)
  199. #
  200. my $results = $global_stylesheet->transform($dom);
  201. @@ -663,9 +795,9 @@
  202. #
  203. foreach ($results->documentElement->getElementsByTagName("a")) {
  204. my $href = $_->getAttribute("href");
  205. - if ($href =~ /^http:\/\/www.fsfe.org/) {
  206. + if ($href =~ /^http:\/\/test.fsfe.org/) {
  207. if ($_->textContent != "Our global work") {
  208. - $href =~ s/http:\/\/www.fsfe.org//;
  209. + $href =~ s/http:\/\/test.fsfe.org//;
  210. }
  211. }
  212. if (($href !~ /^http/) && ($href !~ /^#/)) {
  213. @@ -691,10 +823,6 @@
  214. }
  215. # replace anchor
  216. $href .= $anchor;
  217. - # For pages running on an external server, use full URL
  218. - if ($document->getAttribute("external")) {
  219. - $href = "http://www.fsfe.org$href";
  220. - }
  221. $_->setAttribute("href", $href);
  222. }
  223. }