insub commited on
Commit
8dca7d0
·
verified ·
1 Parent(s): f9b86a7

Delete data_generate.py

Browse files
Files changed (1) hide show
  1. data_generate.py +0 -98
data_generate.py DELETED
@@ -1,98 +0,0 @@
1
- import os
2
- import subprocess
3
- import pandas as pd
4
- from datasets import Dataset
5
-
6
- def remove_repo(path):
7
- subprocess.call(f'rm -rf {path}')
8
-
9
- def download_git_or_zip(url, target_folder)->None:
10
- """
11
- download git repo or zip file
12
- under self.projects_path
13
- """
14
-
15
- if url.startswith("https://github.com"):
16
- subprocess.call(f"git clone {url}", cwd=target_folder, shell=True)
17
- else:
18
- subprocess.call(f"wget {url}", cwd=target_folder, shell=True)
19
- zip_name = url.split('/')[-1]
20
- subprocess.call(f"unzip {zip_name}", cwd=target_folder, shell=True)
21
- subprocess.call(f"rm -rf {zip_name}", cwd=target_folder, shell=True)
22
-
23
- class data_generator:
24
- def __init__(self):
25
- self.dataset_columns = ["repo_name", "file_path", "content"]
26
- self.important_extension = ['.c','.cpp','.cxx','.cc','cp','CPP','c++','.h','.hpp']
27
- self.projects_path = "data/projects"
28
- self.data_path = "data/opensource_dataset.csv"
29
-
30
- targets = [
31
- ['Framework', 'fprime', "https://github.com/nasa/fprime"],
32
- ['comm', 'asio', "https://github.com/boostorg/asio"],
33
- ['parsing', 'tinyxml2', "https://github.com/leethomason/tinyxml2"],
34
- ['parsing', 'inifile-cpp', "https://github.com/Rookfighter/inifile-cpp"],
35
- ['numerical analysis', 'oneAPI-samples', "https://github.com/oneapi-src/oneAPI-samples"],
36
- ['comm', 'rticonnextdds-examples', "https://d2vkrkwbbxbylk.cloudfront.net/sites/default/files/rti-examples/bundles/rticonnextdds-examples/rticonnextdds-examples.zip"],
37
- ['comm', 'rticonnextdds-robot-helpers', "https://github.com/rticommunity/rticonnextdds-robot-helpers"],
38
- ['comm', 'rticonnextdds-getting-started', "https://github.com/rticommunity/rticonnextdds-getting-started"],
39
- ['comm', 'rticonnextdds-usecases', "https://github.com/rticommunity/rticonnextdds-usecases"],
40
- ['xyz', 'PROJ', "https://github.com/OSGeo/PROJ"],
41
- ]
42
- self.targets = pd.DataFrame(targets, columns=('categori','target_lib','data_source'))
43
-
44
- if not os.path.isdir(self.projects_path):
45
- os.makedirs(self.projects_path, exist_ok=True)
46
-
47
- def process_file(self, project_name:str, dir_name:str, file_path:str):
48
- """Processes a single file"""
49
-
50
- try:
51
- with open(file_path, "r", encoding="utf-8") as file:
52
- content = file.read()
53
- if content.strip().startswith('\n/*\nWARNING: THIS FILE IS AUTO-GENERATED'):
54
- content=""
55
- elif content.strip().startswith('/*\nWARNING: THIS FILE IS AUTO-GENERATED'):
56
- content=""
57
-
58
- except Exception:
59
- content=""
60
-
61
- return {
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