|
| 1 | +#! /usr/bin/perl |
| 2 | +# ex:ts=8 sw=4: |
| 3 | +# $OpenBSD: make-readmes,v 1.4 2012/06/01 13:21:26 espie Exp $ |
| 4 | +# |
| 5 | +# Copyright (c) 2012 Marc Espie <espie@openbsd.org> |
| 6 | +# |
| 7 | +# Permission to use, copy, modify, and distribute this software for any |
| 8 | +# purpose with or without fee is hereby granted, provided that the above |
| 9 | +# copyright notice and this permission notice appear in all copies. |
| 10 | +# |
| 11 | +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 12 | +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 13 | +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 14 | +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 15 | +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 16 | +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 17 | +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 18 | + |
| 19 | +use strict; |
| 20 | +use warnings; |
| 21 | +use DBI; |
| 22 | +use Template; |
| 23 | +use File::Path qw(make_path); |
| 24 | +use File::Basename; |
| 25 | +use File::Spec; |
| 26 | +use Data::Dumper; |
| 27 | + |
| 28 | +sub relative_url |
| 29 | +{ |
| 30 | + my ($a, $b) = @_; |
| 31 | + $a .= ".html"; |
| 32 | + $b .= ".html"; |
| 33 | + return File::Spec->abs2rel($a, dirname($b)); |
| 34 | +} |
| 35 | + |
| 36 | +my $db = DBI->connect("dbi:SQLite:dbname=$ENV{DATABASE}", '', '', {}); |
| 37 | + |
| 38 | +my $outputdir = $ENV{OUTPUTDIR}; |
| 39 | +my $template = Template->new( |
| 40 | + { |
| 41 | + INCLUDE_PATH => $ENV{TEMPLATESDIR}, |
| 42 | + OUTPUT_PATH => $outputdir, |
| 43 | + }); |
| 44 | + |
| 45 | + |
| 46 | +my $info_req = $db->prepare( |
| 47 | + qq{select |
| 48 | + paths.id, |
| 49 | + paths.fullpkgpath, |
| 50 | + ports.comment, |
| 51 | + ports.homepage, |
| 52 | + descr.value, |
| 53 | + fullpkgname, |
| 54 | + permit_cd.value, |
| 55 | + permit_ftp.value |
| 56 | + from paths |
| 57 | + join Ports on paths.id=Ports.fullpkgpath |
| 58 | + left join Descr on paths.id=Descr.fullpkgpath |
| 59 | + join keywords2 permit_cd |
| 60 | + on ports.permit_package_cdrom=permit_cd.keyref |
| 61 | + join keywords2 permit_ftp |
| 62 | + on ports.permit_package_ftp=permit_ftp.keyref |
| 63 | + order by paths.fullpkgpath}); |
| 64 | +my ($id, $path, $comment, $homepage, $descr, $fullpkgname, $permit_cd, $permit_ftp); |
| 65 | +$info_req->bind_columns(\($id, $path, $comment, $homepage, $descr, $fullpkgname, $permit_cd, $permit_ftp)); |
| 66 | + |
| 67 | +my $dep_req = $db->prepare( |
| 68 | + q{select |
| 69 | + depends.type, |
| 70 | + depends.fulldepends, |
| 71 | + t2.fullpkgpath |
| 72 | + from depends |
| 73 | + join paths on depends.dependspath=paths.id |
| 74 | + join paths t2 on paths.canonical=t2.id |
| 75 | + where depends.fullpkgpath=? |
| 76 | + order by depends.fulldepends |
| 77 | + }); |
| 78 | +my ($type, $fulldepends, $dependspath); |
| 79 | +$dep_req->bind_columns(\($type, $fulldepends, $dependspath)); |
| 80 | +my $multi_req = $db->prepare( |
| 81 | + q{select |
| 82 | + ports.fullpkgname, |
| 83 | + t2.fullpkgpath |
| 84 | + from multi |
| 85 | + join paths on multi.subpkgpath=paths.id |
| 86 | + join paths t2 on paths.canonical=t2.id |
| 87 | + join ports on paths.canonical=ports.fullpkgpath |
| 88 | + where multi.fullpkgpath=? |
| 89 | + }); |
| 90 | +my ($multi, $subpath); |
| 91 | +$multi_req->bind_columns(\($multi, $subpath)); |
| 92 | +my $only_for = $db->prepare( |
| 93 | + q{select |
| 94 | + Arch.value |
| 95 | + from OnlyForArch |
| 96 | + join Arch on arch.keyref=OnlyForArch.value |
| 97 | + where OnlyForArch.fullpkgpath=? |
| 98 | + order by Arch.value |
| 99 | + }); |
| 100 | +my $arch; |
| 101 | +$only_for->bind_columns(\($arch)); |
| 102 | +my $not_for = $db->prepare( |
| 103 | + q{select |
| 104 | + Arch.value |
| 105 | + from NotforArch |
| 106 | + join Arch on arch.keyref=NotForArch.value |
| 107 | + where NotForArch.fullpkgpath=? |
| 108 | + order by Arch.value |
| 109 | + }); |
| 110 | +$not_for->bind_columns(\($arch)); |
| 111 | + |
| 112 | +my $category; |
| 113 | +my $cat_req = $db->prepare( |
| 114 | + q{select |
| 115 | + categorykeys.value |
| 116 | + from categories |
| 117 | + join categorykeys on categorykeys.keyref=categories.value |
| 118 | + where categories.fullpkgpath=? |
| 119 | + order by categorykeys.value |
| 120 | + }); |
| 121 | +$cat_req->bind_columns(\($category)); |
| 122 | + |
| 123 | +my $broken_req = $db->prepare( |
| 124 | + q{select |
| 125 | + arch.value, |
| 126 | + broken.value |
| 127 | + from broken |
| 128 | + left join arch on arch.keyref=broken.arch |
| 129 | + where fullpkgpath=? |
| 130 | + order by arch.value}); |
| 131 | + |
| 132 | +my $broken; |
| 133 | +$broken_req->bind_columns(\($arch, $broken)); |
| 134 | + |
| 135 | +my $cat = {}; |
| 136 | + |
| 137 | +my @depends = (qw(libdepends rundepends builddepends regressdepends)); |
| 138 | + |
| 139 | +$info_req->execute; |
| 140 | +while ($info_req->fetch) { |
| 141 | + print "+++$path\n"; |
| 142 | + my $e = { path => $path, |
| 143 | + comment => $comment, |
| 144 | + homepage => $homepage, |
| 145 | + descr => $descr, |
| 146 | + fullpkgname => $fullpkgname }; |
| 147 | + unless ($permit_cd =~ /yes/i) { |
| 148 | + $e->{permit_cd} = $permit_cd; |
| 149 | + } |
| 150 | + unless ($permit_ftp =~ /yes/i) { |
| 151 | + $e->{permit_ftp} = $permit_ftp; |
| 152 | + } |
| 153 | + $dep_req->execute($id); |
| 154 | + while ($dep_req->fetch) { |
| 155 | + push(@{$e->{$depends[$type]}}, |
| 156 | + { |
| 157 | + depends => $fulldepends, |
| 158 | + url => relative_url($dependspath, $e->{path}) |
| 159 | + }); |
| 160 | + } |
| 161 | + |
| 162 | + $broken_req->execute($id); |
| 163 | + while ($broken_req->fetch) { |
| 164 | + push (@{$e->{broken}}, |
| 165 | + { |
| 166 | + arch => $arch, |
| 167 | + text => $broken |
| 168 | + }); |
| 169 | + } |
| 170 | + $only_for->execute($id); |
| 171 | + while ($only_for->fetch) { |
| 172 | + push (@{$e->{only_for}}, $arch); |
| 173 | + } |
| 174 | + $not_for->execute($id); |
| 175 | + while ($not_for->fetch) { |
| 176 | + push (@{$e->{not_for}}, $arch); |
| 177 | + } |
| 178 | + $multi_req->execute($id); |
| 179 | + while ($multi_req->fetch) { |
| 180 | + push @{$e->{multi}}, |
| 181 | + { |
| 182 | + name => $multi, |
| 183 | + url => relative_url($subpath, $e->{path}) |
| 184 | + }; |
| 185 | + } |
| 186 | + |
| 187 | + $cat_req->execute($id); |
| 188 | + while ($cat_req->fetch) { |
| 189 | + push @{$e->{category}}, |
| 190 | + { |
| 191 | + name => $category, |
| 192 | + url => relative_url($category, $e->{path}) |
| 193 | + }; |
| 194 | + $cat->{$category}{$e->{fullpkgname}} = $e->{path}; |
| 195 | + } |
| 196 | + $template->process('port.tt2', $e, "$e->{path}.html") or die; |
| 197 | +} |
| 198 | + |
| 199 | +print "Generating category indexes\n"; |
| 200 | +while (my ($c, $h) = each %$cat) { |
| 201 | + my $e = { category => $c}; |
| 202 | + for my $pkgname (sort keys %$h) { |
| 203 | + my $p = $h->{$pkgname}; |
| 204 | + push @{$e->{ports}}, |
| 205 | + { |
| 206 | + name => $pkgname, |
| 207 | + url => relative_url($p, $c) |
| 208 | + }; |
| 209 | + } |
| 210 | + $template->process('category.tt2', $e, "$c.html") or die; |
| 211 | +} |
| 212 | + |
| 213 | +print "Generating main index\n"; |
| 214 | +my $e = {}; |
| 215 | +for my $c (sort keys %$cat) { |
| 216 | + push @{$e->{categories}}, |
| 217 | + { |
| 218 | + name => $c, |
| 219 | + url => "$c.html" |
| 220 | + }; |
| 221 | +} |
| 222 | +$template->process('main.tt2', $e, "index.html") or die; |
0 commit comments