Add Calendar Name and Description to output ical
Previously the calendar was missing a name and description which means that some ical clients retain the URL rather than having a human readable view. This change introduces two new command line options -n|--name and -d|--description for suppling the relevant fields. This implements the X-WR-CALNAME and X-WR-CALDESC ical extension properties. Change-Id: I97d44a2c924699ef362b7c053a637ace89b94fe2 Signed-off-by: Dave Walker (Daviey) <email@daviey.com>
This commit is contained in:
parent
ff513f9efe
commit
2d86450f7e
|
@ -53,6 +53,12 @@ project infrastructure.
|
|||
parser.add_argument("-w", "--indexoutput",
|
||||
dest="index_output",
|
||||
help="output index file")
|
||||
parser.add_argument("-n", "--name",
|
||||
dest="calname",
|
||||
help="name of calendar to set within the ical")
|
||||
parser.add_argument("-d", "--description",
|
||||
dest="caldescription",
|
||||
help="description of calendar to set within the ical")
|
||||
parser.add_argument("-f", "--force",
|
||||
dest="force",
|
||||
action='store_true',
|
||||
|
@ -65,6 +71,10 @@ project infrastructure.
|
|||
(args.index_output and not args.index_template)):
|
||||
parser.error("You need to provide both -t and "
|
||||
"-w if you want to output an index.")
|
||||
if args.ical_dir and (args.calname or args.caldescription):
|
||||
parser.error("Name/Description and single ical per meeting "
|
||||
"(-i) is incompatiable due to spec.")
|
||||
|
||||
return args
|
||||
|
||||
|
||||
|
@ -112,7 +122,9 @@ def main():
|
|||
ical.convert_meetings_to_ical(meetings, outputdir=ical_dir)
|
||||
else:
|
||||
icalfile = _prepare_output(args.icalfile, force=args.force)
|
||||
ical.convert_meetings_to_ical(meetings, outputfile=icalfile)
|
||||
ical.convert_meetings_to_ical(meetings, outputfile=icalfile,
|
||||
caldescription=args.caldescription,
|
||||
calname=args.calname)
|
||||
|
||||
if args.index_template and args.index_output:
|
||||
index_template = os.path.abspath(args.index_template)
|
||||
|
|
|
@ -21,10 +21,14 @@ import pytz
|
|||
class Yaml2IcalCalendar(icalendar.Calendar):
|
||||
"""A calendar in ics format."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, calname=None, caldescription=None):
|
||||
super(Yaml2IcalCalendar, self).__init__()
|
||||
self.add('prodid', '-//yaml2ical agendas//EN')
|
||||
self.add('version', '2.0')
|
||||
if calname is not None:
|
||||
self.add('X-WR-CALNAME', calname)
|
||||
if caldescription is not None:
|
||||
self.add('X-WR-CALDESC', caldescription)
|
||||
|
||||
def add_meeting(self, meeting):
|
||||
"""Add this meeting to the calendar."""
|
||||
|
@ -76,7 +80,8 @@ class Yaml2IcalCalendar(icalendar.Calendar):
|
|||
ics.write(self.to_ical())
|
||||
|
||||
|
||||
def convert_meetings_to_ical(meetings, outputdir=None, outputfile=None):
|
||||
def convert_meetings_to_ical(meetings, outputdir=None, outputfile=None,
|
||||
calname=None, caldescription=None):
|
||||
"""Converts a meeting list to iCal.
|
||||
|
||||
:param meetings: list of meetings to convert
|
||||
|
@ -95,7 +100,7 @@ def convert_meetings_to_ical(meetings, outputdir=None, outputfile=None):
|
|||
|
||||
# convert meetings into a single ical
|
||||
if outputfile:
|
||||
cal = Yaml2IcalCalendar()
|
||||
cal = Yaml2IcalCalendar(calname, caldescription)
|
||||
for m in meetings:
|
||||
cal.add_meeting(m)
|
||||
cal.write_to_disk(outputfile)
|
||||
|
|
Loading…
Reference in New Issue