Merge branch 'master' of pi2:vincent/conf2

This commit is contained in:
vincent 2019-04-25 20:51:44 +02:00
commit 48f52312a7
6 changed files with 232 additions and 35 deletions

View File

@ -24,11 +24,11 @@ If you want to create a pull request, make sure that:
- Your code fits with the general style of the module. In particular, you should use the same indentation pattern that the code uses, and also avoid adding space at the ends of lines. - Your code fits with the general style of the module. In particular, you should use the same indentation pattern that the code uses, and also avoid adding space at the ends of lines.
- Your code its easy to understand, maintainable, and modularized. You should also avoid code duplication wherever possible by adding functions to or using lain.helpers_. If something is unclear, or you can't write it in such a way that it will be clear, explain it with a comment. - Your code its easy to understand, maintainable, and modularized. You should also avoid code duplication wherever possible by adding functions to or using lain.helpers_. If something is unclear, or you can not write it in such a way that it will be clear, explain it with a comment.
- You test your changes before submitting to make sure that you code works and does not break other parts of the module. - You test your changes before submitting to make sure that you code works and does not break other parts of the module.
- You eventually update ``wiki`` submodule with a thorough section. - You update ``wiki`` submodule with a thorough section, if necessary.
Contributed widgets have to be put in ``widget/contrib``. Contributed widgets have to be put in ``widget/contrib``.

View File

@ -14,6 +14,7 @@ local os = os
local pairs = pairs local pairs = pairs
local string = string local string = string
local tconcat = table.concat local tconcat = table.concat
local type = type
local tonumber = tonumber local tonumber = tonumber
local tostring = tostring local tostring = tostring
@ -27,12 +28,22 @@ local function factory(args)
week_start = args.week_start or 2, week_start = args.week_start or 2,
three = args.three or false, three = args.three or false,
followtag = args.followtag or false, followtag = args.followtag or false,
week_number = args.week_number or "none",
week_number_format = args.week_number_format or args.week_number == "left" and "%3d | " or "| %-3d",
icons = args.icons or helpers.icons_dir .. "cal/white/", icons = args.icons or helpers.icons_dir .. "cal/white/",
notification_preset = args.notification_preset or { notification_preset = args.notification_preset or {
font = "Monospace 10", fg = "#FFFFFF", bg = "#000000" font = "Monospace 10", fg = "#FFFFFF", bg = "#000000"
} }
} }
function cal.get_week_number(m, st_day, x)
return string.format(cal.week_number_format, os.date("%V", m) + (x ~= 0 and floor((x + st_day) / 7) - 1 or 0))
end
function cal.sum_week_days(x, y)
return (x + y) % 7
end
function cal.build(month, year) function cal.build(month, year)
local current_month, current_year = tonumber(os.date("%m")), tonumber(os.date("%Y")) local current_month, current_year = tonumber(os.date("%m")), tonumber(os.date("%Y"))
local is_current_month = (not month or not year) or (month == current_month and year == current_year) local is_current_month = (not month or not year) or (month == current_month and year == current_year)
@ -43,13 +54,47 @@ local function factory(args)
local notifytable = { [1] = string.format("%s%s\n", string.rep(" ", floor((28 - this_month:len())/2)), markup.bold(this_month)) } local notifytable = { [1] = string.format("%s%s\n", string.rep(" ", floor((28 - this_month:len())/2)), markup.bold(this_month)) }
for x = 0,6 do notifytable[#notifytable+1] = os.date("%a ", os.time { year=2006, month=1, day=x+cal.week_start }) end for x = 0,6 do notifytable[#notifytable+1] = os.date("%a ", os.time { year=2006, month=1, day=x+cal.week_start }) end
notifytable[#notifytable] = string.format("%s\n%s", notifytable[#notifytable]:sub(1, -2), string.rep(" ", st_day*4)) notifytable[#notifytable] = string.format("%s\n%s", notifytable[#notifytable]:sub(1, -2), string.rep(" ", st_day*4))
local strx
for x = 1,mth_days do for x = 1,mth_days do
local strx = x ~= today and x or markup.bold(markup.color(cal.notification_preset.bg, cal.notification_preset.fg, x) .. " ") strx = x
if x == today then
if x < 10 then x = " " .. x end
strx = markup.bold(markup.color(cal.notification_preset.bg, cal.notification_preset.fg, x) .. " ")
end
strx = string.format("%s%s", string.rep(" ", 3 - tostring(x):len()), strx) strx = string.format("%s%s", string.rep(" ", 3 - tostring(x):len()), strx)
notifytable[#notifytable+1] = string.format("%-4s%s", strx, (x+st_day)%7==0 and x ~= mth_days and "\n" or "") notifytable[#notifytable+1] = string.format("%-4s%s", strx, (x+st_day)%7==0 and x ~= mth_days and "\n" or "")
end end
if string.len(cal.icons or "") > 0 and today then cal.icon = cal.icons .. today .. ".png" end if string.len(cal.icons or "") > 0 and today then cal.icon = cal.icons .. today .. ".png" end
cal.month, cal.year = d.month, d.year cal.month, cal.year = d.month, d.year
if cal.week_number ~= "none" then
local m = os.time { year = year or current_year, month = month and month or current_month, day = 0 }
local head_prepend = string.rep(" ", tostring(string.format(cal.week_number_format, 0)):len())
if cal.week_number == "left" then
notifytable[1] = head_prepend .. notifytable[1] -- month-year row
notifytable[2] = head_prepend .. notifytable[2] -- weekdays row
notifytable[8] = notifytable[8]:gsub("\n", "\n" .. cal.get_week_number(m, st_day, 0)) -- first week of the month
for x = 10,#notifytable do
if cal.sum_week_days(st_day, x) == 2 then
notifytable[x] = cal.get_week_number(m, st_day, x) .. notifytable[x]
end
end
elseif cal.week_number == "right" then
notifytable[8] = notifytable[8]:gsub("\n", head_prepend .. "\n") -- weekdays row
for x = 9,#notifytable do
if cal.sum_week_days(st_day, x) == 1 then
notifytable[x] = notifytable[x]:gsub("\n", cal.get_week_number(m, st_day, x - 7) .. "\n")
end
end
-- last week of the month
local end_days = cal.sum_week_days(st_day, mth_days)
if end_days ~= 0 then end_days = 7 - end_days end
notifytable[#notifytable] = notifytable[#notifytable] .. string.rep(" ", 4 * end_days) .. cal.get_week_number(m, st_day, mth_days + end_days)
end
end
return notifytable return notifytable
end end
@ -80,7 +125,7 @@ local function factory(args)
cal.notification = nil cal.notification = nil
end end
function cal.show(timeout, month, year, scr) function cal.show(seconds, month, year, scr)
cal.notification_preset.text = tconcat(cal.build(month, year)) cal.notification_preset.text = tconcat(cal.build(month, year))
if cal.three then if cal.three then
@ -98,7 +143,7 @@ local function factory(args)
preset = cal.notification_preset, preset = cal.notification_preset,
screen = cal.followtag and awful.screen.focused() or scr or 1, screen = cal.followtag and awful.screen.focused() or scr or 1,
icon = cal.icon, icon = cal.icon,
timeout = timeout or cal.notification_preset.timeout or 5 timeout = type(seconds) == "number" and seconds or cal.notification_preset.timeout or 5
} }
end end

View File

@ -0,0 +1,147 @@
--[[
Licensed under GNU General Public License v2
* (c) 2018, Luca CPZ
* (c) 2013, Conor Heine
--]]
local helpers = require("lain.helpers")
local focused = require("awful.screen").focused
local gears = require("gears")
local naughty = require("naughty")
local wibox = require("wibox")
local string = string
local type = type
-- ThinkPad battery infos and widget creator
-- http://www.thinkwiki.org/wiki/Tp_smapi
-- lain.widget.contrib.tp_smapi
local function factory(apipath)
local tp_smapi = {
path = apipath or "/sys/devices/platform/smapi"
}
function tp_smapi.get(batid, feature)
return helpers.first_line(string.format("%s/%s/%s", tp_smapi.path, batid or "BAT0", feature or ""))
end
function tp_smapi.installed(batid)
return tp_smapi.get(batid, "installed") == "1"
end
function tp_smapi.status(batid)
return tp_smapi.get(batid, "state")
end
function tp_smapi.percentage(batid)
return tp_smapi.get(batid, "remaining_percent")
end
-- either running or charging time
function tp_smapi.time(batid)
local status = tp_smapi.status(batid)
local mins_left = tp_smapi.get(batid, string.match(string.lower(status), "discharging") and "remaining_running_time" or "remaining_charging_time")
if not string.find(mins_left, "^%d+") then return "N/A" end
return string.format("%02d:%02d", math.floor(mins_left / 60), mins_left % 60) -- HH:mm
end
function tp_smapi.hide()
if not tp_smapi.notification then return end
naughty.destroy(tp_smapi.notification)
tp_smapi.notification = nil
end
function tp_smapi.show(batid, seconds, scr)
if not tp_smapi.installed(batid) then return end
local mfgr = tp_smapi.get(batid, "manufacturer") or "no_mfgr"
local model = tp_smapi.get(batid, "model") or "no_model"
local chem = tp_smapi.get(batid, "chemistry") or "no_chem"
local status = tp_smapi.get(batid, "state")
local time = tp_smapi.time(batid)
local msg = ""
if status and status ~= "idle" then
msg = string.format("[%s] %s %s", status, time ~= "N/A" and time or "unknown remaining time",
string.lower(status):gsub(" ", ""):gsub("\n", "") == "charging" and " until charged" or " remaining")
else
msg = "On AC power"
end
tp_smapi.hide()
tp_smapi.notification = naughty.notify {
title = string.format("%s: %s %s (%s)", batid, mfgr, model, chem),
text = msg,
timeout = type(seconds) == "number" and seconds or 0,
screen = scr or focused()
}
end
function tp_smapi.create_widget(args)
local args = args or {}
local pspath = args.pspath or "/sys/class/power_supply/"
local batteries = args.batteries or (args.battery and {args.battery}) or {}
local timeout = args.timeout or 30
local settings = args.settings or function() end
if #batteries == 0 then
helpers.line_callback("ls -1 " .. pspath, function(line)
local bstr = string.match(line, "BAT%w+")
if bstr then batteries[#batteries + 1] = bstr end
end)
end
local all_batteries_installed = true
for i, battery in ipairs(batteries) do
if not tp_smapi.installed(battery) then
naughty.notify {
preset = naughty.config.critical,
title = "tp_smapi: error while creating widget",
text = string.format("battery %s is not installed", battery)
}
all_batteries_installed = false
break
end
end
if not all_batteries_installed then return end
tpbat = {
batteries = batteries,
widget = args.widget or wibox.widget.textbox()
}
function tpbat.update()
tpbat_now = {
n_status = {},
n_perc = {},
n_time = {},
status = "N/A"
}
for i = 1, #batteries do
tpbat_now.n_status[i] = tp_smapi.status(batteries[i]) or "N/A"
tpbat_now.n_perc[i] = tp_smapi.percentage(batteries[i])
tpbat_now.n_time[i] = tp_smapi.time(batteries[i]) or "N/A"
if not tpbat_now.n_status[i]:lower():match("full") then
tpbat_now.status = tpbat_now.n_status[i]
end
end
widget = tpbat.widget -- backwards compatibility
settings()
end
helpers.newtimer("thinkpad-batteries", timeout, tpbat.update)
return tpbat
end
return tp_smapi
end
return factory

View File

@ -15,6 +15,7 @@ local naughty = require("naughty")
local math = math local math = math
local string = string local string = string
local tconcat = table.concat local tconcat = table.concat
local type = type
local tonumber = tonumber local tonumber = tonumber
local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
@ -45,7 +46,7 @@ local function factory(args)
fs.notification_preset.screen = fs.followtag and focused() or scr or 1 fs.notification_preset.screen = fs.followtag and focused() or scr or 1
fs.notification = naughty.notify { fs.notification = naughty.notify {
preset = fs.notification_preset, preset = fs.notification_preset,
timeout = seconds or 5 timeout = type(seconds) == "number" and seconds or 5
} }
end end
@ -68,8 +69,9 @@ local function factory(args)
end end
function fs.update() function fs.update()
local notifytable = { [1] = string.format("%-10s %-5s %s\t%s\t\n", "path", "used", "free", "size") } local notifytable = { [1] = string.format("%-10s %4s\t%6s\t%6s\t\n", "path", "used", "free", "size") }
local pathlen = 10 local pathlen = 10
local maxpathidx = 1
fs_now = {} fs_now = {}
for _, mount in ipairs(Gio.unix_mounts_get()) do for _, mount in ipairs(Gio.unix_mounts_get()) do
@ -94,11 +96,14 @@ local function factory(args)
} }
if fs_now[path].percentage > 0 then -- don't notify unused file systems if fs_now[path].percentage > 0 then -- don't notify unused file systems
notifytable[#notifytable+1] = string.format("\n%-10s %-5s %.2f\t%.2f\t%s", path, notifytable[#notifytable+1] = string.format("\n%-10s %3s%%\t%6.2f\t%6.2f\t%s", path,
fs_now[path].percentage .. "%", fs_now[path].free, fs_now[path].size, math.floor(fs_now[path].percentage), fs_now[path].free, fs_now[path].size,
fs_now[path].units) fs_now[path].units)
pathlen = math.max(pathlen, #path) if #path > pathlen then
pathlen = #path
maxpathidx = #notifytable
end
end end
end end
end end
@ -120,10 +125,13 @@ local function factory(args)
end end
end end
if pathlen > 10 then -- formatting aesthetics if pathlen > 10 then -- if are there paths longer than 10 chars, reformat first column accordingly
local pathspaces
for i = 1, #notifytable do for i = 1, #notifytable do
local pathspaces = notifytable[i]:match("/%w*[/%w*]*%s*") or notifytable[i]:match("path%s*") pathspaces = notifytable[i]:match("[ ]+")
notifytable[i] = notifytable[i]:gsub(pathspaces, pathspaces .. string.rep(" ", pathlen - 10) .. "\t") if i ~= maxpathidx and pathspaces then
notifytable[i] = notifytable[i]:gsub(pathspaces, pathspaces .. string.rep(" ", pathlen - 10))
end
end end
end end

View File

@ -13,6 +13,7 @@ local wibox = require("wibox")
local math = math local math = math
local os = os local os = os
local string = string local string = string
local type = type
local tonumber = tonumber local tonumber = tonumber
-- OpenWeatherMap -- OpenWeatherMap
@ -51,7 +52,7 @@ local function factory(args)
weather.icon_path = icons_path .. "na.png" weather.icon_path = icons_path .. "na.png"
weather.icon = wibox.widget.imagebox(weather.icon_path) weather.icon = wibox.widget.imagebox(weather.icon_path)
function weather.show(t_out) function weather.show(seconds)
weather.hide() weather.hide()
if followtag then if followtag then
@ -63,12 +64,12 @@ local function factory(args)
weather.forecast_update() weather.forecast_update()
end end
weather.notification = naughty.notify({ weather.notification = naughty.notify {
preset = notification_preset,
text = weather.notification_text, text = weather.notification_text,
icon = weather.icon_path, icon = weather.icon_path,
timeout = t_out, timeout = type(seconds == "number") and seconds or notification_preset.timeout
preset = notification_preset }
})
end end
function weather.hide() function weather.hide()

View File

@ -1,17 +1,13 @@
#!/bin/bash #!/bin/bash
# Inspiré d'un script trouvé sur phpnews.fr (plus en ligne) # Inspiré d'un script trouvé sur phpnews.fr (plus en ligne)
# Version 0.3 13/05/2013 # Version 0.3 13/05/2013
# Script sous licence BEERWARE
# Script sous licence BEERWARE
set -eu set -eu
## Paramètres ## Paramètres
USER='dump' USER='dump'
PASS='wg4KAKkbywiLs8pQ' PASS='wg4KAKkbywiLs8pQ'
# Répertoire de stockage des sauvegardes # Répertoire de stockage des sauvegardes
DATADIR="/mnt/backup/mysql" DATADIR="/mnt/diskstation/git/backup/mysql/"
# Répertoire de travail (création/compression) # Répertoire de travail (création/compression)
DATATMP=$DATADIR DATATMP=$DATADIR
# Nom du dump # Nom du dump
@ -22,7 +18,7 @@ COMPRESSIONEXT=".tar.gz"
# Rétention / rotation des sauvegardes # Rétention / rotation des sauvegardes
RETENTION=30 RETENTION=30
# Exclure des bases # Exclure des bases
EXCLUSIONS='(information_schema|performance_schema)' EXCLUSIONS='(information_schema|performance_schema|mysql)'
# Email pour les erreurs (0 pour désactiver # Email pour les erreurs (0 pour désactiver
EMAIL=0 EMAIL=0
# Log d'erreur # Log d'erreur
@ -41,7 +37,7 @@ function cleanup {
trap cleanup EXIT trap cleanup EXIT
# On crée sur le disque un répertoire temporaire # On crée sur le disque un répertoire temporaire
mkdir -p ${DATATMP}/${DATANAME} mkdir -p ${DATATMP}/last
# On place dans un tableau le nom de toutes les bases de données du serveur # On place dans un tableau le nom de toutes les bases de données du serveur
databases="$(mysql -u $USER -p$PASS -Bse 'show databases' | grep -v -E $EXCLUSIONS)" databases="$(mysql -u $USER -p$PASS -Bse 'show databases' | grep -v -E $EXCLUSIONS)"
@ -50,12 +46,12 @@ databases="$(mysql -u $USER -p$PASS -Bse 'show databases' | grep -v -E $EXCLUSIO
for database in ${databases[@]} for database in ${databases[@]}
do do
echo "dump : $database" echo "dump : $database"
mysqldump -u $USER -p$PASS --quick --add-locks --lock-tables --extended-insert $database > ${DATATMP}/${DATANAME}/${database}.sql mysqldump -u $USER -p$PASS --quick --add-locks --lock-tables --extended-insert $database > ${DATATMP}/last/${database}.sql
done done
# On tar tous # On tar tous
cd ${DATATMP} cd ${DATATMP}
${COMPRESSIONCMD} ${DATANAME}${COMPRESSIONEXT} ${DATANAME}/ ${COMPRESSIONCMD} ${DATANAME}${COMPRESSIONEXT} last/
chmod 600 ${DATANAME}${COMPRESSIONEXT} chmod 600 ${DATANAME}${COMPRESSIONEXT}
# On le déplace dans le répertoire # On le déplace dans le répertoire
@ -64,14 +60,14 @@ if [ "$DATATMP" != "$DATADIR" ] ; then
fi fi
# Lien symbolique sur la dernier version # Lien symbolique sur la dernier version
cd ${DATADIR} #cd ${DATADIR}
set +eu #set +eu
unlink last${COMPRESSIONEXT} #unlink last${COMPRESSIONEXT}
set -eu #set -eu
ln ${DATANAME}${COMPRESSIONEXT} last${COMPRESSIONEXT} #ln ${DATANAME}${COMPRESSIONEXT} last${COMPRESSIONEXT}
# On supprime le répertoire temporaire # On supprime le répertoire temporaire
rm -rf ${DATATMP}/${DATANAME} #rm -rf ${DATATMP}/${DATANAME}
echo "Suppression des vieux backup : " echo "Suppression des vieux backup : "
find ${DATADIR} -name "*${COMPRESSIONEXT}" -mtime +${RETENTION} -print -exec rm {} \; find ${DATADIR} -name "*${COMPRESSIONEXT}" -mtime +${RETENTION} -print -exec rm {} \;