Changeset 5702

Show
Ignore:
Timestamp:
03/01/10 00:44:44 (3 years ago)
Author:
jow
Message:

luci-0.9: merge r5698

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/branches/luci-0.9/libs/ipkg/luasrc/model/ipkg.lua

    r5660 r5702  
    2121local pairs = pairs 
    2222local error = error 
     23local table = table 
    2324 
    2425local ipkg = "opkg" 
     
    3132local function _action(cmd, ...) 
    3233    local pkg = "" 
    33     arg.n = nil 
    34     for k, v in pairs(arg) do 
     34    for k, v in pairs({...}) do 
    3535        pkg = pkg .. " '" .. v:gsub("'", "") .. "'" 
    3636    end 
     
    148148    return _action("upgrade") 
    149149end 
     150 
     151-- List helper 
     152function _list(action, pat, cb) 
     153    local fd = io.popen(ipkg .. " " .. action .. (pat and " '*" .. pat:gsub("'", "") .. "*'" or "")) 
     154    if fd then 
     155        local name, version, desc 
     156        while true do 
     157            local line = fd:read("*l") 
     158            if not line then break end 
     159 
     160            if line:sub(1,1) ~= " " then 
     161                name, version, desc = line:match("^(.-) %- (.-) %- (.+)") 
     162 
     163                if not name then 
     164                    name, version = line:match("^(.-) %- (.+)") 
     165                    desc = "" 
     166                end 
     167 
     168                cb(name, version, desc) 
     169 
     170                name    = nil 
     171                version = nil 
     172                desc    = nil 
     173            end 
     174        end 
     175 
     176        fd:close() 
     177    end 
     178end 
     179 
     180--- List all packages known to opkg. 
     181-- @param pat   Only find packages matching this pattern, nil lists all packages 
     182-- @param cb    Callback function invoked for each package, receives name, version and description as arguments 
     183-- @return  nothing 
     184function list_all(pat, cb) 
     185    _list("list", pat, cb) 
     186end 
     187 
     188--- List installed packages. 
     189-- @param pat   Only find packages matching this pattern, nil lists all packages 
     190-- @param cb    Callback function invoked for each package, receives name, version and description as arguments 
     191-- @return  nothing 
     192function list_installed(pat, cb) 
     193    _list("list_installed", pat, cb) 
     194end