-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileListGetter.py
executable file
·89 lines (72 loc) · 3.23 KB
/
fileListGetter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import re
def get_java_file_list_from_root(filepath, suffix="", file_lists_dir="fileListsTest"):
# 遍历filepath下所有java文件,包括子目录
files = os.listdir(filepath)
reg = re.compile(r"\..*")
regForJava = re.compile(r"\.java")
regForGradle = re.compile(r"\.gradle|\.sh|\.pro|\.xml|\.bat|\.jar|\.MD|\.md|\.png|\.txt|\.json|\.flat|\.class")
curDiry = os.path.dirname(os.path.realpath(__file__))
for fi in files:
if reg.match(fi) is not None or regForGradle.search(fi) is not None:
continue
fi_d = os.path.join(filepath, fi)
if os.path.isdir(fi_d):
get_java_file_list_from_root(fi_d, suffix, file_lists_dir)
else:
if regForJava.search(fi_d) is None:
continue
# print(os.path.join(filepath, fi_d)) # 打印的是单个java文件的绝对路径,因此这个循环会把单个repo里所有java文件打印
data = os.path.join(filepath, fi_d) + "\n"
fw = open(os.path.join(curDiry, file_lists_dir, "fileList_" + suffix + ".txt"), 'a+')
# 在这里修改生成的一堆fileList.txt放在哪个文件夹下
fw.write(data)
fw.close()
def get_trunc_file_path(file_lists_dir, suffix=""):
curDir = os.path.dirname(os.path.realpath(__file__))
return os.path.join(curDir, file_lists_dir, "fileList_" + suffix + ".txt")
def trunc_all_context(filePath):
fw = open(filePath, 'a+')
fw.truncate(0)
fw.close()
def get_all_repos_absolute_from_a_group(group_dir):
repo_absolute_dirs = os.listdir(group_dir)
dir_num = len(repo_absolute_dirs)
res = []
reg = re.compile(r"\..*")
for repo in repo_absolute_dirs:
if reg.search(repo):
continue
str_res = group_dir + repo
res.append(str_res)
return res
def get_all_repo_name(group_dir):
repo_names = os.listdir(group_dir)
res = []
reg = re.compile(r"\..*")
for name in repo_names:
if reg.search(name):
continue
res.append(name)
return res
def wrt_all_repo_file_lists_txt(group_dir, repo_dirs, file_lists_dir="fileListsTest"):
repo_names = get_all_repo_name(group_dir)
length = len(repo_dirs)
for i in range(length):
path = get_trunc_file_path(file_lists_dir, repo_names[i])
trunc_all_context(path) # 为了覆写所有Java文件,必须清空上一次运行时的结果
print("repo_dir: %s >>>> repo name: %s" % (repo_dirs[i], repo_names[i]))
get_java_file_list_from_root(repo_dirs[i], repo_names[i], file_lists_dir)
def get_file_lists_allinone(group_dir, file_lists_dir):
repo_absolute_dirs = get_all_repos_absolute_from_a_group(group_dir)
wrt_all_repo_file_lists_txt(group_dir, repo_absolute_dirs, file_lists_dir)
# 递归遍历目录下所有文件
if __name__ == "__main__":
# get_file_lists_allinone("/Users/wangpei/workspace/")
get_file_lists_allinone("/Users/wangpei/git-groups/", "fileListsFromGroupSDK")
# curDir = os.path.dirname(os.path.realpath(__file__))
# fileDir = os.path.join(curDir, "fileList.txt")
# trunc_all_context(fileDir)
# get_java_file_list_from_root('/Users/wangpei/workspace/')