2019-09-18 05:26:23 +02:00
|
|
|
-- contrib/countfiles_all.lua
|
|
|
|
-- Copyright (C) 2017 Jörg Thalheim <joerg@higgsboson.tk>
|
|
|
|
--
|
|
|
|
-- This file is part of Vicious.
|
|
|
|
--
|
|
|
|
-- Vicious is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU General Public License as
|
|
|
|
-- published by the Free Software Foundation, either version 2 of the
|
|
|
|
-- License, or (at your option) any later version.
|
|
|
|
--
|
|
|
|
-- Vicious is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU General Public License for more details.
|
|
|
|
--
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
|
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
|
2010-12-19 04:03:48 +01:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local io = { popen = io.popen }
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local pairs = pairs
|
|
|
|
-- }}}
|
|
|
|
|
2011-10-25 20:47:01 +02:00
|
|
|
-- countfiles: provides a number of files in several directories
|
2010-12-19 04:03:48 +01:00
|
|
|
-- @warg.paths a table with the paths which should be checked
|
|
|
|
-- @warg.pattern a global regex to match files (Default: match all)
|
2011-10-25 20:47:01 +02:00
|
|
|
-- use posix-egrep style instead of the default (less familiar) emacs regex
|
2010-12-19 04:03:48 +01:00
|
|
|
|
|
|
|
-- Be carefull with directories, who contains a mass of files.
|
|
|
|
-- "find" is usally fast, but will also produce delays, if the inodes get to big.
|
|
|
|
-- So if you want to count your music library, you may want to use locate/updatedb instead.
|
|
|
|
|
2017-01-25 19:51:05 +01:00
|
|
|
-- vicious.contrib.countfiles
|
|
|
|
local countfiles_all = {}
|
2010-12-19 04:03:48 +01:00
|
|
|
|
|
|
|
-- {{{ Sum up widget type
|
|
|
|
local function worker(format, warg)
|
|
|
|
if not warg then return end
|
|
|
|
-- Initialise counter table
|
|
|
|
local store = {}
|
|
|
|
|
|
|
|
-- Match by default all files
|
|
|
|
warg.pattern = warg.pattern or ".*"
|
|
|
|
|
|
|
|
for key, value in pairs(warg.paths) do
|
|
|
|
local f = io.popen("find '"..value.."'"..
|
|
|
|
" -type f -regextype posix-egrep"..
|
|
|
|
" -regex '"..warg.pattern.."'")
|
|
|
|
|
|
|
|
local lines = 0
|
|
|
|
for line in f:lines() do
|
|
|
|
lines = lines + 1
|
|
|
|
end
|
|
|
|
|
2011-10-25 20:47:01 +02:00
|
|
|
store[key] = (store[key] or 0) + lines
|
2010-12-19 04:03:48 +01:00
|
|
|
|
|
|
|
f:close()
|
|
|
|
end
|
|
|
|
return store
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
2017-01-25 19:51:05 +01:00
|
|
|
setmetatable(countfiles_all, { __call = function(_, ...) return worker(...) end })
|