diff options
Diffstat (limited to 'desktop/island/calendar/calctl')
| -rwxr-xr-x | desktop/island/calendar/calctl | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/desktop/island/calendar/calctl b/desktop/island/calendar/calctl index ce98098..a28b20a 100755 --- a/desktop/island/calendar/calctl +++ b/desktop/island/calendar/calctl @@ -18,6 +18,7 @@ # calctl calendars {default, calendars: [{name, color, path}]} # calctl list FROM TO occurrences in [FROM, TO), local time # calctl get UID CAL the series itself, for the editor +# calctl read FILE an outside .ics as a new event, for the editor # calctl new EVENT-JSON {uid} # calctl edit UID CAL EVENT-JSON {uid}; CAL is where it is now # calctl delete UID CAL {} @@ -61,7 +62,7 @@ COLORS = { "cyan": "teal", "dark cyan": "teal", "light cyan": "teal", } -USAGE = ("usage: calctl calendars | list FROM TO | get UID CAL | new JSON" +USAGE = ("usage: calctl calendars | list FROM TO | get UID CAL | read FILE | new JSON" " | edit UID CAL JSON | delete UID CAL") @@ -293,6 +294,28 @@ def cmd_get(uid, cal_name): return to_json(cal, ev, start, end, all_day, overrides()) +def cmd_read(file): + """A dropped .ics (an invite, a booking) as a draft for the editor: no + UID, so saving creates a new event in the default calendar. A rule or + alarm the form cannot show reads `none`: a new event has nothing to keep.""" + try: + ev = master(icalendar.Calendar.from_ical(Path(file).read_bytes())) + except OSError as e: + raise Fail(f"cannot read {file}: {e.strerror}") + except ValueError as e: + raise Fail(f"not a calendar file: {e}") + if ev is None or "DTSTART" not in ev: + raise Fail("no event in that file") + cals, default = calendars() + cal = next(c for c in cals if c["name"] == default) + d = to_json(cal, ev, *span(ev), set()) + d["uid"] = "" + for key in ("repeat", "alarm"): + if d[key] == "custom": + d[key] = "none" + return d + + def parse_payload(text, cals): """The form's JSON, checked. Dates become date/datetime; an all-day end becomes exclusive.""" @@ -470,6 +493,8 @@ def main(argv): data = cmd_list(*args) elif cmd == "get" and len(args) == 2: data = cmd_get(*args) + elif cmd == "read" and len(args) == 1: + data = cmd_read(*args) elif cmd == "new" and len(args) == 1: data = cmd_new(*args) elif cmd == "edit" and len(args) == 3: |
