* Moved exec, execl from ffluci.util to ffluci.sys
authorSteven Barth <steven@midlink.org>
Sun, 30 Mar 2008 19:25:31 +0000 (19:25 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 30 Mar 2008 19:25:31 +0000 (19:25 +0000)
* Introduced stub for ffluci.model.ipkg

src/ffluci/controller/admin/uci.lua
src/ffluci/model/cbi/admin_wifi/devices.lua
src/ffluci/model/ipkg.lua [new file with mode: 0644]
src/ffluci/model/uci.lua
src/ffluci/sys.lua
src/ffluci/util.lua

index 9f8c124..3c9fc87 100644 (file)
@@ -1,4 +1,6 @@
 module("ffluci.controller.admin.uci", package.seeall)
+require("ffluci.util")
+require("ffluci.sys")
 
 -- This function has a higher priority than the admin_uci/apply template
 function action_apply()
@@ -24,7 +26,7 @@ function action_apply()
                        for k, v in pairs(apply) do
                                local cmd = ffluci.config.uci_oncommit[k]
                                if cmd then
-                                       output = output .. cmd .. ":" .. ffluci.util.exec(cmd)
+                                       output = output .. cmd .. ":" .. ffluci.sys.exec(cmd)
                                end
                        end
                end
index 7ef794c..0b1b9a2 100644 (file)
@@ -1,5 +1,4 @@
 -- ToDo: Translate, Add descriptions and help texts
-require("ffluci.util")
 
 m = Map("wireless", "Geräte")
 
@@ -16,8 +15,9 @@ t:value("atheros")
 t:value("mac80211")
 t:value("prism2")
 --[[
+require("ffluci.sys")
 local c = ". /etc/functions.sh;for i in /lib/wifi/*;do . $i;done;echo $DRIVERS"
-for driver in ffluci.util.execl(c)[1]:gmatch("[^ ]+") do
+for driver in ffluci.sys.execl(c)[1]:gmatch("[^ ]+") do
        t:value(driver)
 end
 ]]--
diff --git a/src/ffluci/model/ipkg.lua b/src/ffluci/model/ipkg.lua
new file mode 100644 (file)
index 0000000..a0ca8a8
--- /dev/null
@@ -0,0 +1,29 @@
+--[[
+FFLuCI - IPKG wrapper library
+
+Description:
+Wrapper for the ipkg Package manager
+
+Any return value of false or nil can be interpreted as an error
+
+FileId:
+$Id$
+
+License:
+Copyright 2008 Steven Barth <steven@midlink.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at 
+
+       http://www.apache.org/licenses/LICENSE-2.0 
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+]]--
+module("ffluci.model.ipkg", package.seeall)
+require("ffluci.sys")
index 6585c66..94a385c 100644 (file)
@@ -32,6 +32,7 @@ limitations under the License.
 module("ffluci.model.uci", package.seeall)
 require("ffluci.util")
 require("ffluci.fs")
+require("ffluci.sys")
 
 -- The OS uci command
 ucicmd = "uci"
@@ -135,7 +136,7 @@ end
 -- Internal functions --
 
 function Session._uci(self, cmd)
-       local res = ffluci.util.exec(self.ucicmd .. " 2>/dev/null " .. cmd)
+       local res = ffluci.sys.exec(self.ucicmd .. " 2>/dev/null " .. cmd)
        
        if res:len() == 0 then
                return nil
@@ -145,7 +146,7 @@ function Session._uci(self, cmd)
 end
 
 function Session._uci2(self, cmd)
-       local res = ffluci.util.exec(self.ucicmd .. " 2>&1 " .. cmd)
+       local res = ffluci.sys.exec(self.ucicmd .. " 2>&1 " .. cmd)
        
        if res:len() > 0 then
                return false, res
@@ -155,7 +156,7 @@ function Session._uci2(self, cmd)
 end
 
 function Session._uci3(self, cmd)
-       local res = ffluci.util.execl(self.ucicmd .. " 2>&1 " .. cmd)
+       local res = ffluci.sys.execl(self.ucicmd .. " 2>&1 " .. cmd)
        if res[1]:sub(1, ucicmd:len() + 1) == ucicmd .. ":" then
                return nil, res[1]
        end
index 532324d..367d41e 100644 (file)
@@ -27,6 +27,31 @@ limitations under the License.
 module("ffluci.sys", package.seeall)
 require("posix")
 
+-- Runs "command" and returns its output
+function exec(command)
+       local pp   = io.popen(command)
+       local data = pp:read("*a")
+       pp:close()
+       
+       return data
+end
+
+-- Runs "command" and returns its output as a array of lines
+function execl(command)
+       local pp   = io.popen(command)  
+       local line = ""
+       local data = {}
+       
+       while true do
+               line = pp:read()
+               if (line == nil) then break end
+               table.insert(data, line)
+       end 
+       pp:close()      
+       
+       return data
+end
+
 -- Returns the hostname
 function hostname()
        return io.lines("/proc/sys/kernel/hostname")()
index c47a898..54ee071 100644 (file)
@@ -103,33 +103,6 @@ function escape(s, c)
 end
 
 
--- Runs "command" and returns its output
-function exec(command)
-       local pp   = io.popen(command)
-       local data = pp:read("*a")
-       pp:close()
-       
-       return data
-end
-
-
--- Runs "command" and returns its output as a array of lines
-function execl(command)
-       local pp   = io.popen(command)  
-       local line = ""
-       local data = {}
-       
-       while true do
-               line = pp:read()
-               if (line == nil) then break end
-               table.insert(data, line)
-       end 
-       pp:close()      
-       
-       return data
-end
-
-
 -- Populate obj in the scope of f as key 
 function extfenv(f, key, obj)
        local scope = getfenv(f)