Update data_generate.py
Browse files- data_generate.py +65 -1
data_generate.py
CHANGED
|
@@ -1 +1,65 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
}
|