Code_Infilling_C_Cpp / data_generate.py
insub's picture
Update data_generate.py
ab64b7a verified
raw
history blame
2.9 kB
import os
import subprocess
import pandas as pd
from datasets import Dataset
def remove_repo(path):
subprocess.call(f'rm -rf {path}')
def download_git_or_zip(url, target_folder)->None:
"""
download git repo or zip file
under self.projects_path
"""
if url.startswith("https://github.com"):
subprocess.call(f"git clone {url}", cwd=target_folder, shell=True)
else:
subprocess.call(f"wget {url}", cwd=target_folder, shell=True)
zip_name = url.split('/')[-1]
subprocess.call(f"unzip {zip_name}", cwd=target_folder, shell=True)
subprocess.call(f"rm -rf {zip_name}", cwd=target_folder, shell=True)
class data_generator:
def __init__(self):
self.dataset_columns = ["repo_name", "file_path", "content"]
self.important_extension = ['.c','.cpp','.cxx','.cc','cp','CPP','c++','.h','.hpp']
self.projects_path = "data/projects"
self.data_path = "data/opensource_dataset.csv"
targets = [
['Framework', 'fprime', "https://github.com/nasa/fprime"],
['comm', 'asio', "https://github.com/boostorg/asio"],
['parsing', 'tinyxml2', "https://github.com/leethomason/tinyxml2"],
['parsing', 'inifile-cpp', "https://github.com/Rookfighter/inifile-cpp"],
['numerical analysis', 'oneAPI-samples', "https://github.com/oneapi-src/oneAPI-samples"],
['comm', 'rticonnextdds-examples', "https://d2vkrkwbbxbylk.cloudfront.net/sites/default/files/rti-examples/bundles/rticonnextdds-examples/rticonnextdds-examples.zip"],
['comm', 'rticonnextdds-robot-helpers', "https://github.com/rticommunity/rticonnextdds-robot-helpers"],
['comm', 'rticonnextdds-getting-started', "https://github.com/rticommunity/rticonnextdds-getting-started"],
['comm', 'rticonnextdds-usecases', "https://github.com/rticommunity/rticonnextdds-usecases"],
['xyz', 'PROJ', "https://github.com/OSGeo/PROJ"],
]
self.targets = pd.DataFrame(targets, columns=('categori','target_lib','data_source'))
if not os.path.isdir(self.projects_path):
os.makedirs(self.projects_path, exist_ok=True)
def process_file(self, project_name:str, dir_name:str, file_path:str):
"""Processes a single file"""
try:
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()
if content.strip().startswith('\n/*\nWARNING: THIS FILE IS AUTO-GENERATED'):
content=""
elif content.strip().startswith('/*\nWARNING: THIS FILE IS AUTO-GENERATED'):
content=""
except Exception:
content=""
return {
"repo_name": project_name.replace('/','_'),
"file_path": file_path,
"content": content,
}