forked from SMAT-Lab/SnifferDog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlook_for_requirement.py
executable file
·68 lines (57 loc) · 2.05 KB
/
look_for_requirement.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
import os
import sys
import json
from multiprocessing import Pool
def get_path_by_extension(root_dir):
filenames = []
paths = []
for root, dirs, files in os.walk(root_dir):
files = [f for f in files if not f[0] == '.'] # skip hidden files such as git files
dirs[:] = [d for d in dirs if not d[0] == '.']
for f in files:
filenames.append(os.path.join(root, f))
return (root_dir, filenames)
def is_contain_yml(filenames):
for fn in filenames:
if fn.endswith('.yml'):
return True
return False
def is_contain_pipfile(filenames):
return 'Pipfile' in filenames
def parse_module_names():
all_repos = open('folder_names.txt', 'r').readlines()
all_repos = list(map(lambda x:os.path.join('/mnt/fit-Knowledgezoo/Github_repos_download/data/', x.strip()), all_repos))
#all_repos = all_repos[0:50]
results = {}
n_threads = 4
with Pool(n_threads) as pool:
results = pool.map(get_path_by_extension, all_repos)
f = open('config_stat.json','w')
f.write(json.dumps(results))
f.close()
#for folder in all_repos[0:100]:
# count += 1
# if count%1000==0:
# f = open('config_stat.json','w')
# f.write(json.dumps(results))
# f.close()
# print(count)
#folder = folder.strip()
#repo_dir = os.path.join('/mnt/fit-Knowledgezoo/Github_repos_download/data/', folder)
#req_dir = os.path.join(repo_dir, 'requirements.txt')
#if os.path.exists(req_dir):
#filenames = get_path_by_extension(repo_dir)
#results[repo_dir]= filenames
#results[repo_dir]= {
# "conda": is_contain_yml(filenames),
# 'pip': is_contain_pipfile(filenames),
# 'req': 'requirements.txt' in filenames,
# 'setup': 'setup.py' in filenames
# }
#f = open('config_stat.json','w')
#f.write(json.dumps(results))
#f.close()
def main():
parse_module_names()
if __name__ == '__main__':
main()