bin/process-zone
changeset 24 4ccc31fdc047
parent 23 91c073d5615a
child 25 3d35d0eef197
equal deleted inserted replaced
23:91c073d5615a 24:4ccc31fdc047
   284         )
   284         )
   285 
   285 
   286     def __str__ (self) :
   286     def __str__ (self) :
   287         return ' '.join((self.name, self.type, ' '.join(self.data)))
   287         return ' '.join((self.name, self.type, ' '.join(self.data)))
   288 
   288 
       
   289 class TXTRecord (ZoneRecord) :
       
   290     """
       
   291         TXT record.
       
   292     """
       
   293 
       
   294     def __init__ (self, name, text, **opts) :
       
   295         return super(TXTRecord, self).__init__(name, 'TXT', 
       
   296             [u'"{0}"'.format(text.replace('"', '\\"'))], 
       
   297             **opts
       
   298         )
       
   299 
   289 def parse_record (path, lineno, line, **opts) :
   300 def parse_record (path, lineno, line, **opts) :
   290     """
   301     """
   291         Parse (name, ttl, type, data, comment) from bind zonefile.
   302         Parse (name, ttl, type, data, comment) from bind zonefile.
   292 
   303 
   293         Returns None for empty/comment lines.
   304         Returns None for empty/comment lines.
   355 def process_zone_forwards (zone, txt=False, mx=False) :
   366 def process_zone_forwards (zone, txt=False, mx=False) :
   356     """
   367     """
   357         Process zone data -> forward zone data.
   368         Process zone data -> forward zone data.
   358     """
   369     """
   359 
   370 
       
   371     TIMESTAMP_FORMAT='%Y/%m/%d'
       
   372 
   360     for r in zone :
   373     for r in zone :
   361         yield r
   374         yield r
   362 
   375 
   363         if r.type == 'A' :
   376         if r.type == 'A' :
   364             if txt and r.line.comment :
   377             if txt :
   365                 yield ZoneRecord(None, 'TXT', [u'"{0}"'.format(r.line.comment)], ttl=r.ttl)
   378                 # comment?
       
   379                 comment = r.line.comment
       
   380 
       
   381                 if comment :
       
   382                     yield TXTRecord(None, comment, ttl=r.ttl)
       
   383 
       
   384                 # timestamp?
       
   385                 timestamp = r.line.timestamp
       
   386 
       
   387                 if timestamp :
       
   388                     yield TXTRecord(None, timestamp.strftime(TIMESTAMP_FORMAT), ttl=r.ttl)
   366             
   389             
   367             # XXX: RP, do we need it?
   390             # XXX: RP, do we need it?
   368 
   391 
   369             if mx :
   392             if mx :
   370                 # XXX: is this a good idea?
   393                 # XXX: is this a good idea?