Example #1
0
change_type.insert(1, 'filepath')
csvwriter.writerow(change_type)  # writerow写入一行数据,writerows写入多行数据
csvfile.close()


# 输入两个版本的文件所在目录,left和right列表中保存了用于比较的两个版本对应路径下的同名文件
start = time.clock()
filedir = 'E:\PyCharm Workspace\Change Extraction'
left_filename = 'scipy-0.16.0'
right_filename = 'scipy-0.16.1'
left, right = file_find(filedir, left_filename, right_filename)


# 对两个版本程序的对应源代码文件进行比较
csvfile = open('ChangeType_Extraction.csv', 'a', newline='')  # 设置newline参数,去掉输出中的空行
csvwriter = csv.writer(csvfile, dialect='excel')
count = 0  # 记录两个版本程序不同文件的数量
for i in range(len(left)):
    # 利用filecmp.cmp比较两个文件是否相同,不相同的用code_change_extraction抽取变更
    if filecmp.cmp(left[i], right[i]) is False:
        change_type_percentage = code_change_extraction(left[i], right[i])
        count += 1
        change_type_percentage.insert(0, os.path.basename(left[i]))
        change_type_percentage.insert(1, os.path.dirname(left[i]))
        csvwriter.writerow(change_type_percentage)


print('\nThere are %d different files between %s and %s ' % (count, left_filename, right_filename))
csvfile.close()
end = time.clock()
print('time: %fs' % (end - start))
Example #2
0
change_type.insert(0, 'filename')  # 利用insert方法插入数据到列表中,便于以一行的方式写入csv文件
change_type.insert(1, 'filepath')
csvwriter.writerow(change_type)  # writerow写入一行数据,writerows写入多行数据
csvfile.close()

# 输入两个版本的文件所在目录,left和right列表中保存了用于比较的两个版本对应路径下的同名文件
start = time.clock()
filedir = 'E:\PyCharm Workspace\Change Extraction'
left_filename = 'scipy-0.16.0'
right_filename = 'scipy-0.16.1'
left, right = file_find(filedir, left_filename, right_filename)

# 对两个版本程序的对应源代码文件进行比较
csvfile = open('ChangeType_Extraction.csv', 'a',
               newline='')  # 设置newline参数,去掉输出中的空行
csvwriter = csv.writer(csvfile, dialect='excel')
count = 0  # 记录两个版本程序不同文件的数量
for i in range(len(left)):
    # 利用filecmp.cmp比较两个文件是否相同,不相同的用code_change_extraction抽取变更
    if filecmp.cmp(left[i], right[i]) is False:
        change_type_percentage = code_change_extraction(left[i], right[i])
        count += 1
        change_type_percentage.insert(0, os.path.basename(left[i]))
        change_type_percentage.insert(1, os.path.dirname(left[i]))
        csvwriter.writerow(change_type_percentage)

print('\nThere are %d different files between %s and %s ' %
      (count, left_filename, right_filename))
csvfile.close()
end = time.clock()
print('time: %fs' % (end - start))
Example #3
0
import os
from change_type import change_type_enum
from change_extraction import code_change_extraction

# 写变更结果文件头,w表示写文本文件,wb写二进制文件,a追加写文件
csvfile = open('ChangeType_Extraction_File.csv', 'w',
               newline='')  # 设置newline参数,去掉输出中的空行
csvwriter = csv.writer(csvfile, dialect='excel')
change_type = change_type_enum()
change_type.insert(0, 'left_file_name')  # 利用insert方法插入数据到列表中,便于以一行的方式写入csv文件
change_type.insert(1, 'right_file_name')
csvwriter.writerow(change_type)  # writerow写入一行数据,writerows写入多行数据
csvfile.close()

# 输入被比较的两个文件名
start = time.clock()
left_filename = 'scipy-0.16.0\scipy\linalg\_expm_frechet.py'
right_filename = 'scipy-0.16.1\scipy\linalg\_expm_frechet.py'

# 对相同路径下的两个文件进行比较
csvfile = open('ChangeType_Extraction_File.csv', 'a',
               newline='')  # 设置newline参数,去掉输出中的空行
csvwriter = csv.writer(csvfile, dialect='excel')
change_type_percentage = code_change_extraction(left_filename, right_filename)
change_type_percentage.insert(0, os.path.basename(left_filename))
change_type_percentage.insert(1, os.path.basename(right_filename))
csvwriter.writerow(change_type_percentage)
csvfile.close()

end = time.clock()
print('time: %fs' % (end - start))
final_modified_file_list = log_file_process('nameonly.txt')


# 用git的check out命令还原commit之前的文件,对更改前后的两个文件进行比较
unchanged_file_dir = 'E:\\PyCharm Workspace\\Change Extraction\\numpy-master'
changed_file_dir = 'E:\\PyCharm Workspace\\Change Extraction\\gitnumpy'
csvfile = open('ChangeType_Extraction_File.csv', 'a', newline='')  # 设置newline参数,去掉输出中的空行
csvwriter = csv.writer(csvfile, dialect='excel')
# 初始化Git repository,便于后续调用checkout命令(告诉程序对哪个库执行checkout命令)
subprocess.getstatusoutput('git init')
count = 0
for i in range(len(final_modified_file_list)):
    commit_id = final_modified_file_list[i][0]
    filename = final_modified_file_list[i][1]
    print(count, commit_id)
    count += 1
    subprocess.getstatusoutput('git checkout ' + commit_id + ' ' + filename)
    changed_file = os.path.join(changed_file_dir, filename)
    unchanged_file = os.path.join(unchanged_file_dir, filename)
    # 有可能出现增加或删除某个文件的操作,故对每个"文件"是否是文件进行判断
    if os.path.isfile(changed_file) and os.path.isfile(unchanged_file) and \
            changed_file.endswith('.py') and unchanged_file.endswith('.py'):
        print(filename)
        change_type_percentage = code_change_extraction(changed_file, unchanged_file)
        change_type_percentage.insert(0, os.path.basename(commit_id))
        change_type_percentage.insert(1, filename)
        csvwriter.writerow(change_type_percentage)
csvfile.close()

end = time.clock()
print('time: %fs' % (end - start))
Example #5
0
from change_type import change_type_enum
from change_extraction import code_change_extraction


# 写变更结果文件头,w表示写文本文件,wb写二进制文件,a追加写文件
csvfile = open('ChangeType_Extraction_File.csv', 'w', newline='')  # 设置newline参数,去掉输出中的空行
csvwriter = csv.writer(csvfile, dialect='excel')
change_type = change_type_enum()
change_type.insert(0, 'left_file_name')  # 利用insert方法插入数据到列表中,便于以一行的方式写入csv文件
change_type.insert(1, 'right_file_name')
csvwriter.writerow(change_type)  # writerow写入一行数据,writerows写入多行数据
csvfile.close()


# 输入被比较的两个文件名
start = time.clock()
left_filename = 'scipy-0.16.0\scipy\linalg\_expm_frechet.py'
right_filename = 'scipy-0.16.1\scipy\linalg\_expm_frechet.py'


# 对相同路径下的两个文件进行比较
csvfile = open('ChangeType_Extraction_File.csv', 'a', newline='')  # 设置newline参数,去掉输出中的空行
csvwriter = csv.writer(csvfile, dialect='excel')
change_type_percentage = code_change_extraction(left_filename, right_filename)
change_type_percentage.insert(0, os.path.basename(left_filename))
change_type_percentage.insert(1, os.path.basename(right_filename))
csvwriter.writerow(change_type_percentage)
csvfile.close()

end = time.clock()
print('time: %fs' % (end - start))