diff --git a/config/config.dhall b/config/config.dhall index bce6d66..1d8c1b5 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -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::{=} } diff --git a/scripts/seafile_status b/scripts/seafile_status new file mode 100755 index 0000000..5cefe88 --- /dev/null +++ b/scripts/seafile_status @@ -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() diff --git a/src/modules/filesystem.lua b/src/modules/filesystem.lua index 1e3ae97..e57a7ad 100644 --- a/src/modules/filesystem.lua +++ b/src/modules/filesystem.lua @@ -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