libs/ipkg: simplify parsing logic to take advantage of the opkg improvements in trunk...
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 15 Nov 2012 20:59:03 +0000 (20:59 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 15 Nov 2012 20:59:03 +0000 (20:59 +0000)
libs/ipkg/luasrc/model/ipkg.lua

index d0d9788..c927e71 100644 (file)
@@ -10,7 +10,6 @@ You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 
 http://www.apache.org/licenses/LICENSE-2.0
 
-$Id$
 ]]--
 
 local os   = require "os"
 ]]--
 
 local os   = require "os"
@@ -23,7 +22,7 @@ local pairs = pairs
 local error = error
 local table = table
 
 local error = error
 local table = table
 
-local ipkg = "opkg --force-removal-of-dependent-packages --force-overwrite"
+local ipkg = "opkg --force-removal-of-dependent-packages --force-overwrite --nocase"
 local icfg = "/etc/opkg.conf"
 
 --- LuCI OPKG call abstraction library
 local icfg = "/etc/opkg.conf"
 
 --- LuCI OPKG call abstraction library
@@ -159,7 +158,7 @@ end
 -- List helper
 function _list(action, pat, cb)
        local fd = io.popen(ipkg .. " " .. action ..
 -- List helper
 function _list(action, pat, cb)
        local fd = io.popen(ipkg .. " " .. action ..
-               (pat and (" '%s'" % pat:gsub("'", "")) or "")) -- .. " | grep -vE '^ '")
+               (pat and (" '%s'" % pat:gsub("'", "")) or ""))
 
        if fd then
                local name, version, desc
 
        if fd then
                local name, version, desc
@@ -167,20 +166,18 @@ function _list(action, pat, cb)
                        local line = fd:read("*l")
                        if not line then break end
 
                        local line = fd:read("*l")
                        if not line then break end
 
-                       if line:sub(1,1) ~= " " then
-                               name, version, desc = line:match("^(.-) %- (.-) %- (.+)")
+                       name, version, desc = line:match("^(.-) %- (.-) %- (.+)")
 
 
-                               if not name then
-                                       name, version = line:match("^(.-) %- (.+)")
-                                       desc = ""
-                               end
+                       if not name then
+                               name, version = line:match("^(.-) %- (.+)")
+                               desc = ""
+                       end
 
 
-                               cb(name, version, desc)
+                       cb(name, version, desc)
 
 
-                               name    = nil
-                               version = nil
-                               desc    = nil
-                       end
+                       name    = nil
+                       version = nil
+                       desc    = nil
                end
 
                fd:close()
                end
 
                fd:close()
@@ -203,6 +200,15 @@ function list_installed(pat, cb)
        _list("list_installed", pat, cb)
 end
 
        _list("list_installed", pat, cb)
 end
 
+--- Find packages that match the given pattern.
+-- @param pat  Find packages whose names or descriptions match this pattern, nil results in zero results
+-- @param cb   Callback function invoked for each patckage, receives name, version and description as arguments
+-- @return     nothing
+function find(pat, cb)
+       _list("find", pat, cb)
+end
+
+
 --- Determines the overlay root used by opkg.
 -- @return             String containing the directory path of the overlay root.
 function overlay_root()
 --- Determines the overlay root used by opkg.
 -- @return             String containing the directory path of the overlay root.
 function overlay_root()