diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-10-01 21:01:36 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-10-01 21:01:36 +0000 |
commit | f9b953cfd89fc1a24eaccf26884deebc73f3d50c (patch) | |
tree | 8e2ccf86c07f4d73d6740523e5631d99eaabf198 /acfupdate-model.lua | |
parent | c22c4c7b4a060929eba8290c27121a75578d80bb (diff) | |
download | acf-devtools-f9b953cfd89fc1a24eaccf26884deebc73f3d50c.tar.bz2 acf-devtools-f9b953cfd89fc1a24eaccf26884deebc73f3d50c.tar.xz |
Modified acfupdate to use cfes. Tried to make it work out-of-the-box without having to check out of svn first. Works except web server must be restarted afterwards. Also has ability to use different svn server, for those like me using port-forwarding.
git-svn-id: svn://svn.alpinelinux.org/acf/devtools/trunk@1538 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'acfupdate-model.lua')
-rw-r--r-- | acfupdate-model.lua | 180 |
1 files changed, 102 insertions, 78 deletions
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 |