diff options
author | Andrew Lewis <nerf@judo.za.org> | 2016-11-14 20:39:16 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2016-11-15 17:30:39 +0200 |
commit | da83f5296a9e41bc55c8a5bd83fdc3bfd7bf5f54 (patch) | |
tree | 14bc67a2c9af086a375335621457f404df6bea19 /src | |
parent | fc406133889dc128f44e351c3198994c2e8d1b8e (diff) | |
download | rspamd-da83f5296a9e41bc55c8a5bd83fdc3bfd7bf5f54.tar.gz rspamd-da83f5296a9e41bc55c8a5bd83fdc3bfd7bf5f54.zip |
[Minor] Lint rspamadm & test suite scripts
Diffstat (limited to 'src')
-rw-r--r-- | src/rspamadm/confighelp.lua | 7 | ||||
-rw-r--r-- | src/rspamadm/fuzzy_convert.lua | 30 | ||||
-rw-r--r-- | src/rspamadm/fuzzy_stat.lua | 30 | ||||
-rw-r--r-- | src/rspamadm/stat_convert.lua | 10 |
4 files changed, 43 insertions, 34 deletions
diff --git a/src/rspamadm/confighelp.lua b/src/rspamadm/confighelp.lua index 3af3c5b1f..0d61bf394 100644 --- a/src/rspamadm/confighelp.lua +++ b/src/rspamadm/confighelp.lua @@ -1,4 +1,3 @@ -local util = require "rspamd_util" local opts = {} local known_attrs = { data = 1, @@ -20,7 +19,7 @@ local function maybe_print_color(key) end end -local function sort_values(tbl, opts) +local function sort_values(tbl) local res = {} for k, v in pairs(tbl) do table.insert(res, { key = k, value = v }) @@ -91,7 +90,7 @@ local function print_help(key, value, tabs) end local sorted = sort_values(value) - for i, v in ipairs(sorted) do + for _, v in ipairs(sorted) do if not known_attrs[v['key']] then -- We need to go deeper print_help(v['key'], v['value'], tabs .. '\t') @@ -104,7 +103,7 @@ return function(args, res) local sorted = sort_values(res) - for i,v in ipairs(sorted) do + for _,v in ipairs(sorted) do print_help(v['key'], v['value'], '') print('') end diff --git a/src/rspamadm/fuzzy_convert.lua b/src/rspamadm/fuzzy_convert.lua index 5db3c925b..a7ee666b9 100644 --- a/src/rspamadm/fuzzy_convert.lua +++ b/src/rspamadm/fuzzy_convert.lua @@ -41,10 +41,13 @@ end local function send_digests(digests, redis_host, redis_password, redis_db) local conn, err = connect_redis(redis_host, redis_password, redis_db) - if not conn then return false end - local _, v + if err then + print(err) + return false + end + local ret for _, v in ipairs(digests) do - local ret, err = conn:add_cmd('HMSET', { + ret, err = conn:add_cmd('HMSET', { 'fuzzy' .. v[1], 'F', v[2], 'V', v[3], @@ -72,10 +75,13 @@ end local function send_shingles(shingles, redis_host, redis_password, redis_db) local conn, err = connect_redis(redis_host, redis_password, redis_db) - if not conn then return false end - local _, v + if err then + print("Redis error: " .. err) + return false + end + local ret for _, v in ipairs(shingles) do - local ret, err = conn:add_cmd('SET', { + ret, err = conn:add_cmd('SET', { 'fuzzy_' .. v[2] .. '_' .. v[1], v[4], }) @@ -102,8 +108,12 @@ end local function update_counters(total, redis_host, redis_password, redis_db) local conn, err = connect_redis(redis_host, redis_password, redis_db) - if not conn then return false end - local ret, err = conn:add_cmd('SET', { + if err then + print(err) + return false + end + local ret + ret, err = conn:add_cmd('SET', { 'fuzzylocal', total, }) @@ -111,7 +121,7 @@ local function update_counters(total, redis_host, redis_password, redis_db) print('Cannot batch SET command: ' .. err) return false end - local ret, err = conn:add_cmd('SET', { + ret, err = conn:add_cmd('SET', { 'fuzzy_count', total, }) @@ -127,7 +137,7 @@ local function update_counters(total, redis_host, redis_password, redis_db) return true end -return function (args, res) +return function (_, res) local db = sqlite3.open(res['source_db']) local shingles = {} local digests = {} diff --git a/src/rspamadm/fuzzy_stat.lua b/src/rspamadm/fuzzy_stat.lua index 864e149a0..401b297d1 100644 --- a/src/rspamadm/fuzzy_stat.lua +++ b/src/rspamadm/fuzzy_stat.lua @@ -47,7 +47,7 @@ local function print_stat(st, tabs) end -- Sort by checked -local function sort_ips(tbl, opts) +local function sort_ips(tbl, _opts) local res = {} for k,v in pairs(tbl) do table.insert(res, {ip = k, data = v}) @@ -55,23 +55,23 @@ local function sort_ips(tbl, opts) local function sort_order(elt) local key = 'checked' - local res = 0 + local _res = 0 - if opts['sort'] then - if opts['sort'] == 'matched' then + if _opts['sort'] then + if _opts['sort'] == 'matched' then key = 'matched' - elseif opts['sort'] == 'errors' then + elseif _opts['sort'] == 'errors' then key = 'errors' - elseif opts['sort'] == 'ip' then + elseif _opts['sort'] == 'ip' then return elt['ip'] end end if elt['data'][key] then - res = elt['data'][key] + _res = elt['data'][key] end - return res + return _res end table.sort(res, function(a, b) @@ -150,7 +150,7 @@ return function(args, res) opts = getopt(args, '') if wrk then - for i,pr in pairs(wrk) do + for _,pr in pairs(wrk) do -- processes cycle if pr['data'] then local id = pr['id'] @@ -227,16 +227,16 @@ return function(args, res) local res_keys = st['keys'] if res_keys and not opts['no-keys'] and not opts['short'] then print('Keys statistics:') - for k,st in pairs(res_keys) do + for k,_st in pairs(res_keys) do print(string.format('Key id: %s', k)) - print_stat(st, '\t') + print_stat(_st, '\t') - if st['ips'] and not opts['no-ips'] then + if _st['ips'] and not opts['no-ips'] then print('') print('\tIPs stat:') - local sorted_ips = sort_ips(st['ips'], opts) + local sorted_ips = sort_ips(_st['ips'], opts) - for i,v in ipairs(sorted_ips) do + for _,v in ipairs(sorted_ips) do print(string.format('\t%s', v['ip'])) print_stat(v['data'], '\t\t') print('') @@ -264,7 +264,7 @@ return function(args, res) print('IPs statistics:') local sorted_ips = sort_ips(res_ips, opts) - for i, v in ipairs(sorted_ips) do + for _, v in ipairs(sorted_ips) do print(string.format('%s', v['ip'])) print_stat(v['data'], '\t') print('') diff --git a/src/rspamadm/stat_convert.lua b/src/rspamadm/stat_convert.lua index bd3e21bd0..5c880d7c5 100644 --- a/src/rspamadm/stat_convert.lua +++ b/src/rspamadm/stat_convert.lua @@ -41,6 +41,7 @@ local function convert_learned(cache, server, password, redis_db) local converted = 0 local db = sqlite3.open(cache) local ret = true + local err_str if not db then print('Cannot open cache database: ' .. cache) @@ -84,7 +85,6 @@ local function convert_learned(cache, server, password, redis_db) end db:sql('COMMIT;') - local err_str if ret then ret,err_str = conn:exec() end @@ -99,7 +99,7 @@ local function convert_learned(cache, server, password, redis_db) return ret end -return function (args, res) +return function (_, res) local db = sqlite3.open(res['source_db']) local tokens = {} local num = 0 @@ -110,8 +110,8 @@ return function (args, res) local learns = {} local redis_password = res['redis_password'] local redis_db = nil - local ret = false local cmd = 'HINCRBY' + local ret, err_str if res['redis_db'] then redis_db = tostring(res['redis_db']) @@ -166,7 +166,7 @@ return function (args, res) num = num + 1 total = total + 1 if num > lim then - local ret,err_str = send_redis(res['redis_host'], res['symbol'], + ret,err_str = send_redis(res['redis_host'], res['symbol'], tokens, redis_password, redis_db, cmd) if not ret then print('Cannot send tokens to the redis server: ' .. err_str) @@ -178,7 +178,7 @@ return function (args, res) end end if #tokens > 0 then - local ret, err_str = send_redis(res['redis_host'], res['symbol'], tokens, + ret, err_str = send_redis(res['redis_host'], res['symbol'], tokens, redis_password, redis_db, cmd) if not ret then |