cronlist — cron jobs, explained in plain words

cronlist — cron jobs, explained in plain words

cronlist is a LightGUI (Python/XFrame) port of the cronlist utility from util_box: list cron jobs with a human-readable explanation of each schedule. Give it a crontab file — or nothing at all, for your own crontab — and it explains every schedule in plain words: "every day at 9:00 am" instead of "0 9 * * *", "every 15 minutes" instead of "*/15 * * * *". It is one of the 285 apps in util_boxgui, the project recreating util_box utilities as LightGUI apps, each with a screenshot and a walkthrough on the matching LightGUI doc site. The full source is apps/python/cronlist/cronlist.py in that repo.

The current crontab is already listed when the app starts, so a plain launch + screenshot shows real jobs. If this user has no crontab at all, a built-in demo crontab — the same three jobs the CLI self-test uses — is shown instead, clearly labelled as a demo. The screenshot below is the default state, not a staged one: this box had no crontab, so the demo is what you see.

The GUI layout

cronlist running under Xvfb
cronlist running — the demo crontab's three jobs, explained in plain words, captured under Xvfb.

The window is 960×560 and holds five widgets, created with create() + set_prop() and drawn on a single Gtk.DrawingArea:

  • Crontab file: a GtkLabel and a GtkEntry holding the path to a crontab file, empty by default. Empty means the current user's crontab (crontab -l). Click the entry to focus it (a blue outline appears), then type — BackSpace deletes, Escape drops focus.
  • List: a GtkButton that lists the jobs in the entry's file (or the current crontab). Enter re-lists, too.
  • Hint line: a GtkLabel explaining that empty means your crontab and that a file path lists that file instead.
  • Result area: a GtkTextView filling the rest of the window, showing one line per job — the plain-words explanation of its schedule, then the command. It is read-only — clicking it just drops the entry's focus.

Two honest limitations, both inherited from how LightGUI draws its widgets with Cairo on one drawing area: there is no native GTK keyboard focus, so this app wires focus and typing itself; and the result area does not really scroll — the text-view scroll bars are drawn, not functional, so a crontab with more jobs than fit the window clips at the bottom. The window was widened from 800 to 960 during testing because at 800 the command column was clipped — and seeing the command next to its explanation is the whole point of the app.

The demo crontab is three jobs, and the result lines are exactly what the CLI prints for the same input:

0 9 * * 1-5 /usr/bin/backup.sh
*/15 * * * * /usr/bin/check.sh
@daily /usr/bin/clean.sh

cron jobs in demo crontab (3):
(no crontab found for this user - showing a demo)
  at minute 0, at hour 9, on 1-5      /usr/bin/backup.sh
  every 15 minutes                    /usr/bin/check.sh
  every day at midnight               /usr/bin/clean.sh

The first explanation is clunky — "at minute 0, at hour 9, on 1-5" — because the explainer builds its sentence field by field and "1-5" is a range, not a named day. That is the CLI's own wording, reproduced exactly.

The source, in sections

cronlist.py is about 385 lines. It is modelled on the LightGUI Python examples gtkentry.py, gtkbutton.py and gtktextview.py (and the datecalc app in this repo): widgets are created with create() + set_prop(), drawn on a Gtk.DrawingArea by widget.draw(cr), hit-tested on click, and dispatched through a _HANDLERS table. The explanation half is vendored verbatim from the CLI, so the GUI can never drift from it.

The explainer. explain() and parse_lines() are copied byte-for-byte from the CLI script into cronlist.py. The explainer works field by field: a plain hour becomes "every day at 9:00 am" (12-hour clock with am/pm), a step becomes "every 15 minutes", month and weekday numbers become names, and the @daily / @hourly shortcuts become their sentences. The parser skips comments and environment assignments, splits each line into its five fields plus the command, and hands the fields to the explainer:

def explain(minute, hour, dom, month, dow):
    if minute == "0" and hour != "*" and dom == "*" and month == "*" and dow == "*":
        h = int(hour) if hour.isdigit() else hour
        ampm = "am" if isinstance(h, int) and h < 12 else "pm"
        h12 = (h % 12) or 12 if isinstance(h, int) else h
        return "every day at %s:00 %s" % (h12, ampm)
    bits = []
    if minute == "0" and hour == "0" and dom == "*" and month == "*" and dow == "*":
        return "every day at midnight"
    if minute.startswith("*/"):
        bits.append("every %s minutes" % minute[2:])
    elif minute != "*":
        bits.append("at minute %s" % minute)
    if hour.startswith("*/"):
        bits.append("every %s hours" % hour[2:])
    elif hour != "*":
        bits.append("at hour %s" % hour)
    if dom != "*":
        bits.append("on day %s of the month" % dom)
    if month != "*":
        bits.append("in %s" % ", ".join(MONTHS.get(m, m) for m in month.split(",")))
    if dow != "*":
        bits.append("on %s" % ", ".join(DAYS.get(d, d) for d in dow.replace("7", "0").split(",")))
    if not bits:
        return "every minute"
    return ", ".join(bits)

compute_text() is the GUI's own half: it reads the entry (empty means crontab -l via subprocess, a path means that file), falls back to the demo crontab when the user has none, and formats each job as the CLI does — explanation left-padded to 55 characters, then the command. A bad file path shows an error line in the result area instead of a traceback.

The widgets. _build_widgets() creates the five widgets with their design-time geometry, and an _ANCHORS table records each widget's anchor flags so _apply_anchors() can reposition them when the window is resized — recomputed from the design geometry every time, so a resize is idempotent and never drifts:

def _build_widgets():
    """Create every placed widget with its props."""
    widgets = []
    widget = create("GtkLabel", "GtkLabel_001", 16, 12, 110, 30)
    widget.set_prop("label", "Crontab file:")
    widgets.append(widget)
    widget = create("GtkEntry", "GtkEntry_001", 130, 12, 400, 30)
    widget.set_prop("text", "")
    widget.set_prop("placeholder-text", "path (empty = crontab -l)")
    widgets.append(widget)
    widget = create("GtkButton", "GtkButton_001", 542, 12, 100, 30)
    widget.set_prop("label", "List")
    widgets.append(widget)
    widget = create("GtkLabel", "GtkLabel_002", 16, 54, 928, 30)
    widget.set_prop("label", "Empty = your crontab (crontab -l). Type a file path to list that file instead.")
    widgets.append(widget)
    widget = create("GtkTextView", "GtkTextView_001", 16, 96, 928, 448)
    widget.set_prop("editable", "false")
    widget.set_prop("scroll-bars", "3")
    widget.set_prop("font-name", "Monospace")
    widget.set_prop("font-size", "13")
    widget.set_prop("text", compute_text(""))
    widgets.append(widget)
    return widgets

The output area is created already holding the listing — that is why the window opens populated. The entry's placeholder text is a hint, not content.

Events. LightGUI draws the widgets with Cairo, so there is no native GTK focus to rely on — the app wires it itself. Clicking the entry focuses it; typing goes to the focused entry through a window-level key-press handler, which appends printable characters, handles BackSpace and Delete, and re-lists on every keystroke (and on Return). Clicking List re-lists and drops focus; clicking the output area just drops focus. The dispatch is a small hit-test: the topmost visible widget containing the click gets the event through the _HANDLERS table, and a button release always goes to the widget that got the press. main() is the standard LightGUI Python harness: a Gtk.Window titled cronlist - util_boxgui holding a Gtk.DrawingArea, with the draw, button-press, button-release and resize signals connected, and Gtk.main() running the loop.

Building and running it

There is nothing to build — it is pure Python. Run it with the LightGUI Python package on PYTHONPATH, under a real X server or under Xvfb (display :97 is the one used for this app). It needs python3-gi / gir1.2-gtk-3.0 and the LightGUI Python checkout:

cd apps/python/cronlist
PYTHONPATH=/root/graphfix-wt/lightgui_python python3 cronlist.py

# Under Xvfb:
Xvfb :97 -screen 0 1024x768x24 &
DISPLAY=:97 PYTHONPATH=/root/graphfix-wt/lightgui_python python3 cronlist.py

The PYTHONPATH above points at the clean graphfix-wt checkout on the build machine — the usual /root/lg-review/lightgui_python checkout is mid-merge as of this writing, so batch 5 was built against the clean one. On your own machine, point it at wherever you cloned LightGUI Python. The window title is cronlist - util_boxgui.

What the CLI version does differently

Same explanation, same lines, same edge cases — and the differences are all about the medium. The CLI is cronlist [--file FILE] [--user USER] [--system] [--selftest] and prints to stdout; the GUI shows the listing in the result area. The GUI has no --user / --system options — it reads the current user's crontab, or a file you type. A bad file path shows an error line instead of the CLI's stderr message. The CLI prints once and exits; the GUI re-lists on every keystroke. Verified on the same input: the demo crontab's three jobs produce identical lines in both.

See also

Source code: git.lightgui.com/thinkmelt/lightgui_python