diff options
author | Steven Barth <steven@midlink.org> | 2008-10-08 23:35:54 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-10-08 23:35:54 +0000 |
commit | dc494c838c15ef59a72927b9cf6f18878d06bd69 (patch) | |
tree | ecf75aeb41b3d7a2e49ddecb630d9e31418b390e | |
parent | b99972e6715acaf5af640e3fcb88fe466e69d5d8 (diff) |
Optimized IPKG info parser
-rw-r--r-- | libs/ipkg/luasrc/model/ipkg.lua | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/libs/ipkg/luasrc/model/ipkg.lua b/libs/ipkg/luasrc/model/ipkg.lua index 706d36c588..b06834510a 100644 --- a/libs/ipkg/luasrc/model/ipkg.lua +++ b/libs/ipkg/luasrc/model/ipkg.lua @@ -41,28 +41,17 @@ end -- Internal parser function local function _parselist(rawdata) - if type(rawdata) ~= "string" then + if type(rawdata) ~= "function" then error("IPKG: Invalid rawdata given") end - rawdata = util.split(rawdata) local data = {} local c = {} local l = nil - for k, line in pairs(rawdata) do + for line in rawdata do if line:sub(1, 1) ~= " " then - local split = util.split(line, ":", 1) - local key = nil - local val = nil - - if split[1] then - key = util.trim(split[1]) - end - - if split[2] then - val = util.trim(split[2]) - end + local key, val = line:match("(.-): ?(.*)%s*") if key and val then if key == "Package" then @@ -70,7 +59,7 @@ local function _parselist(rawdata) data[val] = c elseif key == "Status" then c.Status = {} - for i, j in pairs(util.split(val, " ")) do + for j in val:gmatch("([^ ]+)") do c.Status[j] = true end else @@ -80,7 +69,7 @@ local function _parselist(rawdata) end else -- Multi-line field - c[l] = c[l] .. "\n" .. line:sub(2) + c[l] = c[l] .. "\n" .. line end end @@ -94,7 +83,7 @@ local function _lookup(act, pkg) cmd = cmd .. " '" .. pkg:gsub("'", "") .. "'" end - return _parselist(util.exec(cmd .. " 2>/dev/null")) + return _parselist(util.execi(cmd .. " 2>/dev/null")) end |