summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Brox <tobixen@gmail.com>2013-10-05 19:27:44 +0200
committerTobias Brox <tobixen@gmail.com>2013-10-05 19:27:44 +0200
commit992b4a24445d823f93c8847e88941795427124f2 (patch)
tree2489fa264a15b266f20d1ccc56daa03499940460
parent30c43736160046043ebe637239cdb0131cbea7b4 (diff)
downloadcalendar-cli-992b4a24445d823f93c8847e88941795427124f2.zip
now the calendar-url option is ... optional :-)
-rwxr-xr-xcalendar-cli.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/calendar-cli.py b/calendar-cli.py
index 4ce79fe..d8a1b46 100755
--- a/calendar-cli.py
+++ b/calendar-cli.py
@@ -37,10 +37,6 @@ def caldav_connect(args):
def calendar_add(caldav_conn, args):
- if (not args.calendar_url):
- ## args.calendar_url must be given ... :/
- niy()
-
cal = Calendar()
cal.add('prodid', '-//{author_short}//{product}//{language}'.format(author_short=__author_short__, product=__product__, language=args.language))
cal.add('version', '2.0')
@@ -62,8 +58,24 @@ def calendar_add(caldav_conn, args):
if args.icalendar:
print(cal.to_ical())
- elif args.caldav_url:
- caldav_conn.session.writeData(URL(args.calendar_url+str(uid)+'.ics'), cal.to_ical(), 'text/calendar', method='PUT')
+ return
+
+ if args.calendar_url:
+ splits = urlparse.urlsplit(args.calendar_url)
+ if splits.path.startswith('/') or splits.scheme:
+ ## assume fully qualified URL or absolute path
+ calendar = args.calendar_url
+ else:
+ ## assume relative path
+ calendar = args.caldav_url + args.calendar_url
+ else:
+ ## Find default calendar
+ url = caldav_conn.getPrincipal().listCalendars()[0].path
+
+ ## Unique file name
+ url = URL(calendar + str(uid) + '.ics')
+ caldav_conn.session.writeData(url, cal.to_ical(), 'text/calendar', method='PUT')
+
def main():
## This boilerplate pattern is from
@@ -121,7 +133,7 @@ def main():
subparsers = parser.add_subparsers(title='command')
calendar_parser = subparsers.add_parser('calendar')
- calendar_parser.add_argument("--calendar-url", help="URL for calendar to be used")
+ calendar_parser.add_argument("--calendar-url", help="URL for calendar to be used (may be absolute or relative to caldav URL)")
calendar_subparsers = calendar_parser.add_subparsers(title='subcommand')
calendar_add_parser = calendar_subparsers.add_parser('add')
calendar_add_parser.add_argument('event_time', help="Timestamp and duration of the event. See the documentation for event_time specifications")