bad_clone_prediction/RCDMain.py

49 lines
1.2 KiB
Python

# aim: this is the main file of Risky Clone Detection
# author: Xunhui Zhang, Yan Zhong
import queue
from typing import List
import GlobalConstants
from ConfigOperator import ConfigOperator
from FileOperator import FileOperator
from models.RepoInfo import RepoInfo
from MySQLOperator import MySQLOperator
from RepoExecutor import RepoExecutorThread
# load repos
repoInfos: List[RepoInfo] = FileOperator("repos").load_repos()
# create repositories table
mysqlOp = MySQLOperator(config_path=GlobalConstants.CONFIG_PATH)
mysqlOp.create_repositories_table()
# init repositories table
mysqlOp.init_repositories_table(repoInfos=repoInfos)
workQueue = queue.Queue()
# handle each repo
for repoInfo in repoInfos:
# query the id of this repository
repo_id = mysqlOp.get_repo_id_by_names(repoInfo=repoInfo)
repoInfo.id = repo_id
workQueue.put(repoInfo)
threads = []
for i in range(
int(
ConfigOperator(config_path=GlobalConstants.CONFIG_PATH).read_config()["RCD"][
"thread_num"
]
)
):
t = RepoExecutorThread(
name="RepoExecutorThread-" + str(i + 1),
q=workQueue,
config_path=GlobalConstants.CONFIG_PATH,
)
t.start()
threads.append(t)
for t in threads:
t.join()
print("Finish")