Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFS Gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
firmware
FFS Gluon
Commits
c9f1fdf6
Unverified
Commit
c9f1fdf6
authored
5 years ago
by
Matthias Schiffer
Browse files
Options
Downloads
Patches
Plain Diff
scripts: check_site: use setfenv to keep global environment clean
This is now much nicer to luacheck.
parent
95e7d415
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/check_site.lua
+40
-37
40 additions, 37 deletions
scripts/check_site.lua
with
40 additions
and
37 deletions
scripts/check_site.lua
+
40
−
37
View file @
c9f1fdf6
...
@@ -34,6 +34,9 @@ end
...
@@ -34,6 +34,9 @@ end
local
site
,
domain_code
,
domain
,
conf
local
site
,
domain_code
,
domain
,
conf
local
M
=
setmetatable
({},
{
__index
=
_G
})
local
function
merge
(
a
,
b
)
local
function
merge
(
a
,
b
)
local
function
is_array
(
t
)
local
function
is_array
(
t
)
local
n
=
0
local
n
=
0
...
@@ -81,9 +84,9 @@ local function array_to_string(array)
...
@@ -81,9 +84,9 @@ local function array_to_string(array)
return
'['
..
table.concat
(
strings
,
', '
)
..
']'
return
'['
..
table.concat
(
strings
,
', '
)
..
']'
end
end
function
table_keys
(
tbl
)
function
M
.
table_keys
(
tbl
)
local
keys
=
{}
local
keys
=
{}
for
k
,
_
in
pairs
(
tbl
)
do
for
k
in
pairs
(
tbl
)
do
keys
[
#
keys
+
1
]
=
k
keys
[
#
keys
+
1
]
=
k
end
end
return
keys
return
keys
...
@@ -127,7 +130,7 @@ local function var_error(path, val, msg)
...
@@ -127,7 +130,7 @@ local function var_error(path, val, msg)
config_error
(
conf_src
(
path
),
'expected %s to %s, but it is %s'
,
path_to_string
(
path
),
msg
,
found
)
config_error
(
conf_src
(
path
),
'expected %s to %s, but it is %s'
,
path_to_string
(
path
),
msg
,
found
)
end
end
function
in_site
(
path
)
function
M
.
in_site
(
path
)
if
has_domains
and
loadpath
(
nil
,
domain
,
unpack
(
path
))
~=
nil
then
if
has_domains
and
loadpath
(
nil
,
domain
,
unpack
(
path
))
~=
nil
then
config_error
(
domain_src
(),
'%s is allowed in site configuration only'
,
path_to_string
(
path
))
config_error
(
domain_src
(),
'%s is allowed in site configuration only'
,
path_to_string
(
path
))
end
end
...
@@ -135,7 +138,7 @@ function in_site(path)
...
@@ -135,7 +138,7 @@ function in_site(path)
return
path
return
path
end
end
function
in_domain
(
path
)
function
M
.
in_domain
(
path
)
if
has_domains
and
loadpath
(
nil
,
site
,
unpack
(
path
))
~=
nil
then
if
has_domains
and
loadpath
(
nil
,
site
,
unpack
(
path
))
~=
nil
then
config_error
(
site_src
(),
'%s is allowed in domain configuration only'
,
path_to_string
(
path
))
config_error
(
site_src
(),
'%s is allowed in domain configuration only'
,
path_to_string
(
path
))
end
end
...
@@ -143,12 +146,12 @@ function in_domain(path)
...
@@ -143,12 +146,12 @@ function in_domain(path)
return
path
return
path
end
end
function
this_domain
()
function
M
.
this_domain
()
return
domain_code
return
domain_code
end
end
function
extend
(
path
,
c
)
function
M
.
extend
(
path
,
c
)
if
not
path
then
return
nil
end
if
not
path
then
return
nil
end
local
p
=
{
unpack
(
path
)}
local
p
=
{
unpack
(
path
)}
...
@@ -172,7 +175,7 @@ function loadpath(path, base, c, ...)
...
@@ -172,7 +175,7 @@ function loadpath(path, base, c, ...)
end
end
end
end
return
loadpath
(
extend
(
path
,
{
c
}),
base
[
c
],
...
)
return
loadpath
(
M
.
extend
(
path
,
{
c
}),
base
[
c
],
...
)
end
end
local
function
loadvar
(
path
)
local
function
loadvar
(
path
)
...
@@ -197,7 +200,7 @@ local function check_one_of(array)
...
@@ -197,7 +200,7 @@ local function check_one_of(array)
end
end
function
alternatives
(
...
)
function
M
.
alternatives
(
...
)
local
errs
=
{
'All of the following alternatives have failed:'
}
local
errs
=
{
'All of the following alternatives have failed:'
}
for
i
,
f
in
ipairs
({
...
})
do
for
i
,
f
in
ipairs
({
...
})
do
local
ok
,
err
=
pcall
(
f
)
local
ok
,
err
=
pcall
(
f
)
...
@@ -238,7 +241,7 @@ local function check_chanlist(channels)
...
@@ -238,7 +241,7 @@ local function check_chanlist(channels)
end
end
end
end
function
need
(
path
,
check
,
required
,
msg
)
function
M
.
need
(
path
,
check
,
required
,
msg
)
local
val
=
loadvar
(
path
)
local
val
=
loadvar
(
path
)
if
required
==
false
and
val
==
nil
then
if
required
==
false
and
val
==
nil
then
return
nil
return
nil
...
@@ -252,11 +255,11 @@ function need(path, check, required, msg)
...
@@ -252,11 +255,11 @@ function need(path, check, required, msg)
end
end
local
function
need_type
(
path
,
type
,
required
,
msg
)
local
function
need_type
(
path
,
type
,
required
,
msg
)
return
need
(
path
,
check_type
(
type
),
required
,
msg
)
return
M
.
need
(
path
,
check_type
(
type
),
required
,
msg
)
end
end
function
need_alphanumeric_key
(
path
)
function
M
.
need_alphanumeric_key
(
path
)
local
val
=
path
[
#
path
]
local
val
=
path
[
#
path
]
-- We don't use character classes like %w here to be independent of the locale
-- We don't use character classes like %w here to be independent of the locale
if
type
(
val
)
~=
'string'
or
not
val
:
match
(
'^[0-9a-zA-Z_]+$'
)
then
if
type
(
val
)
~=
'string'
or
not
val
:
match
(
'^[0-9a-zA-Z_]+$'
)
then
...
@@ -265,12 +268,12 @@ function need_alphanumeric_key(path)
...
@@ -265,12 +268,12 @@ function need_alphanumeric_key(path)
end
end
function
need_string
(
path
,
required
)
function
M
.
need_string
(
path
,
required
)
return
need_type
(
path
,
'string'
,
required
,
'be a string'
)
return
need_type
(
path
,
'string'
,
required
,
'be a string'
)
end
end
function
need_string_match
(
path
,
pat
,
required
)
function
M
.
need_string_match
(
path
,
pat
,
required
)
local
val
=
need_string
(
path
,
required
)
local
val
=
M
.
need_string
(
path
,
required
)
if
not
val
then
if
not
val
then
return
nil
return
nil
end
end
...
@@ -282,15 +285,15 @@ function need_string_match(path, pat, required)
...
@@ -282,15 +285,15 @@ function need_string_match(path, pat, required)
return
val
return
val
end
end
function
need_number
(
path
,
required
)
function
M
.
need_number
(
path
,
required
)
return
need_type
(
path
,
'number'
,
required
,
'be a number'
)
return
need_type
(
path
,
'number'
,
required
,
'be a number'
)
end
end
function
need_boolean
(
path
,
required
)
function
M
.
need_boolean
(
path
,
required
)
return
need_type
(
path
,
'boolean'
,
required
,
'be a boolean'
)
return
need_type
(
path
,
'boolean'
,
required
,
'be a boolean'
)
end
end
function
need_array
(
path
,
subcheck
,
required
)
function
M
.
need_array
(
path
,
subcheck
,
required
)
local
val
=
need_type
(
path
,
'table'
,
required
,
'be an array'
)
local
val
=
need_type
(
path
,
'table'
,
required
,
'be an array'
)
if
not
val
then
if
not
val
then
return
nil
return
nil
...
@@ -298,14 +301,14 @@ function need_array(path, subcheck, required)
...
@@ -298,14 +301,14 @@ function need_array(path, subcheck, required)
if
subcheck
then
if
subcheck
then
for
i
=
1
,
#
val
do
for
i
=
1
,
#
val
do
subcheck
(
extend
(
path
,
{
i
}))
subcheck
(
M
.
extend
(
path
,
{
i
}))
end
end
end
end
return
val
return
val
end
end
function
need_table
(
path
,
subcheck
,
required
)
function
M
.
need_table
(
path
,
subcheck
,
required
)
local
val
=
need_type
(
path
,
'table'
,
required
,
'be a table'
)
local
val
=
need_type
(
path
,
'table'
,
required
,
'be a table'
)
if
not
val
then
if
not
val
then
return
nil
return
nil
...
@@ -313,45 +316,45 @@ function need_table(path, subcheck, required)
...
@@ -313,45 +316,45 @@ function need_table(path, subcheck, required)
if
subcheck
then
if
subcheck
then
for
k
,
_
in
pairs
(
val
)
do
for
k
,
_
in
pairs
(
val
)
do
subcheck
(
extend
(
path
,
{
k
}))
subcheck
(
M
.
extend
(
path
,
{
k
}))
end
end
end
end
return
val
return
val
end
end
function
need_value
(
path
,
value
,
required
)
function
M
.
need_value
(
path
,
value
,
required
)
return
need
(
path
,
function
(
v
)
return
M
.
need
(
path
,
function
(
v
)
return
v
==
value
return
v
==
value
end
,
required
,
'be '
..
tostring
(
value
))
end
,
required
,
'be '
..
tostring
(
value
))
end
end
function
need_one_of
(
path
,
array
,
required
)
function
M
.
need_one_of
(
path
,
array
,
required
)
return
need
(
path
,
check_one_of
(
array
),
required
,
'be one of the given array '
..
array_to_string
(
array
))
return
M
.
need
(
path
,
check_one_of
(
array
),
required
,
'be one of the given array '
..
array_to_string
(
array
))
end
end
function
need_string_array
(
path
,
required
)
function
M
.
need_string_array
(
path
,
required
)
return
need_array
(
path
,
need_string
,
required
)
return
M
.
need_array
(
path
,
M
.
need_string
,
required
)
end
end
function
need_string_array_match
(
path
,
pat
,
required
)
function
M
.
need_string_array_match
(
path
,
pat
,
required
)
return
need_array
(
path
,
function
(
e
)
need_string_match
(
e
,
pat
)
end
,
required
)
return
M
.
need_array
(
path
,
function
(
e
)
M
.
need_string_match
(
e
,
pat
)
end
,
required
)
end
end
function
need_array_of
(
path
,
array
,
required
)
function
M
.
need_array_of
(
path
,
array
,
required
)
return
need_array
(
path
,
function
(
e
)
need_one_of
(
e
,
array
)
end
,
required
)
return
M
.
need_array
(
path
,
function
(
e
)
M
.
need_one_of
(
e
,
array
)
end
,
required
)
end
end
function
need_chanlist
(
path
,
channels
,
required
)
function
M
.
need_chanlist
(
path
,
channels
,
required
)
local
valid_chanlist
=
check_chanlist
(
channels
)
local
valid_chanlist
=
check_chanlist
(
channels
)
return
need
(
path
,
valid_chanlist
,
required
,
return
M
.
need
(
path
,
valid_chanlist
,
required
,
'be a space-separated list of WiFi channels or channel-ranges (separated by a hyphen). '
'be a space-separated list of WiFi channels or channel-ranges (separated by a hyphen). '
..
'Valid channels are: '
..
array_to_string
(
channels
))
..
'Valid channels are: '
..
array_to_string
(
channels
))
end
end
function
need_domain_name
(
path
)
function
M
.
need_domain_name
(
path
)
need_string
(
path
)
M
.
need_string
(
path
)
need
(
path
,
function
(
domain_name
)
M
.
need
(
path
,
function
(
domain_name
)
local
f
=
io.open
(
os.getenv
(
'IPKG_INSTROOT'
)
..
'/lib/gluon/domains/'
..
domain_name
..
'.json'
)
local
f
=
io.open
(
os.getenv
(
'IPKG_INSTROOT'
)
..
'/lib/gluon/domains/'
..
domain_name
..
'.json'
)
if
not
f
then
return
false
end
if
not
f
then
return
false
end
f
:
close
()
f
:
close
()
...
@@ -359,7 +362,7 @@ function need_domain_name(path)
...
@@ -359,7 +362,7 @@ function need_domain_name(path)
end
,
nil
,
'be a valid domain name'
)
end
,
nil
,
'be a valid domain name'
)
end
end
function
obsolete
(
path
,
msg
)
function
M
.
obsolete
(
path
,
msg
)
local
val
=
loadvar
(
path
)
local
val
=
loadvar
(
path
)
if
val
==
nil
then
if
val
==
nil
then
return
nil
return
nil
...
@@ -373,7 +376,7 @@ function obsolete(path, msg)
...
@@ -373,7 +376,7 @@ function obsolete(path, msg)
config_error
(
conf_src
(
path
),
'%s is obsolete. %s'
,
path_to_string
(
path
),
msg
)
config_error
(
conf_src
(
path
),
'%s is obsolete. %s'
,
path_to_string
(
path
),
msg
)
end
end
local
check
=
assert
(
loadfile
())
local
check
=
setfenv
(
assert
(
loadfile
())
,
M
)
site
=
load_json
(
os.getenv
(
'IPKG_INSTROOT'
)
..
'/lib/gluon/site.json'
)
site
=
load_json
(
os.getenv
(
'IPKG_INSTROOT'
)
..
'/lib/gluon/site.json'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment