cronpy/update_preprod.py

34 lines
1.1 KiB
Python
Raw Normal View History

2020-10-03 21:17:53 +00:00
from traceback import format_exc
import sys
from core.webutils import WebUtils
class UpdatePreprod(WebUtils):
def __init__(self):
super().__init__(module_='update_preprod')
tables = list(self.mysqldb.get_tables(self.args.table))
self.nb_tasks = len(tables)
self.start()
self.update_tables(tables)
self.end()
def update_tables(self, tables):
for table in tables:
try:
self.mysqldb.exec('DROP TABLE IF EXISTS preprod.{table}'.format(table=table))
self.mysqldb.exec('CREATE TABLE preprod.{table} LIKE bob.{table}'.format(table=table))
self.mysqldb.exec('INSERT INTO preprod.{table} SELECT * FROM bob.{table}'.format(table=table))
except BaseException as e:
self.logger.error('[-] table {}: {} - {}\n{}'.format(table, type(e), e, format_exc()))
self.errors += 1
else:
self.logger.info('[+] table {}: OK'.format(table))
self.tasks_done += 1
self.quantity += 1
if __name__ == '__main__':
UpdatePreprod()