Debian Codegraph @

tools/sf2bacula_downloads.pl

raw
1 #!/usr/bin/perl -w
2 use strict;
3
4 =head HOWTO USE
5
6 When you release a new version ex: 3.0.3
7 - Modify the $version string
8
9 When you add a new category
10 - Add a print_cat() at the end of the script
11
12 To update the downloads.php file
13
14 - Change the version on the top of the file
15 - ./sf2bacula_downloads.pl > downloads.php
16
17 By default, it downloads the sourceforge page in the current directory
18
19
20 You can also use a previous output
21
22 ./sf2bacula_downloads.pl <version> <sf_list_2022.html> > downloads.php
23
24 =cut
25
26 # bacula|depkgs | depkgs-qt
27 my $version = '5.0.1';
28 if ($ARGV[0] and $ARGV[0] =~ /^[\d\.]+$/) {
29 $version = shift(@ARGV);
30 }
31 my $depkgs_version = '18Dec09|28Jul09|15May10';
32
33 my $base = "http://bacula.git.sourceforge.net/git/gitweb.cgi?p=bacula/bacula;a=blob_plain;hb=Release-$version;f=bacula";
34 my $notes = "$base/ReleaseNotes";
35 my $chglog = "$base/ChangeLog";
36 my %cats;
37 my $cur;
38 my %seen;
39
40 my $file = "sf_list_$$.html";
41 my $cmd = "wget -O $file https://sourceforge.net/projects/bacula/files";
42
43 if ($ARGV[0] && -f $ARGV[0]) {
44 $file = $ARGV[0];
45 } else {
46 system($cmd);
47 }
48
49 open(FP, $file);
50 while (my $l = <FP>)
51 {
52 # cat vers file
53 if ($l =~ m!href="(?:http://sourceforge.net)(/projects/bacula/files/([^/]+)/([^/]+)/([^/]+)/download)"!) {
54 print STDERR "$4\n";
55 $cur = {
56 dl => $1,
57 cat => $2,
58 vers => $3,
59 file => $4
60 };
61 }
62
63 # the size, date, and downloads are just after
64 if ($cur && $l =~ m!<td>([\d\.]+ [KMG]B)</td>!) {
65 $cur->{size} = $1;
66 do {
67 $l = <FP>;
68 if ($l =~ m!<td>(\d{4}-\d{2}-\d{2})</td>!) {
69 $cur->{date} = $1;
70 print STDERR " date: $1\n";
71 }
72 } while (!$cur->{date} and !eof(FP));
73 do {
74 $l = <FP>;
75 if ($l =~ m!<td>([\d,]+)</td>!) {
76 $cur->{downloads} = $1;
77 print STDERR " downloads: $1\n";
78 }
79 } while (!exists $cur->{downloads} and !eof(FP));
80
81
82 # once we have a full $cur element, we can store it
83 if (!exists $seen{$cur->{file}}) {
84 push @{$cats{$cur->{cat}}}, $cur;
85 $seen{$cur->{file}} = 1;
86 $cur = undef;
87 }
88 }
89 }
90 close(FP);
91
92 print '
93 <? require_once("inc/header.php"); ?>
94 <? // This page is generated by sf2bacula_downloads.pl in eric s crontab,
95 // no need to update it by hand ?>
96 <table>
97 <tr>
98 <td class="contentTopic">
99 Bacula downloads for version ', $version, '
100 </td>
101 </tr>
102 <tr>
103 <td class="content">
104 <center>
105 <a href="', $notes, '">Release Notes</a>&nbsp;|&nbsp;
106 <a href="', $chglog, '">ChangeLog</a>&nbsp;|&nbsp;
107 <a href="#bacula">Sources</a>&nbsp;|&nbsp;
108 <a href="#Win32_64">Win32/64</a>&nbsp;|&nbsp;
109 <a href="#rpms">RPM</a>&nbsp;|&nbsp;
110 <a href="https://sourceforge.net/projects/bacula/files/Bacula%20Public%20Key/Current%20Public%20Key/bacula.pub/download">Public Key</a>&nbsp;|&nbsp;
111 <a href="https://sourceforge.net/projects/bacula/files/Bacula%20Public%20Key/Current%20Public%20Key/rpmkey-bacula-0.1-3.noarch.rpm/download">RPM Public Key</a>
112 </center>
113 </td>
114 </tr>
115 ';
116
117 my $cat = 'bacula';
118 #use Data::Dumper;
119 #print Data::Dumper::Dumper(\%cats);
120
121 sub print_cat
122 {
123 my ($cat) = @_;
124 my $row = 'odd';
125
126 print '
127 <tr>
128 <td> <br><a name="', $cat, '"></a><font size="+1"><b>', $cat, ':</b></font>
129 <table cellspacing="2">
130 <tr class="title"><th>Name</th><th align="center">', ($cat !~ /rpm/)?'Signature':'', '</th><th>Size</th><th>Date</th><th>Downloads</th></tr>
131 ';
132 foreach my $elt ( sort { $a->{file} cmp $b->{file} } @{$cats{$cat}})
133 {
134 next if ($elt->{file} =~ /\.sig/); # we skip signature file
135 if ($elt->{vers} eq $version || $elt->{vers} =~ /$depkgs_version/)
136 {
137 print "
138 <tr class=\"$row\">
139 <td><a href='https://sourceforge.net$elt->{dl}'>$elt->{file}</td>
140 <td align=\"center\">",
141 ($cat !~ /rpm/)?"<a href='https://sourceforge.net/projects/bacula/files/$cat/$elt->{vers}/$elt->{file}.sig/download'>sig":"",
142 "</td>
143 <td align=\"right\">$elt->{size}</td>
144 <td align=\"center\">$elt->{date}</td>
145 <td align=\"center\">$elt->{downloads}</td>
146 </tr>
147 ";
148 if ($row eq 'odd') { $row = 'even'; } else { $row = 'odd'; }
149 }
150 }
151 print '</table>
152 </td>
153 </tr>';
154 }
155
156 print_cat('bacula');
157 print_cat('Win32_64');
158 print_cat('rpms');
159 print_cat('rpms-contrib-fschwarz');
160 print_cat('rpms-contrib-psheaffer');
161 print_cat('depkgs');
162 print_cat('depkgs-qt');
163
164
165 print '
166 </table>
167 <small>', scalar(localtime), '</small>
168 <? require_once("inc/footer.php"); ?>
169 ';