]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Improving method import_records() of class ImportPdnsdataApp - avoid NULL values...
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 15 Jan 2018 15:18:13 +0000 (16:18 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 15 Jan 2018 15:18:13 +0000 (16:18 +0100)
pp_lib/import_pdnsdata.py

index 0ee28d1044f872d4da74422049d7449866007572..5ed65d7a6a66592ff0b0182efdc8b988548aa1d5 100644 (file)
@@ -31,7 +31,7 @@ from .common import pp, to_bool
 
 from .cfg_app import PpCfgAppError, PpConfigApplication
 
-__version__ = '0.8.5'
+__version__ = '0.8.6'
 LOG = logging.getLogger(__name__)
 
 # =============================================================================
@@ -90,6 +90,8 @@ class ImportPdnsdataApp(PpConfigApplication):
         self.src_connection = None
         self.tgt_connection = None
 
+        self.domain_ids = {}
+
         self._show_simulate_opt = True
 
         super(ImportPdnsdataApp, self).__init__(
@@ -598,6 +600,8 @@ class ImportPdnsdataApp(PpConfigApplication):
 
         LOG.info("Importing all domains ...")
 
+        self.domain_ids = {}
+
         src_sql = textwrap.dedent('''\
             SELECT id, name, master, last_check, type, notified_serial, account
               FROM domains
@@ -626,6 +630,8 @@ class ImportPdnsdataApp(PpConfigApplication):
 
                 for result in results:
                     i += 1
+                    dom_id = result['id']
+                    self.domain_ids[dom_id] = result['name']
                     if self.is_local(result['name']):
                         LOG.debug("Setting zone {!r} to a local only zone.".format(result['name']))
                         cur_account = result['account']
@@ -853,6 +859,20 @@ class ImportPdnsdataApp(PpConfigApplication):
                                 result['auth'] = True
                             else:
                                 result['auth'] = False
+                        if result['ordername'] is None:
+                            dom_id = result['domain_id']
+                            if dom_id in self.domain_ids:
+                                dom_name = self.domain_ids[dom_id]
+                                if result['name'] == dom_name:
+                                    result['ordername'] = ''
+                                else:
+                                    idx = result['name'].rfind('.' + dom_name)
+                                    if idx >= 0:
+                                        result['ordername'] = result['name'][:idx]
+                                    else:
+                                        result['ordername'] = ''
+                            else:
+                                result['ordername'] = ''
                     if not self.simulate:
                         tgt_cursor.execute(tgt_sql, result)
                 LOG.info("Imported {} records.".format(i))