JAL-4012 tweak release notes wording for legacy.uniprot
[jalview.git] / utils / patchGt.pl
1 #!/bin/perl
2 ##
3 # Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
4 # Copyright (C) $$Year-Rel$$ The Jalview Authors
5
6 # This file is part of Jalview.
7
8 # Jalview is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License 
10 # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 #  
12 # Jalview is distributed in the hope that it will be useful, but 
13 # WITHOUT ANY WARRANTY; without even the implied warranty 
14 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15 # PURPOSE.  See the GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
18 # The Jalview Authors are detailed in the 'AUTHORS' file.
19 ##
20
21 use strict;
22 use Env qw($GTID);
23
24 defined($GTID) or $GTID="UA-9060947-1";
25 my $SCRIPT = <<FOO;
26 <body>
27 <script type="text/javascript">
28     var gaJsHost = (("https:" == document.location.protocol) ?
29         "https://ssl." : "http://www.");
30     document.write(unescape("%3Cscript src=\'" + gaJsHost +
31         "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
32 </script>
33 <script type="text/javascript">
34 try{
35     var pageTracker = _gat._getTracker("'$GTID'");
36     pageTracker._trackPageview();
37 } catch(err) {}
38 </script>
39 FOO
40                 
41 while (scalar @ARGV)
42 {
43     my $f=shift @ARGV;
44     if (-f $f) {
45         if (system("grep","-v","-q",'"'.$GTID.'"',$f)) {
46             if (open OF,">$f.".$GTID) {
47                 if (open IF,"$f") {
48                 while (<IF>) {
49                     if ($_=~m!<body>!) {
50                         $_=~s!<body>!$SCRIPT!;
51                     } else {
52 #                       $_=~s!href="([~"]+)"!href="$1" onclick="
53                     }
54                     print OF $_;
55                 }
56                 close(IF);
57                 close(OF);
58                 rename($f,$f.".old.".$GTID) or die("Couldn't rename $f to $f".".old.".$GTID,$@);
59                 rename($f.".$GTID",$f) or die("Couldn't rename $f.".$GTID." to $f",$@);
60                 unlink($f.".old.".$GTID) or die("Couldn't delete ".$f.".old.".$GTID,$@);
61                 } else {
62                     warn("Can't open $f for reading.",$@);
63                 }
64             } else {
65                 warn("Couldn't open new edited file $f.$GTID",$@);
66             }
67         }
68     }
69 }
70