from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.6.2'
+__version__ = '0.6.3'
LOG = logging.getLogger(__name__)
# =============================================================================
self.exit(6)
# -------------------------------------------------------------------------
- def connect_tgt_db_psql(sellf):
+ def connect_tgt_db_psql(self):
result = None
for table in tables:
LOG.debug("Truncating {!r} ...".format(table))
- sql = 'TRUNCATE TABLE {} RESTART IDENTITY CASCADE'.format(table)
+ if self.tgt_db_type == 'mysql':
+ sql = 'DELETE FROM {}'.format(table)
+ else:
+ sql = 'TRUNCATE TABLE {} RESTART IDENTITY CASCADE'.format(table)
if self.verbose > 1:
LOG.debug("SQL: {}".format(sql))
if not self.simulate:
tgt_cursor.execute(tgt_sql, result)
LOG.info("Imported {} domains.".format(i))
- LOG.debug("Get max. Domain Id ...")
- sql = "SELECT MAX(id) AS max_id FROM domains"
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- tgt_cursor.execute(sql)
- result = tgt_cursor.fetchone()
- if self.verbose > 2:
- LOG.debug("Got max domain Id:\n{}".format(pp(result)))
- max_id = int(result[0])
- sql = "SELECT SETVAL('domains_id_seq', %s)"
- LOG.debug("Setting curval of domains_id_seq to {} ...".format(max_id))
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- if not self.simulate:
- tgt_cursor.execute(sql, (max_id, ))
+ if self.tgt_db_type != 'mysql':
+ LOG.debug("Get max. Domain Id ...")
+ sql = "SELECT MAX(id) AS max_id FROM domains"
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ tgt_cursor.execute(sql)
+ result = tgt_cursor.fetchone()
+ if self.verbose > 2:
+ LOG.debug("Got max domain Id:\n{}".format(pp(result)))
+ max_id = int(result[0])
+ sql = "SELECT SETVAL('domains_id_seq', %s)"
+ LOG.debug("Setting curval of domains_id_seq to {} ...".format(max_id))
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ if not self.simulate:
+ tgt_cursor.execute(sql, (max_id, ))
LOG.debug("Commiting changes ...")
self.tgt_connection.commit()
i = 0
for result in results:
i += 1
- if result['active']:
- result['active'] = True
- else:
- result['active'] = False
+ if self.tgt_db_type != 'mysql':
+ if result['active']:
+ result['active'] = True
+ else:
+ result['active'] = False
if not self.simulate:
tgt_cursor.execute(tgt_sql, result)
LOG.info("Imported {} cryptokeys.".format(i))
- LOG.debug("Get max. CryptoKey Id ...")
- sql = "SELECT MAX(id) AS max_id FROM cryptokeys"
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- tgt_cursor.execute(sql)
- result = tgt_cursor.fetchone()
- if self.verbose > 2:
- LOG.debug("Got max cryptokey Id:\n{}".format(pp(result)))
- max_id = int(result[0])
- sql = "SELECT SETVAL('cryptokeys_id_seq', %s)"
- LOG.debug("Setting curval of cryptokeys_id_seq to {} ...".format(max_id))
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- if not self.simulate:
- tgt_cursor.execute(sql, (max_id, ))
+ if self.tgt_db_type != 'mysql':
+ LOG.debug("Get max. CryptoKey Id ...")
+ sql = "SELECT MAX(id) AS max_id FROM cryptokeys"
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ tgt_cursor.execute(sql)
+ result = tgt_cursor.fetchone()
+ if self.verbose > 2:
+ LOG.debug("Got max cryptokey Id:\n{}".format(pp(result)))
+ max_id = int(result[0])
+ sql = "SELECT SETVAL('cryptokeys_id_seq', %s)"
+ LOG.debug("Setting curval of cryptokeys_id_seq to {} ...".format(max_id))
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ if not self.simulate:
+ tgt_cursor.execute(sql, (max_id, ))
LOG.debug("Commiting changes ...")
self.tgt_connection.commit()
tgt_cursor.execute(tgt_sql, result)
LOG.info("Imported {} domainmetadata.".format(i))
- LOG.debug("Get max. DomainMetadata Id ...")
- sql = "SELECT MAX(id) AS max_id FROM domainmetadata"
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- tgt_cursor.execute(sql)
- result = tgt_cursor.fetchone()
- if self.verbose > 2:
- LOG.debug("Got max domainmetadata Id:\n{}".format(pp(result)))
- max_id = int(result[0])
- sql = "SELECT SETVAL('domainmetadata_id_seq', %s)"
- LOG.debug("Setting curval of domainmetadata_id_seq to {} ...".format(max_id))
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- if not self.simulate:
- tgt_cursor.execute(sql, (max_id, ))
+ if self.tgt_db_type != 'mysql':
+ LOG.debug("Get max. DomainMetadata Id ...")
+ sql = "SELECT MAX(id) AS max_id FROM domainmetadata"
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ tgt_cursor.execute(sql)
+ result = tgt_cursor.fetchone()
+ if self.verbose > 2:
+ LOG.debug("Got max domainmetadata Id:\n{}".format(pp(result)))
+ max_id = int(result[0])
+ sql = "SELECT SETVAL('domainmetadata_id_seq', %s)"
+ LOG.debug("Setting curval of domainmetadata_id_seq to {} ...".format(max_id))
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ if not self.simulate:
+ tgt_cursor.execute(sql, (max_id, ))
LOG.debug("Commiting changes ...")
self.tgt_connection.commit()
for result in results:
i += 1
- result['disabled'] = False
- if result['auth'] is not None:
- if result['auth']:
- result['auth'] = True
- else:
- result['auth'] = False
+ if self.tgt_db_type == 'mysql':
+ result['disabled'] = 0
+ else:
+ result['disabled'] = False
+ if result['auth'] is not None:
+ if result['auth']:
+ result['auth'] = True
+ else:
+ result['auth'] = False
if not self.simulate:
tgt_cursor.execute(tgt_sql, result)
LOG.info("Imported {} records.".format(i))
- LOG.debug("Get max. records Id ...")
- sql = "SELECT MAX(id) AS max_id FROM records"
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- tgt_cursor.execute(sql)
- result = tgt_cursor.fetchone()
- if self.verbose > 2:
- LOG.debug("Got max records Id:\n{}".format(pp(result)))
- max_id = int(result[0])
- sql = "SELECT SETVAL('records_id_seq', %s)"
- LOG.debug("Setting curval of records_id_seq to {} ...".format(max_id))
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- if not self.simulate:
- tgt_cursor.execute(sql, (max_id, ))
+ if self.tgt_db_type != 'mysql':
+ LOG.debug("Get max. records Id ...")
+ sql = "SELECT MAX(id) AS max_id FROM records"
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ tgt_cursor.execute(sql)
+ result = tgt_cursor.fetchone()
+ if self.verbose > 2:
+ LOG.debug("Got max records Id:\n{}".format(pp(result)))
+ max_id = int(result[0])
+ sql = "SELECT SETVAL('records_id_seq', %s)"
+ LOG.debug("Setting curval of records_id_seq to {} ...".format(max_id))
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ if not self.simulate:
+ tgt_cursor.execute(sql, (max_id, ))
LOG.debug("Commiting changes ...")
self.tgt_connection.commit()
tgt_cursor.execute(tgt_sql, result)
LOG.info("Imported {} tsigkeys.".format(i))
- LOG.debug("Get max. TsigKey Id ...")
- sql = "SELECT MAX(id) AS max_id FROM tsigkeys"
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- tgt_cursor.execute(sql)
- result = tgt_cursor.fetchone()
- if self.verbose > 2:
- LOG.debug("Got max TsigKey Id:\n{}".format(pp(result)))
- max_id = int(result[0])
- sql = "SELECT SETVAL('tsigkeys_id_seq', %s)"
- LOG.debug("Setting curval of tsigkeys_id_seq to {} ...".format(max_id))
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- if not self.simulate:
- tgt_cursor.execute(sql, (max_id, ))
+ if self.tgt_db_type != 'mysql':
+ LOG.debug("Get max. TsigKey Id ...")
+ sql = "SELECT MAX(id) AS max_id FROM tsigkeys"
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ tgt_cursor.execute(sql)
+ result = tgt_cursor.fetchone()
+ if self.verbose > 2:
+ LOG.debug("Got max TsigKey Id:\n{}".format(pp(result)))
+ max_id = int(result[0])
+ sql = "SELECT SETVAL('tsigkeys_id_seq', %s)"
+ LOG.debug("Setting curval of tsigkeys_id_seq to {} ...".format(max_id))
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ if not self.simulate:
+ tgt_cursor.execute(sql, (max_id, ))
LOG.debug("Commiting changes ...")
self.tgt_connection.commit()