From 75d8efcf9f4d908736e1dfb3e2ae9b09fa8b1336 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Sat, 21 Aug 2010 14:49:46 -0500 Subject: Save config on exit and fix config saving bugs --- feed-transmission.example.json | 4 ---- feed-transmission.py | 13 +++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/feed-transmission.example.json b/feed-transmission.example.json index 7252575..497ba3c 100644 --- a/feed-transmission.example.json +++ b/feed-transmission.example.json @@ -3,16 +3,12 @@ { "matches": [ { - "type": "re", "value": ".*Thread: Some thread", "white": true, - "matched_count": 0 }, { - "type": "re", "value": ".*Thread: Some other thread", "white": true, - "matched_count": 0 ], "name": "example.com", "poll_delay": 3600, diff --git a/feed-transmission.py b/feed-transmission.py index 167dd6b..deff6b8 100755 --- a/feed-transmission.py +++ b/feed-transmission.py @@ -63,8 +63,9 @@ class App(ConfigParticipant): fd.close() def save_config(self): + config = self.export_config() fd = file(self.config_filename, "w") - json.dump(self.export_data(), fd) + json.dump(config, fd, indent = 4) fd.close() def load_data(self, json_filename): @@ -78,8 +79,9 @@ class App(ConfigParticipant): fd.close() def save_data(self): + data = self.export_data() fd = file(self.data_filename, "w") - json.dump(self.export_data(), fd) + json.dump(data, fd) fd.close() def import_config(self, config): @@ -205,7 +207,7 @@ class Feed(ConfigParticipant): "url": self.url, "poll_delay": self.poll_delay, "matches": [m.export_config() for m in self.matches], - "default_white": self.white, + "default_white": self.default_white, } def import_data(self, data): @@ -232,15 +234,13 @@ class Matcher(ConfigParticipant): m = Matcher() m.white = m._import_attribute(config, "white", bool, m.white) m.str = m._import_attribute(config, "value", str, m.str) - m.matched_count = m._import_attribute(config, "matched_count", int, m.matched_count) m.re = re.compile(m.str) return m def export_config(self): return { "white": self.white, - "str": self.str, - "matched_count": self.matched_count, + "value": self.str, } def import_data(self, data): @@ -260,4 +260,5 @@ if __name__ == "__main__": app.load_data(".feed-transmission.data") app.setup_env() app.main() + app.save_config() -- cgit v1.2.3-54-g00ecf