-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added file to extract the code from the chromium project
- Loading branch information
1 parent
c42b1ba
commit b43b8c1
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from os import listdir | ||
from os.path import isfile, join | ||
import random | ||
|
||
files = [] | ||
|
||
def is_file(path, file): | ||
return isfile(join(path, file)) | ||
|
||
def return_files_and_folders(path): | ||
# To limit the no of prints, to make the process fast | ||
if random.randint(0,100) == 50: | ||
print(f'--Processing file {path}--') | ||
|
||
files = [] | ||
folders = [] | ||
directories = listdir(path) | ||
|
||
for directory in directories: | ||
file = is_file(path, directory) | ||
|
||
if file: | ||
files.append(join(path, directory)) | ||
else: | ||
folders.append(join(path, directory)) | ||
|
||
return files, folders | ||
|
||
def process_files(path): | ||
global files | ||
|
||
_files, _folders = return_files_and_folders(path) | ||
|
||
files = files + _files | ||
|
||
for folder in _folders: | ||
process_files(folder) | ||
|
||
def filter_files(): | ||
filtered_files = [] | ||
extensions = ['c', 'h', 'cpp', 'cc', 'c++', 'cp', 'cxx', 'ii', 'cxx'] | ||
|
||
for file in files: | ||
extension = file.split('/')[-1].split('.')[-1] | ||
|
||
if extension in extensions: | ||
filtered_files.append(file) | ||
|
||
return filtered_files | ||
|
||
process_files("data/chromium-master") | ||
filtered_files = filter_files() | ||
|
||
with open("data/code_list.txt", 'w') as f: | ||
f.write("\n".join(filtered_files)) |