<s> __author__ = '<STR_LIT>' <EOL> import mysql . connector <EOL> from mysql . connector import errorcode <EOL> from datetime import datetime <EOL> class InitDbSchema ( ) : <EOL> def __init__ ( self , db_name , logger ) : <EOL> self . logger = logger <EOL> self . DB_NAME = db_name <EOL> CONFIG = { <EOL> '<STR_LIT:user>' : '<STR_LIT:root>' , <EOL> '<STR_LIT:password>' : '<STR_LIT:root>' , <EOL> '<STR_LIT:host>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT:port>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> self . cnx = mysql . connector . connect ( ** CONFIG ) <EOL> def init_database ( self ) : <EOL> self . init_tables ( ) <EOL> self . init_views ( ) <EOL> self . init_functions ( ) <EOL> self . init_stored_procedures ( ) <EOL> def init_views ( self ) : <EOL> cursor = self . cnx . cursor ( ) <EOL> num_files_deleted = """<STR_LIT>""" <EOL> num_files_present = """<STR_LIT>""" <EOL> num_branches = """<STR_LIT>""" <EOL> number_file_modification_per_commit = """<STR_LIT>""" <EOL> avg_number_file_modification_per_commit = """<STR_LIT>""" <EOL> num_empty_lines_deleted_files = """<STR_LIT>""" <EOL> num_empty_lines_present_files = """<STR_LIT>""" <EOL> num_commented_lines_deleted_files = """<STR_LIT>""" <EOL> num_commented_lines_present_files = """<STR_LIT>""" <EOL> num_lines_deleted_files = """<STR_LIT>""" <EOL> num_lines_present_files = """<STR_LIT>""" <EOL> num_distinct_commits = """<STR_LIT>""" <EOL> num_commits_in_references = """<STR_LIT>""" <EOL> num_developers = """<STR_LIT>""" <EOL> repo_metrics = """<STR_LIT>""" <EOL> developer_weekly_activity_metrics = """<STR_LIT>""" <EOL> totalChanges = """<STR_LIT>""" <EOL> num_commented_lines_per_author = """<STR_LIT>""" <EOL> num_total_commented_lines = """<STR_LIT>""" <EOL> developer_project_activity_metrics = """<STR_LIT>""" <EOL> cursor . execute ( num_files_deleted ) <EOL> cursor . execute ( num_files_present ) <EOL> cursor . execute ( num_branches ) <EOL> cursor . execute ( number_file_modification_per_commit ) <EOL> cursor . execute ( avg_number_file_modification_per_commit ) <EOL> cursor . execute ( num_empty_lines_deleted_files ) <EOL> cursor . execute ( num_empty_lines_present_files ) <EOL> cursor . execute ( num_commented_lines_deleted_files ) <EOL> cursor . execute ( num_commented_lines_present_files ) <EOL> cursor . execute ( num_lines_deleted_files ) <EOL> cursor . execute ( num_lines_present_files ) <EOL> cursor . execute ( num_distinct_commits ) <EOL> cursor . execute ( num_commits_in_references ) <EOL> cursor . execute ( num_developers ) <EOL> cursor . execute ( repo_metrics ) <EOL> cursor . execute ( developer_weekly_activity_metrics ) <EOL> cursor . execute ( totalChanges ) <EOL> cursor . execute ( num_commented_lines_per_author ) <EOL> cursor . execute ( num_total_commented_lines ) <EOL> cursor . execute ( developer_project_activity_metrics ) <EOL> cursor . close ( ) <EOL> def init_functions ( self ) : <EOL> cursor = self . cnx . cursor ( ) <EOL> get_file_history = """<STR_LIT>""" <EOL> levenshtein_distance = """<STR_LIT>""" <EOL> soundex_match = """<STR_LIT>""" <EOL> cursor . execute ( get_file_history ) <EOL> cursor . execute ( levenshtein_distance ) <EOL> cursor . execute ( soundex_match ) <EOL> cursor . close ( ) <EOL> def init_stored_procedures ( self ) : <EOL> cursor = self . cnx . cursor ( ) <EOL> get_file_version = """<STR_LIT>""" <EOL> get_file_version_by_line = """<STR_LIT>""" <EOL> get_file_version_compact = """<STR_LIT>""" <EOL> cursor . execute ( get_file_version ) <EOL> cursor . execute ( get_file_version_by_line ) <EOL> cursor . execute ( get_file_version_compact ) <EOL> cursor . close ( ) <EOL> def init_tables ( self ) : <EOL> cursor = self . cnx . cursor ( ) <EOL> drop_database_if_exists = "<STR_LIT>" + self . DB_NAME <EOL> cursor . execute ( drop_database_if_exists ) <EOL> create_database = "<STR_LIT>" + self . DB_NAME <EOL> cursor . execute ( create_database ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> create_table_repositories = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_references = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_developers = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_commits = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_commit_parent = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_commits2reference = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_files = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_file_renamed = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_file_modifications = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> create_table_lines = "<STR_LIT>" + self . DB_NAME + "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> use_database = "<STR_LIT>" + self . DB_NAME <EOL> cursor . execute ( create_table_repositories ) <EOL> cursor . execute ( create_table_references ) <EOL> cursor . execute ( create_table_developers ) <EOL> cursor . execute ( create_table_commits ) <EOL> cursor . execute ( create_table_commit_parent ) <EOL> cursor . execute ( create_table_commits2reference ) <EOL> cursor . execute ( create_table_files ) <EOL> cursor . execute ( create_table_file_renamed ) <EOL> cursor . execute ( create_table_file_modifications ) <EOL> cursor . execute ( create_table_lines ) <EOL> cursor . execute ( use_database ) <EOL> cursor . close ( ) <EOL> return <EOL> def execute ( self ) : <EOL> start_time = datetime . now ( ) <EOL> self . init_database ( ) <EOL> self . cnx . close ( ) <EOL> end_time = datetime . now ( ) <EOL> minutes_and_seconds = divmod ( ( end_time - start_time ) . total_seconds ( ) , <NUM_LIT> ) <EOL> self . logger . info ( "<STR_LIT>" + str ( minutes_and_seconds [ <NUM_LIT:0> ] ) <EOL> + "<STR_LIT>" + str ( round ( minutes_and_seconds [ <NUM_LIT:1> ] , <NUM_LIT:1> ) ) + "<STR_LIT>" ) <EOL> return </s>
