Skip to content

Commit 50c889d

Browse files
committed
Changed imports and file references to be relative to SecurityKeywordBasedSearchTool/ and added checks for missing files
1 parent 51dd82c commit 50c889d

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

SecurityKeywordsBasedSearchTool/SecFeatFinder/FeatureModel.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from SecurityKeywordsBasedSearchTool.SecFeatFinder.Feature import Feature
3+
from Feature import Feature
44

55

66
def add_to_fm(fm, taxonomy, feature_name, tag):
@@ -35,6 +35,11 @@ def create_feature_model_file(repo_dir, custom_features, library_features, fm):
3535

3636

3737
def read_feature_model(file):
38+
# This function reads a feature mode from a file
39+
if not os.path.exists(file):
40+
print(f"Keywords file not found at { os.path.abspath(file)}.")
41+
return None
42+
3843
with open(file, "r") as f:
3944
depths = {-1: 0}
4045
stack = []

SecurityKeywordsBasedSearchTool/SecFeatFinder/main.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
2+
import sys
23
import json
34
import re
45
from collections import Counter, defaultdict
56

6-
from SecurityKeywordsBasedSearchTool.SecFeatFinder.Feature import Feature
7-
from SecurityKeywordsBasedSearchTool.SecFeatFinder.FeatureModel import add_to_fm, create_feature_model_file, \
7+
from Feature import Feature
8+
from FeatureModel import add_to_fm, create_feature_model_file, \
89
read_feature_model
9-
from SecurityKeywordsBasedSearchTool.SecFeatFinder.GitClient import clone_repository
10+
from GitClient import clone_repository
1011

1112

1213
def flatten_keywords(keyword_dict):
@@ -29,7 +30,8 @@ def process_feature_annotations(features_file, repo_dir, flattened_keywords, tax
2930
with open(features_file, "r") as file:
3031
data = json.load(file)
3132
else:
32-
data = {}
33+
print(f"Features file not found at { os.path.abspath(features_file)}.")
34+
sys.exit(1)
3335

3436
library_features = set()
3537

@@ -298,19 +300,26 @@ def print_top_keywords(keyword_counter, total_matches):
298300

299301
def main():
300302
repo_url = input("Enter the repository URL: ")
301-
keyword_file = "SecList.json"
302-
features_file = "features.json"
303-
taxonomy_file = "taxonomy.feature_model"
303+
keyword_file = "SecFeatFinder/git@github.com:apache/tomcat.gitSecList.json"
304+
features_file = "../Resources/features.json"
305+
taxonomy_file = "../Resources/taxonomy.feature_model"
304306

305307
taxonomy = read_feature_model(taxonomy_file)
308+
if taxonomy is None:
309+
print("Could not load taxonomy")
310+
sys.exit(0)
306311

307312
# Clone the repository
308313
project_dir, repo_name = clone_repository(repo_url)
309314

310315
# Load keywords
311-
with open(keyword_file, "r") as file:
312-
keyword_dict = json.load(file)
313-
flattened_keywords = flatten_keywords(keyword_dict)
316+
if os.path.exists(keyword_file):
317+
with open(keyword_file, "r") as file:
318+
keyword_dict = json.load(file)
319+
flattened_keywords = flatten_keywords(keyword_dict)
320+
else:
321+
print(f"Keywords file not found at { os.path.abspath(keyword_file)}.")
322+
sys.exit(1)
314323

315324
# int fm
316325
fm = Feature(taxonomy.name, None)

0 commit comments

Comments
 (0)