|
| 1 | +# coding: utf-8 |
| 2 | +from __future__ import print_function, unicode_literals |
| 3 | + |
| 4 | +import os |
| 5 | +from configparser import ConfigParser |
| 6 | + |
| 7 | +import codecs |
| 8 | + |
| 9 | + |
| 10 | +class InoreaderConfigManager(): |
| 11 | + |
| 12 | + def __init__(self, config_file): |
| 13 | + self.config_file = config_file |
| 14 | + self.data = {} |
| 15 | + if os.path.exists(config_file): |
| 16 | + self.load() |
| 17 | + |
| 18 | + def load(self): |
| 19 | + config_parser = ConfigParser() |
| 20 | + config_parser.read(self.config_file) |
| 21 | + for section_name in config_parser.sections(): |
| 22 | + self.data[section_name] = dict(config_parser[section_name]) |
| 23 | + |
| 24 | + def save(self): |
| 25 | + with codecs.open(self.config_file, mode='w', encoding='utf-8') as f: |
| 26 | + config_parser = ConfigParser() |
| 27 | + config_parser.update(self.data) |
| 28 | + config_parser.write(f) |
| 29 | + |
| 30 | + @property |
| 31 | + def app_id(self): |
| 32 | + return self.data.get('auth', {}).get('appid') |
| 33 | + |
| 34 | + @app_id.setter |
| 35 | + def app_id(self, value): |
| 36 | + self.data.setdefault('auth', {})['appid'] = value |
| 37 | + |
| 38 | + @property |
| 39 | + def app_key(self): |
| 40 | + return self.data.get('auth', {}).get('appkey') |
| 41 | + |
| 42 | + @app_key.setter |
| 43 | + def app_key(self, value): |
| 44 | + self.data.setdefault('auth', {})['appkey'] = value |
| 45 | + |
| 46 | + @property |
| 47 | + def access_token(self): |
| 48 | + return self.data.get('auth', {}).get('access_token') |
| 49 | + |
| 50 | + @access_token.setter |
| 51 | + def access_token(self, value): |
| 52 | + self.data.setdefault('auth', {})['access_token'] = value |
| 53 | + |
| 54 | + @property |
| 55 | + def refresh_token(self): |
| 56 | + return self.data.get('auth', {}).get('refresh_token') |
| 57 | + |
| 58 | + @refresh_token.setter |
| 59 | + def refresh_token(self, value): |
| 60 | + self.data.setdefault('auth', {})['refresh_token'] = value |
| 61 | + |
| 62 | + @property |
| 63 | + def expires_at(self): |
| 64 | + return self.data.get('auth', {}).get('expires_at') |
| 65 | + |
| 66 | + @expires_at.setter |
| 67 | + def expires_at(self, value): |
| 68 | + self.data.setdefault('auth', {})['expires_at'] = value |
0 commit comments