Skip to content

Commit

Permalink
allow user to specify color of overdue messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Feb 1, 2025
1 parent 0ff7ed5 commit fd68e10
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
8 changes: 8 additions & 0 deletions assimilate/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ def as_bool(arg):
def as_colorscheme(arg):
return arg[1:]

# as_color{{{2
@as_enum(
"'black", "'red", "'green", "'yellow", "'blue",
"'magenta", "'cyan", "'white", "'none"
)
def as_color(arg):
return arg[1:]

# normalize_key {{{2
# converts key to snake case
# downcase; replace whitespace and dashes with underscores
Expand Down
31 changes: 24 additions & 7 deletions assimilate/overdue.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@
from voluptuous import Schema
from .configs import (
add_setting, add_parents_of_non_identifier_keys,
as_emails, as_path, as_abs_path, as_string, as_name
as_color, as_emails, as_path, as_abs_path, as_string, as_name
)
from .preferences import DATA_DIR
from .utilities import output, read_latest, Quantity, Run, to_path
from .utilities import output, read_latest, when, Quantity, InvalidNumber, Run, to_path

# GLOBALS {{{1
username = pwd.getpwuid(os.getuid()).pw_name
Expand All @@ -96,6 +96,7 @@
# colors {{{2
current_color = "green"
overdue_color = "red"
locked_color = "magenta"

# message templates {{{2
verbose_status_message = dedent("""\
Expand Down Expand Up @@ -133,6 +134,9 @@ def as_seconds(arg, units=None):
max_age = as_seconds,
sentinel_root = as_abs_path,
message = as_string,
current_color = as_color,
overdue_color = as_color,
locked_color = as_color,
repositories = {
str: dict(
config = as_name,
Expand Down Expand Up @@ -199,8 +203,12 @@ def get_remote_data(name, host, config, cmd):
repo_data['overdue'] = truth(repo_data['overdue'] == 'yes')
if repo_data.get('hours'):
repo_data['age'] = as_seconds(repo_data['hours'])
del repo_data['hours']
elif repo_data.get('age'):
repo_data['age'] = as_seconds(repo_data['age'])
try:
repo_data['age'] = as_seconds(repo_data['age'])
except InvalidNumber:
repo_data['age'] = as_seconds(0)
if repo_data.get('max_age'):
repo_data['max_age'] = as_seconds(repo_data['max_age'])
repo_data['locked'] = truth(repo_data.get('locked') == 'yes')
Expand All @@ -226,10 +234,14 @@ def overdue(cmdline, args, settings, options):
message = verbose_status_message

report_as_current = InformantFactory(
clone=display, message_color=current_color
clone=display, message_color=od_settings.get("current_color", current_color),
)
report_as_overdue = InformantFactory(
clone=display, message_color=overdue_color,
clone=display, message_color=od_settings.get("overdue_color", overdue_color),
notify=cmdline['--notify'] and not Color.isTTY()
)
report_as_active = InformantFactory(
clone=display, message_color=od_settings.get("locked_color", locked_color),
notify=cmdline['--notify'] and not Color.isTTY()
)

Expand Down Expand Up @@ -276,11 +288,16 @@ def send_mail(recipients, subject, body):


for repo_data in repos_data:
repo_data['updated'] = repo_data['mtime'].humanize()
repo_data['updated'] = when(repo_data['mtime'])
overdue = repo_data['overdue']
locked = repo_data['locked']
description = repo_data['description']
report = report_as_overdue if overdue else report_as_current
if locked:
report = report_as_active
elif overdue:
report = report_as_overdue
else:
report = report_as_current

with Quantity.prefs(spacer=' '):
if overdue or locked or not cmdline["--no-passes"]:
Expand Down
2 changes: 1 addition & 1 deletion assimilate/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def when(time, relative_to=None, as_past=None, as_future=None):
relative_to (datetime):
Time to compare against to form the time difference. If not given,
the current time is used.
as_ast (bool or str):
as_past (bool or str):
If true, the word “ago” will be added to the end of the returned
time difference if it is negative, indicating it occurred in the
past. It it a string, it should contain ‘{}’, which is replaced
Expand Down
22 changes: 22 additions & 0 deletions doc/monitoring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,28 @@ In addition, there are some shared settings available:
- datetimes can include Arrow_ formats, ex: {mtime:DD MMM YY @ H:mm A}
- booleans can include Inform_ true/false strings: {overdue:PAST DUE!/current}

*locked_color*:
The text color to use for repositories that are currently locked. Choose
from:
``'black``, ``'red``, ``'green``, ``'yellow``, ``'blue``, ``'magenta``,
``'cyan``, ``'white``, or ``'none``.
The default is ``'magenta``.

*overdue_color*:
The text color to use for repositories that are currently locked. Choose
from:
``'black``, ``'red``, ``'green``, ``'yellow``, ``'blue``, ``'magenta``,
``'cyan``, ``'white``, or ``'none``.
The default is ``'red``.

*current_color*:
The text color to use for repositories that are currently locked. Choose
from:
``'black``, ``'red``, ``'green``, ``'yellow``, ``'blue``, ``'magenta``,
``'cyan``, ``'white``, or ``'none``.
The default is ``'green``.


To run the program interactively, type:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion tests/assimilate.nt
Original file line number Diff line number Diff line change
Expand Up @@ -4401,7 +4401,7 @@ assimilate:
checks:
stderr:
matches regex:
> test: .* ago
> test: [\d.]+ \w+

locket — overdue --message {{{2:
run: assimilate overdue --message="⟪description⟫\n⟪max_age⟫\n⟪mtime⟫\n⟪age⟫\n⟪updated⟫\n⟪overdue:past due/up to date⟫\n⟪locked:active/not active⟫"
Expand Down

0 comments on commit fd68e10

Please sign in to comment.