From c7f0d053c8b56dff6e0abf0157b34371db910b83 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Wed, 18 Mar 2015 16:54:58 +0000 Subject: add required by and subpkg to package list --- aports.lua | 71 +++++++++++++++++++++++++++++++++++++++++++++----------- assets/style.css | 12 ++++------ tpl/package.tpl | 28 ++++++++++++++++++++++ 3 files changed, 91 insertions(+), 20 deletions(-) diff --git a/aports.lua b/aports.lua index c291f92..cd16817 100755 --- a/aports.lua +++ b/aports.lua @@ -57,22 +57,20 @@ end local PackageRenderer = class("PackageRenderer", turbo.web.RequestHandler) -function PackageRenderer:get(arch, pkgname) - local fields = {} - local table = {} - fields.arch = arch - fields.pkgname = pkgname - local result = QueryPackage(fields) - -- check for empty values and destroy them - if result ~= nil then - table = result +function PackageRenderer:get(arch, name) + local table = QueryPackage(name, arch) + if table ~= nil then table.deps = QueryDeps(table.deps) + table.reqbys = QueryRequiredBy(table.provides) + table.subpkgs = QuerySubPackages(table.origin, table.name) table.maintainer = string.gsub(table.maintainer, '<.*>', '') for k in pairs (table) do if table[k] == "" then table[k] = nil end end + else + table = {} end table.header = tpl:render("header.tpl") table.footer = tpl:render("footer.tpl") @@ -94,6 +92,7 @@ function QueryContents(terms) arch = row.arch, } end + sth:close() return r end @@ -116,16 +115,17 @@ function QueryPackages(terms) bdate = row.build_time } end + sth:close() return r end -function QueryPackage(fields) +function QueryPackage(name, arch) require('DBI') local dbh = assert(DBI.Connect('SQLite3', 'db/apkindex.db')) local sth = assert(dbh:prepare('select *, datetime(build_time, \'unixepoch\') as build_time from apkindex where name like ? and arch like ? limit 1')) - sth:execute(fields.pkgname, fields.arch) - local r = {} - r = sth:fetch(true) + sth:execute(name, arch) + local r = sth:fetch(true) + sth:close() return r end @@ -145,6 +145,7 @@ function QueryDeps(deps) names[k] = k end end + sth:close() local r = {} for _,name in pairs (names) do r[#r+1] = {dep=name} @@ -154,6 +155,50 @@ function QueryDeps(deps) end end +function QueryRequiredBy(provides) + require('DBI') + local names = {} + local dbh = assert(DBI.Connect('SQLite3', 'db/apkindex.db')) + local sth = assert(dbh:prepare('select name from apkindex where deps like ?')) + for _,d in pairs (provides:split(" ")) do + if d:begins('so:') then + d = string.gsub(d, '=.*', '') + sth:execute("%"..d.."%") + for row in sth:rows(true) do + if row ~= nil then + names[row.name] = row.name + end + end + end + end + sth:close() + local r = {} + for _,name in pairs (names) do + r[#r+1] = {reqby=name} + end + if next(r) ~= nil then + return r + end +end + +function QuerySubPackages(origin, name) + require('DBI') + local names = {} + local dbh = assert(DBI.Connect('SQLite3', 'db/apkindex.db')) + local sth = assert(dbh:prepare('select name from apkindex where origin like ?')) + sth:execute(origin) + local r = {} + for row in sth:rows(true) do + if row.name ~= name then + r[#r+1] = {subpkg=row.name} + end + end + sth:close() + if next(r) ~= nil then + return r + end +end + turbo.web.Application({ {"^/$", turbo.web.RedirectHandler, "/packages"}, {"^/contents$", ContentsRenderer, "contents.tpl"}, diff --git a/assets/style.css b/assets/style.css index 680bc13..d72cda3 100644 --- a/assets/style.css +++ b/assets/style.css @@ -70,14 +70,12 @@ nav a.active { /* icons on deps toggle */ .panel-heading .accordion-toggle:after { - /* symbol for "opening" panels */ - font-family: 'Glyphicons Halflings'; /* essential for enabling glyphicon */ - content: "\e114"; /* adjust as needed, taken from bootstrap.css */ - float: right; /* adjust as needed */ - color: grey; /* adjust as needed */ + font-family: 'Glyphicons Halflings'; + content: "\e114"; + float: right; + color: grey; } .panel-heading .accordion-toggle.collapsed:after { - /* symbol for "collapsed" panels */ - content: "\e080"; /* adjust as needed, taken from bootstrap.css */ + content: "\e080"; } diff --git a/tpl/package.tpl b/tpl/package.tpl index 145a3ab..bd9d240 100644 --- a/tpl/package.tpl +++ b/tpl/package.tpl @@ -69,6 +69,10 @@ Commit: {{{commit}}} + + + Contents: + Contents of package {{/name}}{{^name}} This package does not exist! @@ -89,6 +93,30 @@ +
+
+ +
+
    {{#reqbys}} +
  • {{{reqby}}}
  • {{/reqbys}}{{^reqbys}}
  • None
  • {{/reqbys}} +
+
+
+
+
+
+ +
+
    {{#subpkgs}} +
  • {{{subpkg}}}
  • {{/subpkgs}}{{^subpkgs}}
  • None
  • {{/subpkgs}} +
+
+
+
-- cgit v1.2.3