Skip to content

Commit

Permalink
Fix configure: no more crash if no vdir configured.
Browse files Browse the repository at this point in the history
Fixes #579.
  • Loading branch information
geier committed Feb 17, 2017
1 parent 62b015c commit d756792
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -7,6 +7,12 @@ Package maintainers and users who have to manually update their installation
may want to subscribe to `GitHub's tag feed
<https://github.com/geier/khal/tags.atom>`_.

0.9.3
=====
not released yet

* FIX `configure` would crash if neither "import config from vdirsyncer" nor
"create locale vdir" was selected

0.9.2
=====
Expand Down
9 changes: 6 additions & 3 deletions khal/configwizard.py
Expand Up @@ -146,12 +146,12 @@ def create_vdir(names=[]):
print("Could not create directory {} because of {}. Exiting".format(path, error))
raise
print("Created new vdir at {}".format(path))
return (name, path, 'calendar')
return [(name, path, 'calendar')]


def create_config(vdirs, dateformat, timeformat):
config = ['[calendars]']
for name, path, type_ in sorted(vdirs) or ():
for name, path, type_ in sorted(vdirs or ()):
config.append('\n[[{name}]]'.format(name=name))
config.append('path = {path}'.format(path=path))
config.append('type = {type}'.format(type=type_))
Expand Down Expand Up @@ -186,10 +186,13 @@ def configwizard():
print()
if not vdirs:
try:
vdirs = [create_vdir()]
vdirs = create_vdir()
except OSError as error:
raise FatalError(error)

if not vdirs:
print("\nWARNING: no vdir configured, khal will not be usable like this!\n")

config = create_config(vdirs, dateformat=dateformat, timeformat=timeformat)
config_path = join(xdg.BaseDirectory.xdg_config_home, 'khal', 'config')
if not confirm(
Expand Down
13 changes: 12 additions & 1 deletion tests/cli_test.py
Expand Up @@ -448,7 +448,6 @@ def choices(ordering=0, separator=0, dateconfirm=True,
create_vdir=False,
write_config=True):
"""helper function to generate input for testing `configure`"""
assert parse_vdirsyncer_conf != create_vdir
confirm = {True: 'y', False: 'n'}

out = [
Expand Down Expand Up @@ -655,6 +654,18 @@ def test_configure_command_cannot_create_vdir(runner):
assert result.exit_code == 1


def test_configure_no_vdir(runner):
runner = runner()
runner.config_file.remove()
result = runner.invoke(
main_khal, ['configure'],
input=choices(parse_vdirsyncer_conf=False, create_vdir=False),
)
assert 'khal will not be usable like this' in result.output
assert result.exit_code == 0
assert not result.exception


def test_edit(runner):
runner = runner()
result = runner.invoke(main_khal, ['list'])
Expand Down

0 comments on commit d756792

Please sign in to comment.