Add viewer for reverse dependency list
This commit is contained in:
parent
8dd0170015
commit
5fb096f31a
@ -13,6 +13,11 @@ use Mojo::SQLite;
|
|||||||
use HTML::Escape qw/escape_html/;
|
use HTML::Escape qw/escape_html/;
|
||||||
|
|
||||||
my $dbFile = "combined.db";
|
my $dbFile = "combined.db";
|
||||||
|
my $sqlPortsFile = "/usr/local/share/sqlports";
|
||||||
|
|
||||||
|
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
|
||||||
|
localtime();
|
||||||
|
$year = $year + 1900;
|
||||||
|
|
||||||
if ( $^O eq "openbsd" ) {
|
if ( $^O eq "openbsd" ) {
|
||||||
require OpenBSD::Pledge;
|
require OpenBSD::Pledge;
|
||||||
@ -26,6 +31,9 @@ if ( $^O eq "openbsd" ) {
|
|||||||
OpenBSD::Pledge::pledge(qw(stdio dns inet rpath proc flock wpath cpath))
|
OpenBSD::Pledge::pledge(qw(stdio dns inet rpath proc flock wpath cpath))
|
||||||
or die;
|
or die;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$sqlPortsFile = "/tmp/openbsd_app/stable/share/sqlports";
|
||||||
|
}
|
||||||
|
|
||||||
my $mtime = ( stat($dbFile) )[9];
|
my $mtime = ( stat($dbFile) )[9];
|
||||||
$mtime = scalar localtime $mtime;
|
$mtime = scalar localtime $mtime;
|
||||||
@ -44,8 +52,7 @@ helper sqlite => sub {
|
|||||||
|
|
||||||
helper sqlports => sub {
|
helper sqlports => sub {
|
||||||
state $sql = Mojo::SQLite->new;
|
state $sql = Mojo::SQLite->new;
|
||||||
$sql->from_filename( "/usr/local/share/sqlports",
|
$sql->from_filename( $sqlPortsFile, { ReadOnly => 1, no_wal => 1 } );
|
||||||
{ ReadOnly => 1, no_wal => 1 } );
|
|
||||||
$sql->on(
|
$sql->on(
|
||||||
connection => sub {
|
connection => sub {
|
||||||
my ( $sql, $dbh ) = @_;
|
my ( $sql, $dbh ) = @_;
|
||||||
@ -85,6 +92,25 @@ my $depsQuery = q{
|
|||||||
SELECT substr('..........',1,level*3) || name FROM under_port;
|
SELECT substr('..........',1,level*3) || name FROM under_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
my $reverseQuery = q{
|
||||||
|
WITH RECURSIVE d (fullpkgpath, dependspath, type) as
|
||||||
|
(select root.fullpkgpath, root.dependspath, root.type
|
||||||
|
from _canonical_depends root
|
||||||
|
join _paths
|
||||||
|
on root.dependspath=_paths.canonical
|
||||||
|
join _paths p2
|
||||||
|
on p2.fullpkgpath = ? and p2.id=_paths.pkgpath
|
||||||
|
where root.type!=3
|
||||||
|
union
|
||||||
|
select child.fullpkgpath, child.dependspath, child.type
|
||||||
|
from d parent, _canonical_depends child
|
||||||
|
where parent.fullpkgpath=child.dependspath and child.type!=3)
|
||||||
|
select distinct _paths.fullpkgpath from d
|
||||||
|
join _paths
|
||||||
|
on _paths.id=d.fullpkgpath
|
||||||
|
order by _paths.fullpkgpath;
|
||||||
|
};
|
||||||
|
|
||||||
my $title = "OpenBSD.app";
|
my $title = "OpenBSD.app";
|
||||||
my $descr = "OpenBSD package search";
|
my $descr = "OpenBSD package search";
|
||||||
|
|
||||||
@ -119,18 +145,43 @@ sub fix_fts ($s) {
|
|||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get '/reverse' => sub ($c) {
|
||||||
|
my $v = $c->validation;
|
||||||
|
|
||||||
|
$c->stash( title => $title );
|
||||||
|
$c->stash( descr => $descr );
|
||||||
|
$c->stash( mtime => $mtime );
|
||||||
|
$c->stash( year => (localtime)[5] + 1900 );
|
||||||
|
|
||||||
|
my $search = $c->param('name');
|
||||||
|
my $raw = $c->param('raw');
|
||||||
|
my $db = $c->sqlports->db;
|
||||||
|
|
||||||
|
if ( defined $raw && $raw ne "" ) {
|
||||||
|
$c->render( text => $db->query( $reverseQuery, $search )->text );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$c->render(
|
||||||
|
template => 'reverse',
|
||||||
|
name => $search,
|
||||||
|
list => $db->query( $reverseQuery, $search )->text
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
get '/tree' => sub ($c) {
|
get '/tree' => sub ($c) {
|
||||||
my $v = $c->validation;
|
my $v = $c->validation;
|
||||||
|
|
||||||
$c->stash( title => $title );
|
$c->stash( title => $title );
|
||||||
$c->stash( descr => $descr );
|
$c->stash( descr => $descr );
|
||||||
$c->stash( mtime => $mtime );
|
$c->stash( mtime => $mtime );
|
||||||
|
$c->stash( year => (localtime)[5] + 1900 );
|
||||||
|
|
||||||
my $search = $c->param('name');
|
my $search = $c->param('name');
|
||||||
my $raw = $c->param('raw');
|
my $raw = $c->param('raw');
|
||||||
my $db = $c->sqlports->db;
|
my $db = $c->sqlports->db;
|
||||||
|
|
||||||
if ( $raw ne "" ) {
|
if ( defined $raw && $raw ne "" ) {
|
||||||
$c->render( text => $db->query( $depsQuery, $search )->text );
|
$c->render( text => $db->query( $depsQuery, $search )->text );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -272,6 +323,15 @@ __DATA__
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ reverse.html.ep
|
||||||
|
% layout 'default';
|
||||||
|
<div>
|
||||||
|
<h3>Reverse dependency list for: <%= $name %></h3>
|
||||||
|
<p>
|
||||||
|
<pre><%= $list %></pre>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ results.html.ep
|
@@ results.html.ep
|
||||||
% layout 'default';
|
% layout 'default';
|
||||||
<p>
|
<p>
|
||||||
@ -307,6 +367,11 @@ __DATA__
|
|||||||
title="Dependencies for <%= $result->{FULLPKGNAME} %>"
|
title="Dependencies for <%= $result->{FULLPKGNAME} %>"
|
||||||
>Dep Tree</a>
|
>Dep Tree</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="/reverse?name=<%= $result->{FULLPKGPATH} %>"
|
||||||
|
title="Reverse dependencies for <%= $result->{FULLPKGNAME} %>"
|
||||||
|
>Reverse Dep List</a>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
href="https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/<%= $result->{FULLPKGPATH} %>"
|
href="https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/<%= $result->{FULLPKGPATH} %>"
|
||||||
|
Loading…
Reference in New Issue
Block a user