From fef6cb3c1952e66126e8496d6b51ae62c91e698e Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 19 Jul 2022 22:55:17 -0400 Subject: [PATCH] ENH make fallback more minimal --- config/fallback.yml | 46 ++++++------------------------------ config/schema.yml | 2 +- conky.conf | 57 +++++++++++++++++++++++++++++---------------- core | 2 +- 4 files changed, 46 insertions(+), 61 deletions(-) diff --git a/config/fallback.yml b/config/fallback.yml index 3d1ddde..5521547 100644 --- a/config/fallback.yml +++ b/config/fallback.yml @@ -2,55 +2,23 @@ bootstrap: update_interval: 1 dimensions: [1920, 1080] modules: - filesystem: - show_smart: true - fs_paths: - - {path: /, name: root} - - {path: /boot, name: boot} - - {path: /home, name: home} - - {path: /mnt/data, name: data} - - {path: /mnt/dcache, name: dcache} - - {path: /tmp, name: tmpfs} - graphics: - show_temp: true - show_clock: true - show_gpu_util: true - show_mem_util: true - show_vid_util: true memory: - show_stats: true - show_swap: true + show_stats: false + show_swap: false show_plot: true - table_rows: 5 - power: - battery: BAT0 - rapl_specs: - - {name: PKG0, address: intel-rapl:0} - - {name: DRAM, address: intel-rapl:0:2} + table_rows: 3 processor: - core_rows: 1 + core_rows: 0 core_padding: 0 - show_stats: true + show_stats: false show_plot: true - table_rows: 5 - readwrite: - devices: [sda, nvme0n1] + table_rows: 3 layout: anchor: [12, 11] panels: - columns: - - {blocks: [system, 19, graphics, 16, processor], width: 436} - margins: [20, 10] - - 10 - - columns: - - {blocks: [readwrite], width: 436} - - 20 - - {blocks: [network], width: 436} - margins: [20, 10] - - 10 - - columns: - - {blocks: [pacman, 24, filesystem, 23, power, 19, memory], width: 436} + - {blocks: [network, 10, memory, 10, processor], width: 436} margins: [20, 10] theme: diff --git a/config/schema.yml b/config/schema.yml index 9c12ad9..76c64c0 100644 --- a/config/schema.yml +++ b/config/schema.yml @@ -20,8 +20,8 @@ properties: type: integer minimum: 1 + # NOTE none of these are required modules: - required: [filesystem, graphics, memory, power, processor, readwrite] additionalProperties: false properties: filesystem: diff --git a/conky.conf b/conky.conf index 464e991..2820847 100644 --- a/conky.conf +++ b/conky.conf @@ -32,32 +32,49 @@ local yaml = require 'lyaml' local i_o = require 'i_o' local schema_path = conky_dir..'/config/schema.yml' +local validate_config -local try_config_paths = { - '/home/ndwar/.config/conky.yml', - conky_dir..'config/fallback.yml' -} -local config_path -local config - -for i = 1, #try_config_paths do - config_path = try_config_paths[i] - local r = i_o.read_file(config_path) - if r ~= nil then - config = yaml.load(r) - break +if i_o.exe_exists('yajsv') then + validate_config = function(config_path) + local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path) + return i_o.exit_code_cmd(cmd) == 0 + end +else + validate_config = function(_) + print('WARNING: could not validate config') + return true end end -i_o.printf('Using config at %s', config_path) - -if i_o.exit_code_cmd('command -v yajsv > /dev/null') == 0 then - local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path) - assert(i_o.exit_code_cmd(cmd) == 0, 'ERROR: config failed validation') -else - print(string.format('WARNING: could not validate config')) +local find_valid_config = function(paths) + for i = 1, #paths do + local path = paths[i] + local r = i_o.read_file(path) + if r ~= nil then + if validate_config(path) then + i_o.printf('INFO: Using config at %s', path) + return path, yaml.load(r) + else + i_o.printf('WARNING: %s did not pass; trying next', path) + end + else + i_o.printf('INFO: could not find %s; trying next', path) + end + end + assert(false, 'ERROR: could not load valid config') end +local get_config_dir = function() + return (os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME")..'/.config')..'/' +end + +local try_config_paths = { + get_config_dir()..'conky.ymll', + conky_dir..'config/fallback.yml' +} + +local config_path, config = find_valid_config(try_config_paths) + local bootstrap = config.bootstrap local startup_hook = string.format( diff --git a/core b/core index 8f14951..2924a61 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 8f1495175f08bdc0716ef11b73d3babb10874c8b +Subproject commit 2924a6118d4fe30f3005800d65f6c378305f7c61