ENH add indicator for seafile

This commit is contained in:
Nathan Dwarshuis 2023-01-08 12:12:57 -05:00
parent 2ddb317dd3
commit 3436a7f1da
3 changed files with 91 additions and 2 deletions

View File

@ -52,7 +52,11 @@ let AllGeo =
let FileSystem =
{ Type =
{ show_smart : Bool, fs_paths : List FSPath, geometry : FSGeo.Type }
{ show_smart : Bool
, show_seafile : Bool
, fs_paths : List FSPath
, geometry : FSGeo.Type
}
, default.geometry = FSGeo::{=}
}

60
scripts/seafile_status Executable file
View File

@ -0,0 +1,60 @@
#! /bin/env python
# determine the status of the seafile client
import subprocess as sp
import os
SEAF_FILE = "/tmp/.conky_seafile"
CMD = ["seaf-cli", "status"]
# possible statuses (according to the source here: https://github.com/haiwen/seafile/blob/91e5d897395c728a1e862dbdaf3d8a519c2ed73e/daemon/sync-mgr.c#L471)
# ranked in order from least to most severe in terms of "being synced"
STATUS_RANK = [
"synchronized",
"committing",
"initializing",
"downloading",
"merging",
"uploading",
"error",
"canceled",
"cancel pending",
]
def get_conf_dir():
try:
conf_dir = os.environ["CCNET_CONF_DIR"]
return ["-c", conf_dir]
except KeyError:
return []
def collapse_statuses(xs):
try:
return STATUS_RANK[max(STATUS_RANK.index(x) for x in xs)]
except ValueError:
return "unknown"
def query_statuses():
args = get_conf_dir()
res = sp.run(CMD + args, capture_output=True, check=True)
raw = res.stdout.rstrip().split(b"\n")[1:]
statuses = [ln.split(b"\t")[1].strip().decode() for ln in raw]
return collapse_statuses(statuses)
def write_output(status):
with open(SEAF_FILE, "w", encoding="utf8") as f:
f.write(status.capitalize())
def main():
status = query_statuses()
write_output(status)
main()

View File

@ -29,6 +29,28 @@ return function(main_state, config, common, width, point)
)
end
-----------------------------------------------------------------------------
-- seafile
local SEAF_FILE = '/tmp/.conky_seafile'
local mk_seafile = function(y)
local obj = common.make_text_row(point.x, y, width, 'Seafile Daemon')
local update = function()
if main_state.trigger10 == 0 then
local status = i_o.read_file(SEAF_FILE)
common.text_row_set(obj, status)
end
end
return common.mk_acc(
width,
0,
update,
pure.partial(common.text_row_draw_static, obj),
pure.partial(common.text_row_draw_dynamic, obj)
)
end
-----------------------------------------------------------------------------
-- filesystem bar chart
@ -79,7 +101,10 @@ return function(main_state, config, common, width, point)
point = point,
width = width,
set_state = nil,
top = {{mk_smart, config.show_smart, separator_bar_spacing}},
top = {
{mk_smart, config.show_smart, separator_bar_spacing},
{mk_seafile, config.show_seafile, separator_bar_spacing}
},
common.mk_section(separator_bar_spacing, {mk_bars, true, 0})
}
end