@@ -16,9 +16,9 @@ def __init__(self, src_entry):
1616 except KeyError :
1717 return
1818
19- def search_component (self , compname , compver ):
20- logging .debug ("" )
21- logging .debug (f"search_component() Checking Comp '{ compname } /{ compver } ' - { self .path } :" )
19+ def search_component (self , compname_arr , compver ):
20+ # logging.debug("")
21+ # logging.debug(f"search_component() Checking Comp '{compname}/{compver}' - {self.path}:")
2222 # If component_version_reqd:
2323 # - folder matches compname and compver
2424 # - folder1 matches compname and folder2 matches compver
@@ -29,76 +29,103 @@ def search_component(self, compname, compver):
2929 # Bool2 - version found
3030 # Match_value - search result against both
3131
32- compstring = f"{ compname } { compver } "
33- element_in_compname = 0
34- compver_in_element = 0
3532
36- # test of path search
37- newpath = self . path . replace ( os . sep , " " )
38- newpath = re . sub ( r"([a-zA-Z-]*)[0-9] " , " \1 " , newpath )
39- comp_in_path = fuzz . token_set_ratio ( compstring , newpath )
40- logging . debug ( f"search_component(): TEST comp_in_path is { comp_in_path } : path=' { self . path } " )
33+ best_match_name = 0
34+ best_match_ver = 0
35+ # match_path = ''
36+ for cname in compname_arr :
37+ # compstring = f"{cname} {compver}"
4138
42- found_compname_only = False
43- for element in self .elements :
44- pos = re .search (r"\.dll|\.obj|\.o|\.a|\.lib|\.iso|\.qcow2|\.vmdk|\.vdi|\.ova|\.nbi|\.vib|\.exe|\.img|"
45- "\.bin|\.apk|\.aac|\.ipa|\.msi|\.zip|\.gz|\.tar|\.xz|\.lz|\.bz2|\.7z|\.rar|"
46- "\.cpio|\.Z|\.lz4|\.lha|\.arj|\.jar|\.ear|\.war|\.rpm|\.deb|\.dmg|\.pki" , element )
47- if pos is not None :
48- element = element [:pos .start ()]
49- # How much of the element string is from the compname and version?
50- # - for example acl-1.3.0.jar
51- # - Value of 100 indicates either compname or version exists in element
52- element_in_compstring = fuzz .token_set_ratio (element , compstring )
53- element_in_compname = fuzz .token_set_ratio (element , compname )
54- compver_in_element = fuzz .token_set_ratio (compver , element )
39+ # test of path search
40+ newpath = self .path .replace (os .sep , " " )
41+ # comp_in_path = fuzz.token_set_ratio(compstring, newpath)
42+ compname_in_path = fuzz .token_set_ratio (cname , newpath )
43+ compver_in_path = fuzz .token_set_ratio (compver , newpath )
44+ if compname_in_path + compver_in_path > 90 :
45+ if compname_in_path + compver_in_path > best_match_name + best_match_ver :
46+ best_match_name = compname_in_path
47+ best_match_ver = compver_in_path
48+ # match_path = self.path
49+ logging .debug (f"search_component(): TEST '{ cname } /{ compver } ' - { compname_in_path ,compver_in_path } : path='{ self .path } " )
5550
56- if element_in_compstring > 80 :
57- if compver_in_element > 50 :
58- # element has both compname and version
59- logging .debug (f"search_component() - MATCHED component name & version ({ compstring } ) in '{ element } '" )
60- return True , True , element_in_compname + compver_in_element
61- elif element_in_compname > 50 and len (element ) > 2 :
62- found_compname_only = True
63- logging .debug (f"search_component() - FOUND component name ONLY ({ compname } ) in '{ element } '" )
64- elif found_compname_only :
65- if compver_in_element > 50 :
66- logging .debug (f"search_component() - MATCHED component version ({ compver } ) in '{ element } '" )
67- return True , True , element_in_compname + compver_in_element
68- else :
69- test = 1
51+ name_bool = False
52+ ver_bool = False
53+ if best_match_name > 45 :
54+ name_bool = True
55+ if best_match_ver > 45 :
56+ ver_bool = True
7057
71- if found_compname_only :
72- logging .debug ("search_component() - MATCHED Compname only" )
73- return True , False , element_in_compname + compver_in_element
74-
75- logging .debug (f"search_component() - NOT MATCHED" )
76- return False , False , 0
58+ return name_bool , ver_bool , best_match_name + best_match_ver
59+ # compstring = f"{compname} {compver}"
60+ # element_in_compname = 0
61+ # compver_in_element = 0
62+ # found_compname_only = False
63+ # for element in self.elements:
64+ # pos = re.search(r"\.dll|\.obj|\.o|\.a|\.lib|\.iso|\.qcow2|\.vmdk|\.vdi|\.ova|\.nbi|\.vib|\.exe|\.img|"
65+ # "\.bin|\.apk|\.aac|\.ipa|\.msi|\.zip|\.gz|\.tar|\.xz|\.lz|\.bz2|\.7z|\.rar|"
66+ # "\.cpio|\.Z|\.lz4|\.lha|\.arj|\.jar|\.ear|\.war|\.rpm|\.deb|\.dmg|\.pki", element)
67+ # if pos is not None:
68+ # element = element[:pos.start()]
69+ # # How much of the element string is from the compname and version?
70+ # # - for example acl-1.3.0.jar
71+ # # - Value of 100 indicates either compname or version exists in element
72+ # element_in_compstring = fuzz.token_set_ratio(element, compstring)
73+ # element_in_compname = fuzz.token_set_ratio(element, compname)
74+ # compver_in_element = fuzz.token_set_ratio(compver, element)
75+ #
76+ # if element_in_compstring > 80:
77+ # if compver_in_element > 50:
78+ # # element has both compname and version
79+ # logging.debug(f"search_component() - MATCHED component name & version ({compstring}) in '{element}'")
80+ # return True, True, element_in_compname + compver_in_element
81+ # elif element_in_compname > 50 and len(element) > 2:
82+ # found_compname_only = True
83+ # logging.debug(f"search_component() - FOUND component name ONLY ({compname}) in '{element}'")
84+ # elif found_compname_only:
85+ # if compver_in_element > 50:
86+ # logging.debug(f"search_component() - MATCHED component version ({compver}) in '{element}'")
87+ # return True, True, element_in_compname + compver_in_element
88+ # else:
89+ # test = 1
90+ #
91+ # if found_compname_only:
92+ # logging.debug("search_component() - MATCHED Compname only")
93+ # return True, False, element_in_compname + compver_in_element
94+ #
95+ # logging.debug(f"search_component() - NOT MATCHED")
7796
7897
7998 def filter_folders (self ):
8099 # Return True if path should be ignored + reason
81100 if not global_values .no_ignore_synopsys :
82- syn_folders = ['.synopsys' , 'synopsys-detect' , '.coverity' , 'synopsys-detect.jar' ,
83- 'scan.cli.impl-standalone.jar' , 'seeker-agent.tgz' , 'seeker-agent.zip' ,
84- 'Black_Duck_Scan_Installation' ]
85- for e in self .elements :
86- if e in syn_folders :
87- return True , f"Found '{ e } ' in Signature match path '{ self .path } '"
101+ # syn_folders = ['.synopsys', 'synopsys-detect', '.coverity', 'synopsys-detect.jar',
102+ # 'scan.cli.impl-standalone.jar', 'seeker-agent.tgz', 'seeker-agent.zip',
103+ # 'Black_Duck_Scan_Installation']
104+
105+ syn_folders_re = (f"{ os .sep } (\.synopsys|synopsys-detect|\.coverity|synopsys-detect.*\.jar|scan\.cli\.impl-standalone\.jar|"
106+ f"seeker-agent.*|Black_Duck_Scan_Installation){ os .sep } " )
107+ res = re .search (syn_folders_re , self .path )
108+ if res :
109+ return True , f"Found { res .group ()} folder in Signature match path '{ self .path } '"
88110
89111 if not global_values .no_ignore_defaults :
90- def_folders = ['.cache' , '.m2' , '.local' , '.cache' ,'.config' , '.docker' , '.npm' , '.npmrc' , '.pyenv' ,
91- '.Trash' , '.git' , 'node_modules' ]
92- for e in self .elements :
93- if e in def_folders :
94- return True , f"Found '{ e } ' in Signature match path '{ self .path } '"
112+ # def_folders = ['.cache', '.m2', '.local', '.cache','.config', '.docker', '.npm', '.npmrc', '.pyenv',
113+ # '.Trash', '.git', 'node_modules']
114+ def_folders_re = (f"{ os .sep } (\.cache|\.m2|\.local|\.config|\.docker|\.npm|\.npmrc|"
115+ f"\.pyenv|\.Trash|\.git|node_modules){ os .sep } " )
116+ res = re .search (def_folders_re , os .sep + self .path + os .sep )
117+ if res :
118+ return True , f"Found { res .group ()} folder in Signature match path '{ self .path } '"
95119
96120 if not global_values .no_ignore_test :
97- test_folders = r"^ test$|^ tests$|^ testsuite$ "
98- for e in self .elements :
99- if re . search ( test_folders , e , flags = re . IGNORECASE ) is not None :
100- return True , f"Found ' { e } ' in Signature match path '{ self .path } '"
121+ test_folders = f" { os . sep } ( test| tests| testsuite) { os . sep } "
122+ res = re . search ( test_folders , os . sep + self .path + os . sep , flags = re . IGNORECASE )
123+ if res :
124+ return True , f"Found { res . group () } in Signature match path '{ self .path } '"
101125 # if e in test_folders:
102126 # return True, f"Found '{e}' in Signature match path '{self.path}'"
103127
104128 return False , ''
129+
130+ def get_sigpath (self ):
131+ return (f"- { self .path } " )
0 commit comments