Fix for issue 7
This commit is contained in:
parent
7b13874dad
commit
283885e14c
|
@ -8,6 +8,6 @@ This is a project for finding factors related to bad clones.
|
|||
- activate the environment using command `conda activate bad_clone`
|
||||
- install dependent python packages using command `pip install -r requirements.txt`
|
||||
- Mysql:
|
||||
- this project uses [Mysql](https://dev.mysql.com/downloads/installer/) 8.0.30
|
||||
- this project uses [Mysql](https://dev.mysql.com/downloads/) 8.0.30
|
||||
- copy the configuration template and rename it using command`cp ./config.template.yml ./config.yml`
|
||||
- uncomment and set the section of the config with the hints in the template
|
||||
- set the section of the config with the hints in the template
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
######### MySQL Configuration Template ##############################################################################
|
||||
######### Configuration Template ##############################################################################
|
||||
#
|
||||
# To use, copy this template and name it 'config.yml'
|
||||
#
|
||||
# cp ./config.template.yml ./config.yml
|
||||
#
|
||||
# Now, uncomment the section of the config with following hints.
|
||||
#
|
||||
################################################################################################################
|
||||
|
||||
mysql:
|
||||
|
||||
################################################################################################################
|
||||
#
|
||||
# The host and port can be set by uncommenting and editing the following lines.
|
||||
|
@ -16,18 +16,18 @@
|
|||
#
|
||||
################################################################################################################
|
||||
|
||||
# host: "127.0.0.1"
|
||||
# port: 3306
|
||||
host: "127.0.0.1"
|
||||
port: 3306
|
||||
|
||||
################################################################################################################
|
||||
# Set the database you want to connect.
|
||||
################################################################################################################
|
||||
|
||||
# database: "database_name"
|
||||
database: "database_name"
|
||||
|
||||
################################################################################################################
|
||||
# Set the user and corresponding password of your mysql.
|
||||
################################################################################################################
|
||||
|
||||
# user: "username"
|
||||
# passwd: "password"
|
||||
user: "username"
|
||||
passwd: "password"
|
||||
|
|
|
@ -30,21 +30,20 @@ class MySQLOperator(object):
|
|||
- The connection of a database
|
||||
"""
|
||||
try:
|
||||
file = open(configPath)
|
||||
config = yaml.safe_load(file)
|
||||
self.host = config.get("host")
|
||||
self.port = config.get("port")
|
||||
self.database = config.get("database")
|
||||
self.username = config.get("user")
|
||||
self.password = config.get("passwd")
|
||||
self.connection = pymysql.connect(**config)
|
||||
self.cursor = self.connection.cursor()
|
||||
print("Connect success!")
|
||||
file.close()
|
||||
with open(configPath) as file:
|
||||
config = yaml.safe_load(file)
|
||||
mysql_config = config.get("mysql")
|
||||
self.host = mysql_config.get("host")
|
||||
self.port = mysql_config.get("port")
|
||||
self.database = mysql_config.get("database")
|
||||
self.username = mysql_config.get("user")
|
||||
self.password = mysql_config.get("passwd")
|
||||
self.connection = pymysql.connect(**mysql_config)
|
||||
self.cursor = self.connection.cursor()
|
||||
print("Connect successfully!")
|
||||
return self.connection
|
||||
except Exception as e:
|
||||
print("Connect failure:", e)
|
||||
file.close()
|
||||
|
||||
|
||||
# The test of the function connect is in test.py
|
||||
|
|
42
utils.py
42
utils.py
|
@ -10,6 +10,36 @@ from dulwich.repo import Repo
|
|||
from models.BlobInfo import BlobInfo
|
||||
|
||||
|
||||
def download_project(gitAddress):
|
||||
"""
|
||||
Function: download a project in git
|
||||
input:
|
||||
- gitAddress: the address of a git repo
|
||||
"""
|
||||
try:
|
||||
os.chdir("projects")
|
||||
os.popen("git clone " + gitAddress)
|
||||
print("Clone successfully!")
|
||||
except Exception as e:
|
||||
print("Clone failure:", e)
|
||||
|
||||
|
||||
def download_projects(addresslist):
|
||||
"""
|
||||
Function: download a list of projects in git
|
||||
input:
|
||||
- addresslist: a list of the address of git repo
|
||||
"""
|
||||
try:
|
||||
os.chdir("projects")
|
||||
for address in addresslist:
|
||||
os.popen("git clone " + address)
|
||||
print("Clone" + address + "successfuly!")
|
||||
print("Clone finish!")
|
||||
except Exception as e:
|
||||
print("Clone failure:", e)
|
||||
|
||||
|
||||
def load_blob_objects(path):
|
||||
"""
|
||||
Function: Find all blob objects in a given repo and make a list
|
||||
|
@ -46,7 +76,8 @@ def write_source_files(path, list):
|
|||
"""
|
||||
Function: Write all source code to a new folder
|
||||
input:
|
||||
- path:the directory of a new folder, the code list in type byte
|
||||
- path: the directory of a new folder,
|
||||
- list: the code list in type byte
|
||||
"""
|
||||
folderpath = os.path.join(path, "sourceFiles")
|
||||
os.mkdir(folderpath)
|
||||
|
@ -136,12 +167,3 @@ test extract_commit_blob_relation function
|
|||
"""
|
||||
# result = extract_commit_blob_relation(repo_path="NIL")
|
||||
# print(result)
|
||||
|
||||
|
||||
# a test for local repo
|
||||
# list = loadBlobObjects("C:/Users/Administrator/redis")
|
||||
# print(list[0])
|
||||
# writeSourceCode("C:/Users/Administrator/redis/1.txt", list[0])
|
||||
# writeSourceFiles("C:/Users/Administrator/redis", list)
|
||||
|
||||
# print(loadProjectList("testForLoadProjects.txt"))
|
||||
|
|
Loading…
Reference in New Issue