-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #17
- Loading branch information
Showing
11 changed files
with
730 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package adapters | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/akamensky/argparse" | ||
"github.com/dploeger/icarus/v2/pkg/processors" | ||
"github.com/emersion/go-ical" | ||
) | ||
|
||
// The FilterAdapter filters the calendar for selected events | ||
type MergeAdapter struct { | ||
toolbox processors.Toolbox | ||
mergeCalendar *os.File | ||
overwrite *bool | ||
mergeProps *[]string | ||
} | ||
|
||
func (a *MergeAdapter) Initialize(parser *argparse.Parser) (*argparse.Command, error) { | ||
command := parser.NewCommand("merge", "Merge another calendar into the input calendar. The filter options work on the additional calendar for this comand.") | ||
a.mergeCalendar = command.File("I", "merge-calendar", os.O_RDONLY, 0600, &argparse.Options{ | ||
Help: "Calendar to merge into the input calendar", | ||
Required: true, | ||
}) | ||
a.overwrite = command.Flag("O", "overwrite", &argparse.Options{ | ||
Help: "Overwrite events in the input calendar with those from the other calendar", | ||
}) | ||
a.mergeProps = command.StringList("P", "merge-props", &argparse.Options{ | ||
Help: "The ical event properties which decide if two events are the same", | ||
Default: []string{ical.PropSummary, ical.PropDateTimeStart, ical.PropDateTimeEnd}, | ||
}) | ||
return command, nil | ||
} | ||
|
||
func (a *MergeAdapter) Process(input ical.Calendar, output *ical.Calendar) error { | ||
var mergeCalendar ical.Calendar | ||
dec := ical.NewDecoder(a.mergeCalendar) | ||
if cal, err := dec.Decode(); err != nil { | ||
return err | ||
} else { | ||
mergeCalendar = *cal | ||
} | ||
p := processors.NewMergeProcessor(mergeCalendar) | ||
p.MergeProps = *a.mergeProps | ||
if *a.overwrite { | ||
p.MergeOption = processors.MergeOptionOverWrite | ||
} | ||
p.SetToolbox(a.toolbox) | ||
return p.Process(input, output) | ||
} | ||
|
||
func (f *MergeAdapter) SetToolbox(toolbox processors.Toolbox) { | ||
f.toolbox = toolbox | ||
} | ||
|
||
var _ Adapter = &MergeAdapter{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
stdin example.ics | ||
exec icarus merge -I examplemerge.ics | ||
! stderr . | ||
stdout 'SUMMARY:Test\r\n' | ||
stdout 'SUMMARY:Test3\r\n' | ||
|
||
-- example.ics -- | ||
BEGIN:VCALENDAR | ||
CALSCALE:GREGORIAN | ||
PRODID:-//Apple Inc.//macOS 14.2.1//EN | ||
VERSION:2.0 | ||
X-APPLE-CALENDAR-COLOR:#1BADF8 | ||
X-WR-CALNAME:example | ||
BEGIN:VTIMEZONE | ||
TZID:Europe/Berlin | ||
BEGIN:DAYLIGHT | ||
DTSTART:19810329T020000 | ||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU | ||
TZNAME:MESZ | ||
TZOFFSETFROM:+0100 | ||
TZOFFSETTO:+0200 | ||
END:DAYLIGHT | ||
BEGIN:STANDARD | ||
DTSTART:19961027T030000 | ||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU | ||
TZNAME:MEZ | ||
TZOFFSETFROM:+0200 | ||
TZOFFSETTO:+0100 | ||
END:STANDARD | ||
END:VTIMEZONE | ||
BEGIN:VEVENT | ||
CREATED:20240123T214815Z | ||
DTEND;TZID=Europe/Berlin:20240123T113000 | ||
DTSTAMP:20240123T214844Z | ||
DTSTART;TZID=Europe/Berlin:20240123T101500 | ||
LAST-MODIFIED:20240123T214815Z | ||
SEQUENCE:0 | ||
SUMMARY:Test | ||
TRANSP:OPAQUE | ||
UID:B9243EBE-1F38-477B-A21C-D9C0BD61C025 | ||
X-APPLE-CREATOR-IDENTITY:com.apple.calendar | ||
X-APPLE-CREATOR-TEAM-IDENTITY:0000000000 | ||
BEGIN:VALARM | ||
ACTION:NONE | ||
TRIGGER;VALUE=DATE-TIME:19760401T005545Z | ||
END:VALARM | ||
END:VEVENT | ||
BEGIN:VEVENT | ||
CREATED:20240123T214829Z | ||
DTEND;VALUE=DATE:20240125 | ||
DTSTAMP:20240123T214844Z | ||
DTSTART;VALUE=DATE:20240124 | ||
LAST-MODIFIED:20240123T214829Z | ||
SEQUENCE:0 | ||
SUMMARY:Test2 | ||
TRANSP:TRANSPARENT | ||
UID:87C40F70-6E3F-4409-B8DC-874BA54C4048 | ||
X-APPLE-CREATOR-IDENTITY:com.apple.calendar | ||
X-APPLE-CREATOR-TEAM-IDENTITY:0000000000 | ||
BEGIN:VALARM | ||
ACTION:NONE | ||
TRIGGER;VALUE=DATE-TIME:19760401T005545Z | ||
END:VALARM | ||
END:VEVENT | ||
END:VCALENDAR | ||
|
||
-- examplemerge.ics -- | ||
BEGIN:VCALENDAR | ||
CALSCALE:GREGORIAN | ||
PRODID:-//Apple Inc.//macOS 14.2.1//EN | ||
VERSION:2.0 | ||
X-APPLE-CALENDAR-COLOR:#1BADF8 | ||
X-WR-CALNAME:example | ||
BEGIN:VTIMEZONE | ||
TZID:Europe/Berlin | ||
BEGIN:DAYLIGHT | ||
DTSTART:19810329T020000 | ||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU | ||
TZNAME:MESZ | ||
TZOFFSETFROM:+0100 | ||
TZOFFSETTO:+0200 | ||
END:DAYLIGHT | ||
BEGIN:STANDARD | ||
DTSTART:19961027T030000 | ||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU | ||
TZNAME:MEZ | ||
TZOFFSETFROM:+0200 | ||
TZOFFSETTO:+0100 | ||
END:STANDARD | ||
END:VTIMEZONE | ||
BEGIN:VEVENT | ||
CREATED:20240123T214815Z | ||
DTEND;TZID=Europe/Berlin:20240223T113000 | ||
DTSTAMP:20240123T214844Z | ||
DTSTART;TZID=Europe/Berlin:20240223T101500 | ||
LAST-MODIFIED:20240123T214815Z | ||
SEQUENCE:0 | ||
SUMMARY:Test3 | ||
TRANSP:OPAQUE | ||
UID:B9243EBE-1F38-477B-A21C-D9C0BD61C025 | ||
X-APPLE-CREATOR-IDENTITY:com.apple.calendar | ||
X-APPLE-CREATOR-TEAM-IDENTITY:0000000000 | ||
BEGIN:VALARM | ||
ACTION:NONE | ||
TRIGGER;VALUE=DATE-TIME:19760401T005545Z | ||
END:VALARM | ||
END:VEVENT | ||
END:VCALENDAR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
stdin example.ics | ||
exec icarus merge -I examplemerge.ics -s Test3 | ||
! stderr . | ||
stdout 'SUMMARY:Test\r\n' | ||
stdout 'SUMMARY:Test3\r\n' | ||
! stdout 'SUMMARY:Test4\r\n' | ||
|
||
-- example.ics -- | ||
BEGIN:VCALENDAR | ||
CALSCALE:GREGORIAN | ||
PRODID:-//Apple Inc.//macOS 14.2.1//EN | ||
VERSION:2.0 | ||
X-APPLE-CALENDAR-COLOR:#1BADF8 | ||
X-WR-CALNAME:example | ||
BEGIN:VTIMEZONE | ||
TZID:Europe/Berlin | ||
BEGIN:DAYLIGHT | ||
DTSTART:19810329T020000 | ||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU | ||
TZNAME:MESZ | ||
TZOFFSETFROM:+0100 | ||
TZOFFSETTO:+0200 | ||
END:DAYLIGHT | ||
BEGIN:STANDARD | ||
DTSTART:19961027T030000 | ||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU | ||
TZNAME:MEZ | ||
TZOFFSETFROM:+0200 | ||
TZOFFSETTO:+0100 | ||
END:STANDARD | ||
END:VTIMEZONE | ||
BEGIN:VEVENT | ||
CREATED:20240123T214815Z | ||
DTEND;TZID=Europe/Berlin:20240123T113000 | ||
DTSTAMP:20240123T214844Z | ||
DTSTART;TZID=Europe/Berlin:20240123T101500 | ||
LAST-MODIFIED:20240123T214815Z | ||
SEQUENCE:0 | ||
SUMMARY:Test | ||
TRANSP:OPAQUE | ||
UID:B9243EBE-1F38-477B-A21C-D9C0BD61C025 | ||
X-APPLE-CREATOR-IDENTITY:com.apple.calendar | ||
X-APPLE-CREATOR-TEAM-IDENTITY:0000000000 | ||
BEGIN:VALARM | ||
ACTION:NONE | ||
TRIGGER;VALUE=DATE-TIME:19760401T005545Z | ||
END:VALARM | ||
END:VEVENT | ||
BEGIN:VEVENT | ||
CREATED:20240123T214829Z | ||
DTEND;VALUE=DATE:20240125 | ||
DTSTAMP:20240123T214844Z | ||
DTSTART;VALUE=DATE:20240124 | ||
LAST-MODIFIED:20240123T214829Z | ||
SEQUENCE:0 | ||
SUMMARY:Test2 | ||
TRANSP:TRANSPARENT | ||
UID:87C40F70-6E3F-4409-B8DC-874BA54C4048 | ||
X-APPLE-CREATOR-IDENTITY:com.apple.calendar | ||
X-APPLE-CREATOR-TEAM-IDENTITY:0000000000 | ||
BEGIN:VALARM | ||
ACTION:NONE | ||
TRIGGER;VALUE=DATE-TIME:19760401T005545Z | ||
END:VALARM | ||
END:VEVENT | ||
END:VCALENDAR | ||
|
||
-- examplemerge.ics -- | ||
BEGIN:VCALENDAR | ||
CALSCALE:GREGORIAN | ||
PRODID:-//Apple Inc.//macOS 14.2.1//EN | ||
VERSION:2.0 | ||
X-APPLE-CALENDAR-COLOR:#1BADF8 | ||
X-WR-CALNAME:example | ||
BEGIN:VTIMEZONE | ||
TZID:Europe/Berlin | ||
BEGIN:DAYLIGHT | ||
DTSTART:19810329T020000 | ||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU | ||
TZNAME:MESZ | ||
TZOFFSETFROM:+0100 | ||
TZOFFSETTO:+0200 | ||
END:DAYLIGHT | ||
BEGIN:STANDARD | ||
DTSTART:19961027T030000 | ||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU | ||
TZNAME:MEZ | ||
TZOFFSETFROM:+0200 | ||
TZOFFSETTO:+0100 | ||
END:STANDARD | ||
END:VTIMEZONE | ||
BEGIN:VEVENT | ||
CREATED:20240123T214815Z | ||
DTEND;TZID=Europe/Berlin:20240223T113000 | ||
DTSTAMP:20240123T214844Z | ||
DTSTART;TZID=Europe/Berlin:20240223T101500 | ||
LAST-MODIFIED:20240123T214815Z | ||
SEQUENCE:0 | ||
SUMMARY:Test3 | ||
TRANSP:OPAQUE | ||
UID:B9243EBE-1F38-477B-A21C-D9C0BD61C025 | ||
X-APPLE-CREATOR-IDENTITY:com.apple.calendar | ||
X-APPLE-CREATOR-TEAM-IDENTITY:0000000000 | ||
BEGIN:VALARM | ||
ACTION:NONE | ||
TRIGGER;VALUE=DATE-TIME:19760401T005545Z | ||
END:VALARM | ||
END:VEVENT | ||
BEGIN:VEVENT | ||
CREATED:20240123T214815Z | ||
DTEND;TZID=Europe/Berlin:20240223T113000 | ||
DTSTAMP:20240123T214844Z | ||
DTSTART;TZID=Europe/Berlin:20240223T101500 | ||
LAST-MODIFIED:20240123T214815Z | ||
SEQUENCE:0 | ||
SUMMARY:Test4 | ||
TRANSP:OPAQUE | ||
UID:B9243EBE-1F38-477B-A21C-D9C0BD61C025 | ||
X-APPLE-CREATOR-IDENTITY:com.apple.calendar | ||
X-APPLE-CREATOR-TEAM-IDENTITY:0000000000 | ||
BEGIN:VALARM | ||
ACTION:NONE | ||
TRIGGER;VALUE=DATE-TIME:19760401T005545Z | ||
END:VALARM | ||
END:VEVENT | ||
END:VCALENDAR |
Oops, something went wrong.