Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 29 additions & 1 deletion abeluna/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import hashlib
import os
import threading
import sys

import keyring
import pytz
from gi.repository import GLib

Expand Down Expand Up @@ -50,6 +52,16 @@ def __init__(self):
for section in self.config.sections():
if section.startswith('calendar '):
calendar = dict(self.config[section])

if 'password' not in calendar and calendar['url']:
try:
calendar['password'] = keyring.get_password("abeluna", calendar['uid'])
except keyring.errors.KeyringLocked as e:
print('Error: keyring locked. Unlock keyring to proceed')
sys.exit(1)
except (RuntimeError, keyring.errors.KeyringError) as e:
print('Error getting password for calendar "{}" from keyring'.format(calendar['name']))

self.add_or_update_calendar(calendar)
self.commit()

Expand All @@ -64,11 +76,27 @@ def commit(self):
with self._lock:
for section in self.config.sections():
if section.startswith('calendar '):
calendar = dict(self.config[section])
if calendar['url'] and 'password' not in calendar:
try:
keyring.delete_password("abeluna", calendar['uid'])
except (RuntimeError, keyring.errors.KeyringError) as e:
pass
self.config.remove_section(section)
for uid, calendar in self.CALENDARS.items():
section_name = 'calendar {}'.format(uid)
self.config.add_section(section_name)
self.config[section_name].update(calendar)
_calendar = calendar.copy()

if _calendar['url'] and _calendar['password']:
try:
keyring.set_password("abeluna", uid, bytes(_calendar['password'], 'utf-8'))
del _calendar['password']
except (RuntimeError, keyring.errors.KeyringError) as e:
pass

self.config[section_name].update(_calendar)

with open(self.CONFIG_FILE, 'w') as f:
self.config.write(f)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pygobject
humanize
icalendar
caldav
keyring
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
},
author='Evan Zhang',
install_requires=['pygobject', 'humanize', 'icalendar', 'caldav'],
install_requires=['pygobject', 'humanize', 'icalendar', 'caldav', 'keyring'],
include_package_data=True,
description='A simple GUI to-do/task manager with CalDAV support.',
long_description=readme,
Expand Down