Merge pull request #396 from freifunk-gluon/empty-json-objects
gluon-announce, ...: don't output empty lists where not appropriate
This commit is contained in:
commit
d42a7b9184
@ -3,6 +3,7 @@
|
|||||||
module('gluon.announce', package.seeall)
|
module('gluon.announce', package.seeall)
|
||||||
|
|
||||||
fs = require 'nixio.fs'
|
fs = require 'nixio.fs'
|
||||||
|
json = require 'luci.json'
|
||||||
uci = require('luci.model.uci').cursor()
|
uci = require('luci.model.uci').cursor()
|
||||||
util = require 'luci.util'
|
util = require 'luci.util'
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ local function collect_entry(entry)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function collect_dir(dir)
|
function collect_dir(dir)
|
||||||
local ret = {}
|
local ret = { [json.null] = true }
|
||||||
|
|
||||||
for entry in fs.dir(dir) do
|
for entry in fs.dir(dir) do
|
||||||
if entry:sub(1, 1) ~= '.' then
|
if entry:sub(1, 1) ~= '.' then
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
local json = require 'luci.json'
|
|
||||||
local util = require 'luci.util'
|
|
||||||
local fs = require 'nixio.fs'
|
|
||||||
|
|
||||||
local ifname_address_cache = {}
|
local ifname_address_cache = {}
|
||||||
|
|
||||||
function ifname2address(ifname)
|
function ifname2address(ifname)
|
||||||
@ -26,7 +22,7 @@ function batadv()
|
|||||||
if mac1 ~= nil and mac1 == mac2 then
|
if mac1 ~= nil and mac1 == mac2 then
|
||||||
ifaddress = ifname2address(ifname)
|
ifaddress = ifname2address(ifname)
|
||||||
if interfaces[ifaddress] == nil then
|
if interfaces[ifaddress] == nil then
|
||||||
interfaces[ifaddress] = { neighbours = {} }
|
interfaces[ifaddress] = { neighbours = { [json.null] = true } }
|
||||||
end
|
end
|
||||||
|
|
||||||
interfaces[ifaddress].neighbours[mac1] = { tq = tonumber(tq)
|
interfaces[ifaddress].neighbours[mac1] = { tq = tonumber(tq)
|
||||||
@ -35,7 +31,9 @@ function batadv()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if next(interfaces) then
|
||||||
return interfaces
|
return interfaces
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return batadv()
|
return batadv()
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
local json = require 'luci.json'
|
|
||||||
local util = require 'luci.util'
|
|
||||||
local fs = require 'nixio.fs'
|
|
||||||
local iwinfo = require 'iwinfo'
|
local iwinfo = require 'iwinfo'
|
||||||
|
|
||||||
function neighbours(iface)
|
function neighbours(iface)
|
||||||
@ -12,8 +9,10 @@ function neighbours(iface)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if next(stations) then
|
||||||
return stations
|
return stations
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function interfaces()
|
function interfaces()
|
||||||
local interfaces = {}
|
local interfaces = {}
|
||||||
@ -38,4 +37,6 @@ for address, iface in pairs(interfaces()) do
|
|||||||
wifi[address] = { neighbours = neighbours(iface) }
|
wifi[address] = { neighbours = neighbours(iface) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if next(wifi) then
|
||||||
return wifi
|
return wifi
|
||||||
|
end
|
||||||
|
@ -48,5 +48,6 @@ end
|
|||||||
return {
|
return {
|
||||||
wireless = nil_table(wireless),
|
wireless = nil_table(wireless),
|
||||||
tunnel = nil_table(tunnel),
|
tunnel = nil_table(tunnel),
|
||||||
other = nil_table(other)
|
other = nil_table(other),
|
||||||
|
[json.null] = true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user