def copyConfirm(listfile, dir): content = read_file(listfile) projects = content.split('\n') error_count = 0 for i in os.listdir(dir): if i in projects: continue else: error_count += 1 print i print "error count: ", error_count
def copy_projects_from_gitbase(listfile, gitbase, dst): print 'Copying the target projects...' count_copy = 0 target_list = read_file(listfile) for i in target_list.split('\n'): if i == '.DS_Store': continue count_copy += 1 print "Processing " + i + '...' + str(count_copy) try: copytree(gitbase + i, dst + i) except: print '!!!!!!!!!!!!!!!!!!!!!!!! Copy failed with ' + i print 'Done..'
def buildLinePosDict(file): contents = read_file(file) char = len(contents) line_endpos_dict = {} pos = 0 maxline = len(contents.splitlines()) print maxline for i, line in enumerate(contents.split('\n'), 1): if maxline < i: break if line == '': pos += 1 else: pos += len(line) + 1 print i, pos line_endpos_dict[i] = pos print char print pos return line_endpos_dict
if not os.path.isdir(target_destination_detail): os.mkdir(target_destination_detail) copytree(i, target_destination_detail) else: print 'The directory is already existing..' if __name__ == '__main__': src = '/Users/Falcon/Desktop/GitArchive/Git_testcode_only/' # refineDirectories(src) # check_for_duplicates(src) # rm_dup(src) # javafiles = java_files_from_dir(src) # count = 0 # for i in javafiles: # count += 1 # # print count aset = set() contents = read_file( '/Users/Falcon/Desktop/projects_with_test_code_only.txt') for i in contents.split('\n'): aset.add(i) for i in aset: write_file('/Users/Falcon/Desktop/projects_test_code_only.txt', i) pass
# {hunk: lines} dict 생성 (한 파일 당, 분산된 여러 hunk 가 있을 수 있음.) hunk_num = 0 hunk_lines_dict = {} # diff 정보 가져오기 # hunk_lines_dict # h[1]:63..74 // 63, 64, 65, ... , 74 # h[2]:78..89 // hunk_lines_dict = getDiffNew(user_repo_, commit_hash, prev_hash, file_name) if hunk_lines_dict is None: print("Failed to get the diff for ...Commit: %s /// File: %s" % (commit_hash, file_hash)) continue # 2개의 파일을 받아서 [변경된 라인 번호] + [각 라인 별 Position range] 얻기 before = read_file(before_file_path) after = read_file(after_file_path) # {line: position} dict 생성 (한 라인 당, position) f_pos_1 = 0 f_pos_2 = 0 f_init_line_num = 0 line_positions_dict = {} for i in before.split('\n'): f_init_line_num += 1 f_pos_2 = f_pos_1 + i.__len__() # line_positions_dict # l[0]:0..12 # l[1]:13..21 line_positions_dict[f_init_line_num] = str(f_pos_1) + ".." + str(f_pos_2)
def charCounter(st): count = 0 for _ in read_file(st): count += 1 return count
def stripFile(file): return read_file(file).strip()