def create_thread_conn(self): # DB origin. Connect to local Database (by default MSSQL) if self.sgbd.lower() == 'mssql': db_from = MsSqlDao() else: db_from = PgDao() db_from.set_params(self.host, self.port, self.db, self.user, self.pwd) ok = db_from.init_db() if ok: return db_from
def connect_databases(): global db_from, db_dest, host, port, db, user, pwd, sgbd # DB origin. Connect to local Database (by default MsSQL) try: host = settings.get('database', 'host') port = settings.get('database', 'port') db = settings.get('database', 'db') user = settings.get('database', 'user') pwd = settings.get('database', 'pwd') sgbd = settings.get('database', 'sgbd') if sgbd.lower() == 'mssql': db_from = MsSqlDao() else: db_from = PgDao() db_from.set_params(host, port, db, user, pwd) from_ok = db_from.init_db() except ConfigParser.NoOptionError, e: logger.warning('{connect_databases} %s' % e) return False
return False # DB destination. Connect to remote Database (by default PostgreSQL) try: host_to = settings.get('database', 'host_to') port_to = settings.get('database', 'port_to') db_to = settings.get('database', 'db_to') user_to = settings.get('database', 'user_to') pwd_to = settings.get('database', 'pwd_to') sgbd_to = settings.get('database', 'sgbd_to') if sgbd_to.lower() == 'mssql': db_dest = MsSqlDao() else: db_dest = PgDao() db_dest.set_params(host_to, port_to, db_to, user_to, pwd_to) dest_ok = db_dest.init_db() except ConfigParser.NoOptionError, e: logger.warning('{connect_databases} %s' % e) return False return (from_ok and dest_ok) def set_task(): task = db_task.DbTask() task.set_database_params(host, port, db, user, pwd, sgbd) task.set_main_params(service_id, interval, sleep, default_start_tstamp, track_all_records) task.set_db_to(db_dest) task.set_settings(settings)