diff options
-rw-r--r-- | acfupdate-controller.lua | 29 | ||||
-rw-r--r-- | acfupdate-html.lsp | 82 | ||||
-rw-r--r-- | acfupdate-model.lua | 180 | ||||
-rw-r--r-- | acfupdate.menu | 4 |
4 files changed, 176 insertions, 119 deletions
diff --git a/acfupdate-controller.lua b/acfupdate-controller.lua index 4e88f7a..b193e70 100644 --- a/acfupdate-controller.lua +++ b/acfupdate-controller.lua @@ -5,32 +5,23 @@ module (..., package.seeall) default_action = "read" -function read (self ) - return ({projects = self.model:get(), - url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) +function read(self) + return self.model.read(clientdata.repository) end -function update (self ) - return ({projects = self.model:get(), - updates = self.model:update(), - url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) +function update(self) + return self:redirect_to_referrer(self.model.update(clientdata.repository, self.sessiondata)) end -function diff (self ) - return ({projects = self.model:get(), - updates = self.model:diffs(), - url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) +function diff(self) + return self:redirect_to_referrer(self.model.diffs(clientdata.repository)) end -function status (self ) - return ({projects = self.model:get(), - updates = self.model:status(), - url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) +function status(self) + return self:redirect_to_referrer(self.model.status(clientdata.repository)) end -function log (self ) - return ({projects = self.model:get(), - updates = self.model:log(), - url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) +function log(self) + return self:redirect_to_referrer(self.model.log(clientdata.repository)) end diff --git a/acfupdate-html.lsp b/acfupdate-html.lsp index 60e8ceb..967dae7 100644 --- a/acfupdate-html.lsp +++ b/acfupdate-html.lsp @@ -1,23 +1,69 @@ -<% local view = ... %> +<% local data, viewlibrary, page_info, session = ... +require("viewfunctions") +%> -<h1>Fetch ACF updates</h1> +<H1>System Info</H1> +<DL> +<% +displayitem(data.value.version) +displayitem(data.value.repository) +%> +</DL> -<p>Click on the tab <B>update</B> to fetch/update all available projects.</p> -<p>The 'sandbox' project is not automatically fetched/checked out!<BR> -But if you have manually checked it out, you will get a update on it by pressing the <B>update</B> tab.</p> +<% displaycommandresults({"log"}, session) %> +<% + local cmdresult = {} + for i,cmd in ipairs({"status", "update", "diff"}) do + if session[cmd.."result"] then + cmdresult[#cmdresult + 1] = session[cmd.."result"] + session[cmd.."result"] = nil + end + end + if #cmdresult > 0 then + for i,result in ipairs(cmdresult) do + io.write("<H1>"..result.label.."</H1>\n<DL>\n") + for i,value in ipairs(result.value) do + if value.updates ~= "" then %> +<H3><%= value.name %></H3> +<pre><%= html.html_escape(value.updates) %></pre> + <% end + end + io.write("</DL>\n") + end + end +%> -<h2>Available projects</h2> -<pre><%= view.projects %></pre> - -<% if (view.updates) then %> - <h2>Summary</h2> - <% for i = 1, table.maxn(view["updates"]["cmdresult"]) do %> - <% if (view["updates"]["cmdresult"][i]["updates"] ~= "") then %> - <h3><%= view["updates"]["cmdresult"][i]["name"] %></h3> - <pre><%= view["updates"]["cmdresult"][i]["updates"] %></pre> - <% end %> - <% end %> - <h3>-- End of updates --</h3> +<% if not data.value.repository.errtxt then %> +<H1>Actions</H1> +<DL> +<DT>View Status</DT> +<DD> +<form action="<%= page_info.script .. page_info.prefix .. page_info.controller .. "/status" %>" method="POST"> +<input type=hidden value="<%= data.value.repository.value %>" name="repository"> +<input type=submit class=submit value="View Status"> +</form> +</DD> +<DT>View Diff</DT> +<DD> +<form action="<%= page_info.script .. page_info.prefix .. page_info.controller .. "/diff" %>" method="POST"> +<input type=hidden value="<%= data.value.repository.value %>" name="repository"> +<input type=submit class=submit value="View Diff"> +</form> +</DD> +<DT>View Log</DT> +<DD> +<form action="<%= page_info.script .. page_info.prefix .. page_info.controller .. "/log" %>" method="POST"> +<input type=hidden value="<%= data.value.repository.value %>" name="repository"> +<input type=submit class=submit value="View Log"> +</form> +</DD> +<DT>Update</DT> +<DD> +<form action="<%= page_info.script .. page_info.prefix .. page_info.controller .. "/update" %>" method="POST"> +<input type=hidden value="<%= data.value.repository.value %>" name="repository"> +<input type=submit class=submit value="Update"> +</form> +</DD> +</DL> <% end %> - diff --git a/acfupdate-model.lua b/acfupdate-model.lua index 99e7451..be4f3ef 100644 --- a/acfupdate-model.lua +++ b/acfupdate-model.lua @@ -2,6 +2,10 @@ module (..., package.seeall) -- Load libraries require("fs") +require("processinfo") + +local packagename = "subversion" +local svnurl = "svn://svn.alpinelinux.org/acf/" -- ################################################################################ -- LOCAL FUNCTIONS @@ -13,103 +17,123 @@ local function querycmd ( cmdline ) return cmd_result end +local function svndir(archive) + local retval = "/usr/share/acf/" + if archive == "skins/" then + retval = retval.."www/skins/" + elseif archive and archive ~= "core/" then + retval = retval.."app/"..archive + end + return retval +end + +local function determinerepository(repository) + if not repository then + -- try to determine the archive from svn + local cmdresult = querycmd("/usr/bin/svn info "..svndir()) + if string.find(cmdresult, "Repository Root:") then + repository = string.match(cmdresult, "Repository Root:%s+(%S+)") + -- or if not defined, use the default + else + repository = svnurl + end + end + return repository +end + -- ################################################################################ -- PUBLIC FUNCTIONS +function read(repository) + repository = determinerepository(repository) + local status = {} -function get (self) - local svnurl = "svn://svn.alpinelinux.org/acf/" - return querycmd("/usr/bin/svn list -v " .. svnurl ) -end + local value, errtxt = processinfo.package_version(packagename) + status.version = cfe({ + label="Program version", + value=value, + errtxt=errtxt, + }) + + status.repository = cfe({ value=repository, label="SVN Repository" }) + if "" == querycmd("/usr/bin/svn list "..repository) then + status.repository.errtxt = "Repository cannot be reached" + end + + return cfe({ type="group", value=status, descr="ACF Update Info" }) +end -function update (self) - local svnurl = "svn://svn.alpinelinux.org/acf/" - local updates = {} +function update(repository, sessiondata) + repository = determinerepository(repository) 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 (list == "skins/") and ( fs.is_dir("/usr/share/acf/www/" .. list)) then - updateresult = querycmd("/usr/bin/svn up /usr/share/acf/www/skins 2>&1") - elseif (list == "skins/") and not ( fs.is_dir("/usr/share/acf/www/" .. list)) then - updateresult = querycmd("/usr/bin/svn co " .. svnurl .. list .."trunk/ /usr/share/acf/www/" .. list .. " 2>&1") - elseif (list == "skins/") then - updateresult = querycmd("/usr/bin/svn up /usr/share/acf/www/skins 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") + local mustrestart + + function work(list) + local dir = svndir(list) + -- If we have the directory already, but not from archive, delete it + if posix.stat(dir) and not posix.stat(dir..".svn") then + querycmd("rm -r "..dir) + if list == "core/" then + -- We have to restart the web server because we've just deleted the + mustrestart = true + end end + local updateresult = querycmd("/usr/bin/svn co "..repository.."/"..list.."trunk "..dir.." 2>&1") -- Hide projects without updates - if (string.match(updateresult, "^At revision.*")) then updateresult = "" end + if (string.match(updateresult, "^Checked out revision.*")) then updateresult = "" end table.insert(cmdresult, {name=list, updates=updateresult}) end - updates.cmdresult = cmdresult - return updates -end -function diffs (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") + if "" ~= querycmd("/usr/bin/svn list "..repository) then + work("core/") + for list in string.gmatch((querycmd("/usr/bin/svn list " .. repository )), "%S+") do + if list~="core/" and list~="sandbox/" then + work(list) + end end - updateresult = string.gsub(updateresult,"<","[") - updateresult = string.gsub(updateresult,">","]") - table.insert(cmdresult, {name=list, updates=updateresult}) end - updates.cmdresult = cmdresult - return updates + -- Destroy the menu and permissions session data so it's recalculated + if sessiondata then sessiondata.menu = nil end + if sessiondata then sessiondata.permissions = nil end + + if mustrestart then + -- FIXME + --processinfo.daemoncontrol("mini_httpd", "restart") + end + + return cfe({ type="structure", value=cmdresult, label="SVN update Result"}) end -function status (self) - local svnurl = "svn://svn.alpinelinux.org/acf/" - local updates = {} +function diffs(repository) + repository = determinerepository(repository) 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") + for list in string.gmatch((querycmd("/usr/bin/svn list " .. repository )), "%S+") do + if (list ~= "sandbox/") then + local updateresult = querycmd("/usr/bin/svn diff "..svndir(list).." 2>&1") + if updateresult ~= "" then + table.insert(cmdresult, {name=list, updates=updateresult}) + end 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 + return cfe({ type="structure", value=cmdresult, label="SVN diff Result" }) end -function log (self) - local svnurl = "svn://svn.alpinelinux.org/acf/" - local updates = {} + +function status(repository) + repository = determinerepository(repository) 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 ) - 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 = "" + for list in string.gmatch((querycmd("/usr/bin/svn list " .. repository )), "%S+") do + if (list ~= "sandbox/") then + local updateresult = querycmd("/usr/bin/svn st -u "..svndir(list).." 2>&1") + -- Hide projects without diffs + if (string.match(updateresult, "^Status against revision.*")) then updateresult = "" end + table.insert(cmdresult, {name=list, updates=updateresult}) end - svnupdates = svnupdates .. v end - updates.cmdresult = cmdresult - return updates + return cfe({ type="structure", value=cmdresult, label="SVN status Result" }) +end + +function log (repository) + repository = determinerepository(repository) + local enddate = tostring(os.date("%Y-%m-%d", (os.time() - (3600 * 24) * 7))) + local svnresult = querycmd("/usr/bin/svn log -v -rHEAD:{".. enddate .. "} " .. repository ) + return cfe({ type="longtext", value=svnresult, label="SVN log Result" }) end diff --git a/acfupdate.menu b/acfupdate.menu index 32ef476..a24c7b1 100644 --- a/acfupdate.menu +++ b/acfupdate.menu @@ -1,6 +1,2 @@ #CAT GROUP/DESC TAB ACTION 99DevTools 98SVN_status_(for_ACF) Info read -99DevTools 98SVN_status_(for_ACF) Update update -99DevTools 98SVN_status_(for_ACF) Diff diff -99DevTools 98SVN_status_(for_ACF) Status status -99DevTools 98SVN_status_(for_ACF) Log log |