From: Frank Brehm Date: Mon, 15 Jan 2018 15:18:13 +0000 (+0100) Subject: Improving method import_records() of class ImportPdnsdataApp - avoid NULL values... X-Git-Tag: 0.1.2~32 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=38edcf1c6dff1507ca1600ca93ff3c601ec3e739;p=pixelpark%2Fadmin-tools.git Improving method import_records() of class ImportPdnsdataApp - avoid NULL values for ordername in records. --- diff --git a/pp_lib/import_pdnsdata.py b/pp_lib/import_pdnsdata.py index 0ee28d1..5ed65d7 100644 --- a/pp_lib/import_pdnsdata.py +++ b/pp_lib/import_pdnsdata.py @@ -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))