Add new feeds at end of file, and rework config editor code a bit.
authorAdam Sampson <ats@offog.org>
Tue, 4 Jan 2005 23:27:50 +0000 (23:27 +0000)
committerAdam Sampson <ats@offog.org>
Tue, 4 Jan 2005 23:27:50 +0000 (23:27 +0000)
NEWS
rawdoglib/rawdog.py

diff --git a/NEWS b/NEWS
index b8e0814fca8125b54258517a956edf3c16d605c2..4c1de27ae52968d43e4c79041ad8851f38a53b6b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,9 @@ arguments.
 Add a meta element to the default template to stop search engines
 indexing rawdog pages (patch from Rick van Rein).
 
+Add new feeds at the end of the config file rather than before the first
+feed line (patch from Decklin Foster).
+
 - rawdog 2.1
 
 Fix a character encoding problem with format=text feeds.
index 85384cf22dd876c26794e087f2877151835ecc6f..b6434534ec4d5a93e856c1b717522697872c4d98 100644 (file)
@@ -692,8 +692,7 @@ def edit_file(filename, editfunc):
        newname = "%s.new-%d" % (filename, os.getpid())
        oldfile = open(filename, "r")
        newfile = open(newname, "w")
-       for line in oldfile.xreadlines():
-               editfunc(line, newfile)
+       editfunc(oldfile, newfile)
        newfile.close()
        oldfile.close()
        os.rename(newname, filename)
@@ -701,14 +700,12 @@ def edit_file(filename, editfunc):
 class AddFeedEditor:
        def __init__(self, feedline):
                self.feedline = feedline
-               self.seen = False
-       def edit(self, line, outputfile):
-               if not self.seen:
-                       ls = line.split(None, 1)
-                       if len(ls) > 0 and ls[0] == "feed":
-                               outputfile.write(self.feedline)
-                               self.seen = True
-               outputfile.write(line)
+       def edit(self, inputfile, outputfile):
+               d = inputfile.read()
+               outputfile.write(d)
+               if not d.endswith("\n"):
+                       outputfile.write("\n")
+               outputfile.write(self.feedline)
 
 def add_feed(filename, url, config):
        """Try to add a feed to the config file."""
@@ -725,11 +722,12 @@ class ChangeFeedEditor:
        def __init__(self, oldurl, newurl):
                self.oldurl = oldurl
                self.newurl = newurl
-       def edit(self, line, outputfile):
-               ls = line.strip().split(None)
-               if len(ls) > 2 and ls[0] == "feed" and ls[2] == self.oldurl:
-                       line = line.replace(self.oldurl, self.newurl, 1)
-               outputfile.write(line)
+       def edit(self, inputfile, outputfile):
+               for line in inputfile.xreadlines():
+                       ls = line.strip().split(None)
+                       if len(ls) > 2 and ls[0] == "feed" and ls[2] == self.oldurl:
+                               line = line.replace(self.oldurl, self.newurl, 1)
+                       outputfile.write(line)
 
 class Rawdog(Persistable):
        """The aggregator itself."""