summaryrefslogtreecommitdiffstats
path: root/acfupdate-model.lua
blob: b713c1847380d13b36840873899cfa40364ee525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-- acf model for displaying logfiles recusivly 
module (..., package.seeall)

require("fs")
require("format")
-- no initializer in model - use controller.init for that

-- ###############################################################
-- Private functions
local function querycmd ( cmdline )
	local cmd = io.popen( cmdline )
	local cmd_result = cmd:read("*a") or "unknown"
	cmd:close()
	return cmd_result
end

-- ###############################################################
-- Public functions

get = function (self)
	local svnurl = "svn://svn.alpinelinux.org/acf/"
	return querycmd("/usr/bin/svn list -v " .. svnurl )
end

update = function (self)
	local svnurl = "svn://svn.alpinelinux.org/acf/"
	local updates = {}
	local cmdresult = {}
	updates.svnurl = svnurl
	for list in string.gmatch((querycmd("/usr/bin/svn list " .. svnurl )), "%S+") do
		local updateresult = ""
		if (list == "core/") then
			updateresult = querycmd("/usr/bin/svn up /usr/share/acf/ 2>&1")
		elseif ( fs.is_dir("/usr/share/acf/app/" .. list)) then
			updateresult = querycmd("/usr/bin/svn up /usr/share/acf/app/" .. list .. " 2>&1")
		elseif (list ~= "sandbox/") then
			updateresult = querycmd("/usr/bin/svn co " .. svnurl .. list .."trunk/ /usr/share/acf/app/" .. list .. " 2>&1")
		end
		-- Hide projects without updates
		if (string.match(updateresult, "^At revision.*")) then updateresult = "" end
		table.insert(cmdresult, {name=list, updates=updateresult})
	end
	updates.cmdresult = cmdresult
	return updates
end

diffs = function (self)
	local svnurl = "svn://svn.alpinelinux.org/acf/"
	local updates = {}
	local cmdresult = {}
	updates.svnurl = svnurl
	table.insert(cmdresult, {name="INFORMATION", updates="<p class=attention>Important information.</p><p>In the following output all html-brackets < and > are replaced to [ and ].<BR>This is to be able to display the diffs in text (perhibit the browser to display the diff as graphics).</p>"})
	for list in string.gmatch((querycmd("/usr/bin/svn list " .. svnurl )), "%S+") do
		local updateresult = ""
		if (list == "core/") then
			updateresult = querycmd("/usr/bin/svn -rHEAD diff /usr/share/acf/ 2>&1")
		elseif ( fs.is_dir("/usr/share/acf/app/" .. list)) then
			updateresult = querycmd("/usr/bin/svn -rHEAD diff /usr/share/acf/app/" .. list .. " 2>&1")
		end
		updateresult = format.search_replace({updateresult},"<","[")
		updateresult = format.search_replace(updateresult,">","]")
		updateresult = table.concat(updateresult, "\n")
		table.insert(cmdresult, {name=list, updates=updateresult})
	end
	updates.cmdresult = cmdresult
	return updates
end

status = function (self)
	local svnurl = "svn://svn.alpinelinux.org/acf/"
	local updates = {}
	local cmdresult = {}
	updates.svnurl = svnurl
	for list in string.gmatch((querycmd("/usr/bin/svn list " .. svnurl )), "%S+") do
		local updateresult = ""
		if (list == "core/") then
			updateresult = querycmd("/usr/bin/svn st -u /usr/share/acf/ 2>&1")
		elseif ( fs.is_dir("/usr/share/acf/app/" .. list)) then
			updateresult = querycmd("/usr/bin/svn st -u /usr/share/acf/app/" .. list .. " 2>&1")
		end
		-- Hide projects without diffs
		if (string.match(updateresult, "^Status against revision.*")) then updateresult = "" end
		table.insert(cmdresult, {name=list, updates=updateresult})
	end
	updates.cmdresult = cmdresult
	return updates
end
log = function (self)
	local svnurl = "svn://svn.alpinelinux.org/acf/"
	local updates = {}
	local cmdresult = {}
	local enddate = tostring(os.date("%Y-%m-%d",  (os.time() - (3600 * 24) * 7)))
	local svnresult = querycmd("/usr/bin/svn log -v -rHEAD:{".. enddate .. "} " .. svnurl )
--	for k,v in pairs(format.string_to_table("r%d+%s+", svnresult)) do
	local svnheader = os.date("%Y-%m-%d")
	local svnupdates = ""
	table.insert(cmdresult, {name="INFORMATION", updates="<p>This is the result of svn log 1 week back in time.</p><p>  svn log -v -rHEAD:{".. enddate .. "} " .. svnurl .. "</p>"})

	for v in string.gmatch(svnresult,"(.-\n)") do
		local svnheader_tmp = string.match(v, "r%d+%s+.-(%d+%-%d+%-%d+)")
		if (svnheader_tmp) and (svnheader_tmp ~= svnheader) then
			table.insert(cmdresult,{
				["updates"] = svnupdates,
				["name"] = svnheader, })
			svnheader = svnheader_tmp
			svnupdates = ""
		end
		svnupdates = svnupdates .. v
	end
	updates.cmdresult = cmdresult
	return updates
end