diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2014-07-09 13:08:11 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2014-07-09 13:08:11 +0000 |
commit | 35fc117ae46a403d4051ef7891819b5c1431132e (patch) | |
tree | d9cf78558a0e45512cc868665f344e2e8e721170 | |
parent | 2a47f6b4c38027b27da55374cfbf0f586c5ac018 (diff) | |
download | upstream-monitor-35fc117ae46a403d4051ef7891819b5c1431132e.tar.bz2 upstream-monitor-35fc117ae46a403d4051ef7891819b5c1431132e.tar.xz |
gnome: refactor the api to be more generic
-rwxr-xr-x | aports-vercmp | 8 | ||||
-rw-r--r-- | upstream/gnome.lua | 33 |
2 files changed, 26 insertions, 15 deletions
diff --git a/aports-vercmp b/aports-vercmp index 511f59a..8fdd91f 100755 --- a/aports-vercmp +++ b/aports-vercmp @@ -11,10 +11,10 @@ io.stderr:write("Reading aports...\n") db = require("aports.db").new("~/aports", "main") for p in db:each_aport() do - local gname = gnome.is_gnome_source(p) - if gname then - newver = gnome.find_newer(gname, p.pkgver) - upstream = "gnome" + local upstream_pkg = gnome.init(p) + if upstream_pkg then + newver = upstream_pkg:find_newer() + upstream = upstream_pkg.provider_name else newver = archlinux:find_newer(p.pkgname, p.pkgver) upstream = "archlinux" diff --git a/upstream/gnome.lua b/upstream/gnome.lua index dd02fac..bf9a153 100644 --- a/upstream/gnome.lua +++ b/upstream/gnome.lua @@ -2,18 +2,19 @@ http = require("socket.http") json = require("cjson") -ml = require("ml") apk = require("apk") -local gnome = {} -function gnome.find_newer(upkgname, oldver) - print("DEBUG: searching:", upkgname) +local M = {} + +local function find_newer(self) + local oldver = self.pkg.pkgver + print("DEBUG: searching:", self.gnome_name) local baseurl = "http://ftp.gnome.org/pub/GNOME/sources/" - local jsonurl = baseurl..upkgname.."/cache.json" + local jsonurl = baseurl..self.gnome_name.."/cache.json" local jsondata = assert(http.request(jsonurl)) local n,t = unpack(json.decode(jsondata)) local latest = oldver or "0" - for k,v in pairs(t[upkgname]) do + for k,v in pairs(t[self.gnome_name]) do if apk.version_compare(k, latest) == ">" then latest = k end @@ -24,16 +25,26 @@ function gnome.find_newer(upkgname, oldver) return latest end +function M.init(pkg) + local provider = { + provider_name = "gnome", + pkg = pkg, + } -function gnome.is_gnome_source(pkg) for source in pkg:remote_sources() do - local gnomename = string.match(source, "GNOME/sources/([^/]+)/") or - string.match(source, "download.gnome.org/sources/([^/]+)/") + local gnomename = string.match(source, "GNOME/sources/([^/]+)/") + or string.match(source, + "download.gnome.org/sources/([^/]+)/") if gnomename then - return gnomename + return { + gnome_name = gnomename, + provider_name = "gnome", + find_newer = find_newer, + pkg = pkg + } end end return nil end -return gnome +return M |