Skip to content

Import #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 22, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ask for confirmation before overwriting
  • Loading branch information
geier committed Jun 22, 2015
commit 499d0d5ad873498a1dfafac8d14d3e538578006e
10 changes: 6 additions & 4 deletions khal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def new(ctx, description, location, repeat, until):
@click.option('--include-calendar', '-a', help=('The calendar to use.'),
expose_value=False, callback=_calendar_select_callback,
metavar='CAL')
@click.option('--batch', help=('do not ask for confirmation.'),
@click.option('--batch', help=('do not ask for any confirmation.'),
is_flag=True)
@click.option('--random_uid', '-r', help=('Select a random uid.'),
is_flag=True)
Expand All @@ -258,9 +258,11 @@ def import_ics(ctx, ics, batch, random_uid):
'''Import events from an .ics file.

If an event with the same UID is already present in the (implicitly)
selected calendar import will update (i.e. overwrite) that old event
with the imported one. If this behaviour is not desired, that the
`--random-uid` flag.
selected calendar import will ask before updating (i.e. overwriting)
that old event with the imported one, unless --batch is given, than it
will always update. If this behaviour is not desired, use the
`--random-uid` flag to generate a new, random UID.

'''
ics_str = ics.read()
controllers.import_ics(
Expand Down
17 changes: 11 additions & 6 deletions khal/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def interactive(collection, conf):

def import_ics(collection, conf, ics, batch=False, random_uid=False):
"""
:param batch: setting this to True will insert without asking for approval
:param batch: setting this to True will insert without asking for approval,
even when an event with the same uid already exists
:type batch: bool
"""
cal = icalendar.Calendar.from_ical(ics)
Expand All @@ -218,14 +219,18 @@ def import_ics(collection, conf, ics, batch=False, random_uid=False):
locale=conf['locale'])
if not batch:
echo(event.long())
if batch or confirm('Do you want to import this event into `{}`?'
''.format(collection.default_calendar_name)):
if batch or confirm("Do you want to import this event into `{}`?"
"".format(collection.default_calendar_name)):
ics = aux.ics_from_list(vevent, random_uid)
try:
collection.new(
Item(ics.to_ical().decode('utf-8')),
collection=collection.default_calendar_name)
except DuplicateUid:
collection.force_update(
Item(ics.to_ical().decode('utf-8')),
collection=collection.default_calendar_name)
if batch or confirm("An event with the same UID already exists. "
"Do you want to update it?"):
collection.force_update(
Item(ics.to_ical().decode('utf-8')),
collection=collection.default_calendar_name)
else:
logger.warn("Not importing event with UID `{}`".format(event.uid))