Added example custom keyring backend.
This commit is contained in:
parent
215b85e431
commit
b0d5fdba75
27
i3pystatus/core/netrc_backend.py
Normal file
27
i3pystatus/core/netrc_backend.py
Normal file
@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
__author__ = 'facetoe'
|
||||
from keyring.backend import KeyringBackend
|
||||
|
||||
|
||||
# This is an example custom keyring backend. It should probably be somewhere else...
|
||||
class NetrcBackend(KeyringBackend):
|
||||
def get_password(self, service, username):
|
||||
from netrc import netrc
|
||||
sections = service.split('.')
|
||||
setting = sections[-1]
|
||||
if setting == 'password':
|
||||
key = ".".join(sections[:-1])
|
||||
setting_tuple = netrc().authenticators(key)
|
||||
if setting_tuple:
|
||||
login, account, password = setting_tuple
|
||||
return password
|
||||
|
||||
def set_password(self, service, username, password):
|
||||
raise Exception("Setting password not supported!")
|
||||
|
||||
def priority(cls):
|
||||
netrc_path = os.path.isfile(os.path.expanduser("~/.netrc"))
|
||||
if not os.path.isfile(netrc_path):
|
||||
raise Exception("No .netrc found at: %s" % netrc_path)
|
||||
return 0.5
|
@ -83,7 +83,6 @@ class SettingsBase:
|
||||
def set_protected_settings(self):
|
||||
for setting_name in self.__PROTECTED_SETTINGS:
|
||||
if hasattr(self, setting_name) and not getattr(self, setting_name):
|
||||
print("%s.%s" % (self.__name__, setting_name))
|
||||
setting = self.get_protected_setting("%s.%s" % (self.__name__, setting_name))
|
||||
if setting:
|
||||
setattr(self, setting_name, setting)
|
||||
|
Loading…
Reference in New Issue
Block a user