From 607080b9b771dc8503780a40fa1346f1f8b4dca9 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Tue, 17 Mar 2015 09:43:40 +0000 Subject: cleanup ident --- aports.lua | 113 +++++++++++++++++++++++++++---------------------------- tpl/contents.tpl | 18 ++++----- tpl/footer.tpl | 4 +- tpl/header.tpl | 4 +- tpl/package.tpl | 88 +++++++++++++++++++++---------------------- tpl/packages.tpl | 60 ++++++++++++++--------------- 6 files changed, 143 insertions(+), 144 deletions(-) diff --git a/aports.lua b/aports.lua index 7a3a7d9..ad9862d 100755 --- a/aports.lua +++ b/aports.lua @@ -10,87 +10,86 @@ local tpl = turbo.web.Mustache.TemplateHelper("./tpl") local ContentsRenderer = class("ContentsRenderer", turbo.web.RequestHandler) function ContentsRenderer:get() - local table = {} + local table = {} local args = { filename = self:get_argument("filename","", true), arch = self:get_argument("arch", "x86", true), } - if args.filename ~= "" then + if args.filename ~= "" then local result = QueryContents(args) if next(result) ~= nil then table.rows = result end end table.contents = true - table.filename = args.filename - table.header = tpl:render("header.tpl", table) + table.filename = args.filename + table.header = tpl:render("header.tpl", table) table.footer = tpl:render("footer.tpl", table) - local page = tpl:render(self.options, table) - self:write(page) + local page = tpl:render(self.options, table) + self:write(page) end local PackagesRenderer = class("PackagesRenderer", turbo.web.RequestHandler) function PackagesRenderer:get() - local table = {} + local table = {} local args = { package = self:get_argument("package","", true) } - if args.package == "" then - args.package = "%" - end - local result = QueryPackages(args) - if next(result) ~= nil then - table.rows = result - end + if args.package == "" then + args.package = "%" + end + local result = QueryPackages(args) + if next(result) ~= nil then + table.rows = result + end table.packages = true - table.header = tpl:render("header.tpl", table) - table.footer = tpl:render("footer.tpl", table) - local page = tpl:render(self.options, table) - self:write(page) + table.header = tpl:render("header.tpl", table) + table.footer = tpl:render("footer.tpl", table) + local page = tpl:render(self.options, table) + self:write(page) print(inspect(table)) end local PackageRenderer = class("PackageRenderer", turbo.web.RequestHandler) function PackageRenderer:get(arch, pkgname) - local fields = {} - local table = {} - fields.arch = arch - fields.pkgname = pkgname - result = QueryPackage(fields) - - if result ~= nil then - table = result - for k in pairs (table) do + local fields = {} + local table = {} + fields.arch = arch + fields.pkgname = pkgname + result = QueryPackage(fields) + if result ~= nil then + table = result + for k in pairs (table) do if table[k] == "" then table[k] = nil end end - end - table.header = tpl:render("header.tpl") - table.footer = tpl:render("footer.tpl") - local page = tpl:render(self.options, table) - self:write(page) + end + table.header = tpl:render("header.tpl") + table.footer = tpl:render("footer.tpl") + local page = tpl:render(self.options, table) + self:write(page) end function QueryContents(terms) - require('DBI') - local dbh = assert(DBI.Connect('SQLite3', 'db/filelist.db')) - local sth = assert(dbh:prepare('select * from filelist where file like ? and arch like ? limit 100')) - sth:execute(terms.filename, terms.arch) - local r = {} - for row in sth:rows(true) do - r[#r + 1] = { - file = "/" .. row.path .. "/" .. row.file, - pkgname = row.pkgname, - repo = row.repo, - arch = row.arch, - } - end - return r - + require('DBI') + local dbh = assert(DBI.Connect('SQLite3', 'db/filelist.db')) + local sth = assert(dbh:prepare('select * from filelist where file like ? and arch like ? limit 100')) + sth:execute(terms.filename, terms.arch) + local r = {} + for row in sth:rows(true) do + r[#r + 1] = { + file = "/" .. row.path .. "/" .. row.file, + pkgname = row.pkgname, + repo = row.repo, + arch = row.arch, + } + end + return r end + function QueryPackages(terms) require('DBI') local dbh = assert(DBI.Connect('SQLite3', 'db/apkindex.db')) @@ -114,21 +113,21 @@ function QueryPackages(terms) end function QueryPackage(fields) - require('DBI') - local dbh = assert(DBI.Connect('SQLite3', 'db/apkindex.db')) + 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(fields.pkgname, fields.arch) + local r = {} + r = sth:fetch(true) print(inspect(r)) - return r + return r end turbo.web.Application({ - {"^/$", turbo.web.RedirectHandler, "/packages"}, - {"^/contents$", ContentsRenderer, "contents.tpl"}, + {"^/$", turbo.web.RedirectHandler, "/packages"}, + {"^/contents$", ContentsRenderer, "contents.tpl"}, {"^/packages$", PackagesRenderer, "packages.tpl"}, - {"^/package/(.*)/(.*)$", PackageRenderer, "package.tpl"}, - {"/assets/(.*)$", turbo.web.StaticFileHandler, "assets/"}, + {"^/package/(.*)/(.*)$", PackageRenderer, "package.tpl"}, + {"/assets/(.*)$", turbo.web.StaticFileHandler, "assets/"}, }):listen(8888) turbo.ioloop.instance():start() diff --git a/tpl/contents.tpl b/tpl/contents.tpl index dc4fe92..f3084d8 100644 --- a/tpl/contents.tpl +++ b/tpl/contents.tpl @@ -8,14 +8,14 @@ -
+
- -
+
@@ -23,15 +23,15 @@ - - - + + + {{#rows}} - - - + + + {{/rows}} {{{^rows}}} diff --git a/tpl/footer.tpl b/tpl/footer.tpl index 60e689e..2d29c22 100644 --- a/tpl/footer.tpl +++ b/tpl/footer.tpl @@ -1,3 +1,3 @@ - - + + diff --git a/tpl/header.tpl b/tpl/header.tpl index fdfdb67..072aff9 100644 --- a/tpl/header.tpl +++ b/tpl/header.tpl @@ -25,14 +25,14 @@
FilePackage nameRepositoryArchitecturePackage nameRepositoryArchitecture
{{{file}}}{{{pkgname}}}{{{repo}}}{{{arch}}}{{{pkgname}}}{{{repo}}}{{{arch}}}
- {{#name}} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
Name{{{name}}}
Version{{{version}}}
ProjectURL
Licence{{{lic}}}
Architecture{{{arch}}}
RepositoryRepository
Maintainer{{{maintainer}}}
Build date{{{build_time}}}
+ {{#name}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{#install_if}} - - - + + + {{/install_if}} - {{/name}} - {{^name}} - - - - {{/name}} -
Name{{{name}}}
Version{{{version}}}
ProjectURL
Licence{{{lic}}}
Architecture{{{arch}}}
RepositoryRepository
Maintainer{{{maintainer}}}
Build date{{{build_time}}}
Install if{{{install_if}}}
Install if{{{install_if}}}
This package does not exist!
+ {{/name}} + {{^name}} + + This package does not exist! + + {{/name}} + {{{footer}}} diff --git a/tpl/packages.tpl b/tpl/packages.tpl index 9027858..4008ff0 100644 --- a/tpl/packages.tpl +++ b/tpl/packages.tpl @@ -8,44 +8,44 @@ -
+
- -
+
- - - - - - - - - - - {{#rows}} - - - - - - - - - - {{/rows}} - {{{^rows}}} - - - - {{{/rows}}} -
PackageVersionProjectLicenceArchitectureRepositoryMaintainerBuild date
{{{package}}}{{{version}}}URL{{{license}}}{{{arch}}}{{{repo}}}{{{maintainer}}}{{{bdate}}}
No item found...
+ + + + + + + + + + + {{#rows}} + + + + + + + + + + {{/rows}} + {{{^rows}}} + + + + {{{/rows}}} +
PackageVersionProjectLicenceArchitectureRepositoryMaintainerBuild date
{{{package}}}{{{version}}}URL{{{license}}}{{{arch}}}{{{repo}}}{{{maintainer}}}{{{bdate}}}
No item found...
{{{footer}}} -- cgit v1.2.3