Update data_generate.py
Browse files- data_generate.py +34 -1
data_generate.py
CHANGED
@@ -62,4 +62,37 @@ class data_generator:
|
|
62 |
"repo_name": project_name.replace('/','_'),
|
63 |
"file_path": file_path,
|
64 |
"content": content,
|
65 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
"repo_name": project_name.replace('/','_'),
|
63 |
"file_path": file_path,
|
64 |
"content": content,
|
65 |
+
}
|
66 |
+
|
67 |
+
def read_repository_files(self, project_name:str)->pd.DataFrame:
|
68 |
+
"""
|
69 |
+
project_name : str
|
70 |
+
repo_df : pd.DataFrame
|
71 |
+
"""
|
72 |
+
repo_df = pd.DataFrame(columns=self.dataset_columns)
|
73 |
+
file_paths = []
|
74 |
+
pwd = os.path.join(self.projects_path, project_name)
|
75 |
+
for root, _, files in os.walk(pwd):
|
76 |
+
for file in files:
|
77 |
+
file_path = os.path.join(root, file)
|
78 |
+
|
79 |
+
if file.endswith(tuple(self.important_extension)):
|
80 |
+
file_paths.append((os.path.dirname(root), file_path))
|
81 |
+
|
82 |
+
print("#"*10, f"{project_name} Total file paths:{len(file_paths)}", "#"*10)
|
83 |
+
|
84 |
+
for i, (dir_name, file_path) in enumerate(file_paths):
|
85 |
+
file_content = self.process_file(project_name, dir_name, file_path)
|
86 |
+
assert isinstance(file_content, dict)
|
87 |
+
if file_content["content"] != "":
|
88 |
+
tmp_df = pd.DataFrame.from_dict([file_content])
|
89 |
+
repo_df = pd.concat([repo_df, tmp_df])
|
90 |
+
if len(repo_df)==0:
|
91 |
+
repo_df = {
|
92 |
+
"repo_name": project_name,
|
93 |
+
"file_path": "",
|
94 |
+
"content": "",
|
95 |
+
}
|
96 |
+
repo_df = pd.DataFrame.from_dict([repo_df])
|
97 |
+
assert isinstance(repo_df, pd.DataFrame)
|
98 |
+
return repo_df
|