def create_new_database(path, tables_script_filename): db_file = open(path, 'w') db_file.close() connection = SQLiteConnector() connection.create_connection(path) create_tables(connection.get_cursor(), tables_script_filename) return connection
def update_database(path): connection = SQLiteConnector() connection.create_connection(path) tables = list(connection.get_cursor().execute("SELECT name FROM sqlite_master WHERE type='table'")) if tables == []: logging.error("Database is empty, can't update it") exit() return connection
def main(): args, input_db_config, output_db_config, log_filename, create_index = get_arguments() if log_filename: logging.basicConfig(filename=log_filename, format='[%(asctime)s] %(levelname)s: %(message)s', level=logging.INFO) else: logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', level=logging.INFO) if os.path.isfile(input_db_config): pesto_connector = SQLiteConnector() pesto_connector.create_connection(input_db_config) logging.info('Connected to Pesto database') else: logging.error('Input database file not found') exit() output_connector = get_mysql_connector(output_db_config) output_connector.close() try: pesto_cur = pesto_connector.get_cursor() recommender = MorePopularNextProblemRecommender(pesto_cur, output_db_config) if create_index: recommender.create_index() if args['start_from']: between = (args['start_from'], args['end']) recommender.fill_recommendations_table(between) else: recommender.fill_recommendations_table() except SystemExit: raise except: logging.critical('The following exception was caught:') print_exception(*sys.exc_info()) pesto_connector.close_connection() logging.info('Pesto connection closed') exit() pesto_connector.close_connection() logging.info('Pesto connection closed')