* Moved exec, execl from ffluci.util to ffluci.sys

* Introduced stub for ffluci.model.ipkg
This commit is contained in:
Steven Barth 2008-03-30 19:25:31 +00:00
parent 9b4e269bea
commit 1bf67dcd79
6 changed files with 63 additions and 33 deletions

View 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

View 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
]]--

29
src/ffluci/model/ipkg.lua Normal file
View file

@ -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")

View 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

View 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")()

View 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)