from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.6.1'
+__version__ = '0.6.2'
LOG = logging.getLogger(__name__)
# =============================================================================
# -------------------------------------------------------------------------
def pre_run(self):
+ self.connect_src_db()
+ self.connect_tgt_db()
+
+ # -------------------------------------------------------------------------
+ def connect_src_db(self):
+
result = None
LOG.debug("Connecting to source MySQL database on {}@{}:{}/{} ...".format(
e.__class__.__name__, e))
self.exit(6)
+ # -------------------------------------------------------------------------
+ def connect_tgt_db(self):
+
+ if self.tgt_db_type == 'mysql':
+ self.connect_tgt_db_mysql()
+ else:
+ self.connect_tgt_db_psql()
+
+ # -------------------------------------------------------------------------
+ def connect_tgt_db_mysql(self):
+
+ result = None
+
+ LOG.debug("Connecting to target MySQL database on {}@{}:{}/{} ...".format(
+ self.tgt_db_user, self.tgt_db_host, self.tgt_db_port, self.tgt_db_schema))
+ try:
+ self.tgt_connection = pymysql.connect(
+ host=self.tgt_db_host,
+ port=self.tgt_db_port,
+ db=self.tgt_db_schema,
+ user=self.tgt_db_user,
+ password=self.tgt_db_pass,
+ charset='utf8',
+ cursorclass=pymysql.cursors.DictCursor
+ )
+
+ sql = 'SHOW VARIABLES LIKE "version"'
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ with self.tgt_connection.cursor() as cursor:
+ cursor.execute(sql)
+ result = cursor.fetchone()
+ if self.verbose > 2:
+ LOG.debug("Got version info:\n{}".format(pp(result)))
+ LOG.info("Target database is MySQL version {!r}.".format(result['Value']))
+
+ except (pymysql.err.OperationalError) as e:
+ LOG.error("Could not connect to target database ({}): {}".format(
+ e.__class__.__name__, e))
+ self.exit(6)
+
+ # -------------------------------------------------------------------------
+ def connect_tgt_db_psql(sellf):
+
+ result = None
+
LOG.debug("Connecting to target PostgreSQL database on {}@{}:{}/{} ...".format(
self.tgt_db_user, self.tgt_db_host, self.tgt_db_port, self.tgt_db_schema))
try: