2017-04-15 12:45:56 +00:00
|
|
|
--[[--
|
|
|
|
This module helps with retrieving version information.
|
|
|
|
]]
|
|
|
|
|
|
|
|
local Version = {}
|
|
|
|
|
|
|
|
--- Returns current KOReader git-rev.
|
2018-07-03 21:16:45 +00:00
|
|
|
-- @treturn string full KOReader git-rev such as `v2015.11-982-g704d4238`
|
2017-04-15 12:45:56 +00:00
|
|
|
function Version:getCurrentRevision()
|
|
|
|
if not self.rev then
|
|
|
|
local rev_file = io.open("git-rev", "r")
|
|
|
|
if rev_file then
|
2021-01-16 03:41:46 +00:00
|
|
|
self.rev = rev_file:read("*line")
|
2017-04-15 12:45:56 +00:00
|
|
|
rev_file:close()
|
|
|
|
end
|
|
|
|
-- sanity check in case `git describe` failed
|
|
|
|
if self.rev == "fatal: No names found, cannot describe anything." then
|
|
|
|
self.rev = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self.rev
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Returns normalized version of KOReader git-rev input string.
|
2018-07-03 21:16:45 +00:00
|
|
|
-- @string rev full KOReader git-rev such as `v2015.11-982-g704d4238`
|
|
|
|
-- @treturn int version in the form of a 10 digit number such as `2015110982`
|
2017-04-15 12:45:56 +00:00
|
|
|
-- @treturn string short git commit version hash such as `704d4238`
|
|
|
|
function Version:getNormalizedVersion(rev)
|
|
|
|
if not rev then return end
|
2018-11-05 20:21:20 +00:00
|
|
|
local year, month, point, revision = rev:match("v(%d%d%d%d)%.(%d%d)%.?(%d?%d?)-?(%d*)")
|
2018-11-01 10:41:31 +00:00
|
|
|
|
2018-11-01 10:54:29 +00:00
|
|
|
year = tonumber(year)
|
|
|
|
month = tonumber(month)
|
2018-11-05 20:21:20 +00:00
|
|
|
point = tonumber(point)
|
2018-11-01 10:54:29 +00:00
|
|
|
revision = tonumber(revision)
|
2018-11-01 10:41:31 +00:00
|
|
|
|
2018-07-03 21:16:45 +00:00
|
|
|
local commit = rev:match("-%d*-g(%x*)[%d_%-]*")
|
|
|
|
-- NOTE: * 10000 to handle at most 9999 commits since last tag ;).
|
2018-11-05 20:21:20 +00:00
|
|
|
return ((year or 0) * 100 + (month or 0)) * 1000000 + (point or 0) * 10000 + (revision or 0), commit
|
2017-04-15 12:45:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Returns current version of KOReader.
|
2018-07-03 21:16:45 +00:00
|
|
|
-- @treturn int version in the form of a 10 digit number such as `2015110982`
|
2017-04-15 12:45:56 +00:00
|
|
|
-- @treturn string short git commit version hash such as `704d4238`
|
2019-06-09 13:50:22 +00:00
|
|
|
-- @see getNormalizedVersion
|
2017-04-15 12:45:56 +00:00
|
|
|
function Version:getNormalizedCurrentVersion()
|
|
|
|
if not self.version or not self.commit then
|
|
|
|
self.version, self.commit = self:getNormalizedVersion(self:getCurrentRevision())
|
|
|
|
end
|
|
|
|
return self.version, self.commit
|
|
|
|
end
|
|
|
|
|
2020-08-29 03:20:28 +00:00
|
|
|
--- Returns current version of KOReader, in short form.
|
|
|
|
-- @treturn string version, without the git details (i.e., at most YYYY.MM.P-R)
|
|
|
|
function Version:getShortVersion()
|
|
|
|
if not self.short then
|
|
|
|
local rev = self:getCurrentRevision()
|
|
|
|
local year, month, point, revision = rev:match("v(%d%d%d%d)%.(%d%d)%.?(%d?%d?)-?(%d*)")
|
|
|
|
self.short = year .. "." .. month
|
2020-09-21 19:40:48 +00:00
|
|
|
if point and point ~= "" then
|
2020-08-29 03:20:28 +00:00
|
|
|
self.short = self.short .. "." .. point
|
|
|
|
end
|
2020-09-21 19:40:48 +00:00
|
|
|
if revision and revision ~= "" then
|
2020-08-29 03:20:28 +00:00
|
|
|
self.short = self.short .. "-" .. revision
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self.short
|
|
|
|
end
|
|
|
|
|
2021-04-13 15:54:11 +00:00
|
|
|
--- Returns the release date of the current version of KOReader, YYYYmmdd, in UTC.
|
|
|
|
--- Technically closer to the build date, but close enough where official builds are concerned ;).
|
|
|
|
-- @treturn int date
|
|
|
|
function Version:getBuildDate()
|
|
|
|
if not self.date then
|
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
|
|
|
local mtime = lfs.attributes("git-rev", "modification")
|
|
|
|
if mtime then
|
|
|
|
local ts = os.date("!%Y%m%d", mtime)
|
|
|
|
self.date = tonumber(ts) or 0
|
|
|
|
else
|
|
|
|
-- No git-rev file?
|
|
|
|
self.date = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self.date
|
|
|
|
end
|
|
|
|
|
2017-04-15 12:45:56 +00:00
|
|
|
return Version
|