# Copyright 2015 Lars Wirzenius # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # =*= License: GPL-3+ =*= import yaml class InformationStore(object): attrs = [] def __init__(self): self._filename = None for attr in self.attrs: setattr(self, attr, None) def set_filename(self, filename): self._filename = filename def save(self): obj = {} for attr in self.attrs: obj[attr] = getattr(self, attr) with open(self._filename, 'w') as f: yaml.safe_dump(obj, stream=f, default_flow_style=False, indent=4) def load(self): with open(self._filename) as f: obj = yaml.safe_load(f) for attr in self.attrs: setattr(self, attr, obj.get(attr))