process-zone: generate TXT records for ZoneLine.timestamp, if available
authorTero Marttila <terom@paivola.fi>
Mon, 19 Mar 2012 10:58:50 +0200
changeset 547 4ccc31fdc047
parent 546 91c073d5615a
child 548 3d35d0eef197
process-zone: generate TXT records for ZoneLine.timestamp, if available
bin/process-zone
--- a/bin/process-zone	Mon Mar 19 10:50:34 2012 +0200
+++ b/bin/process-zone	Mon Mar 19 10:58:50 2012 +0200
@@ -286,6 +286,17 @@
     def __str__ (self) :
         return ' '.join((self.name, self.type, ' '.join(self.data)))
 
+class TXTRecord (ZoneRecord) :
+    """
+        TXT record.
+    """
+
+    def __init__ (self, name, text, **opts) :
+        return super(TXTRecord, self).__init__(name, 'TXT', 
+            [u'"{0}"'.format(text.replace('"', '\\"'))], 
+            **opts
+        )
+
 def parse_record (path, lineno, line, **opts) :
     """
         Parse (name, ttl, type, data, comment) from bind zonefile.
@@ -357,12 +368,24 @@
         Process zone data -> forward zone data.
     """
 
+    TIMESTAMP_FORMAT='%Y/%m/%d'
+
     for r in zone :
         yield r
 
         if r.type == 'A' :
-            if txt and r.line.comment :
-                yield ZoneRecord(None, 'TXT', [u'"{0}"'.format(r.line.comment)], ttl=r.ttl)
+            if txt :
+                # comment?
+                comment = r.line.comment
+
+                if comment :
+                    yield TXTRecord(None, comment, ttl=r.ttl)
+
+                # timestamp?
+                timestamp = r.line.timestamp
+
+                if timestamp :
+                    yield TXTRecord(None, timestamp.strftime(TIMESTAMP_FORMAT), ttl=r.ttl)
             
             # XXX: RP, do we need it?