Skip to content

Commit 3b03e37

Browse files
committed
v1.0.6 - further changes
1 parent 1245275 commit 3b03e37

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

detect_advisor/global_values.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,5 +716,6 @@
716716
'emit-db': 3,
717717
}
718718

719-
exclude_dirs = [
720-
]
719+
exclude_dirs = []
720+
721+
message_list = []

detect_advisor/messages.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@
8686
'impact': 'Local license text may need to be scanned',
8787
'action': 'Add options --detect.blackduck.signature.scanner.license.search=true and optionally --detect.blackduck.signature.scanner.upload.source.mode=true',
8888
'cli': 'lic',
89-
'cli_search': 'detect.blackduck.signature.scanner.upload.source.mode',
90-
'cli_text': '--detect.blackduck.signature.scanner.upload.source.mode=true (CAUTION - will upload local source files)',
89+
'cli_search': 'detect.blackduck.signature.scanner.license.search',
90+
'cli_text': '--detect.blackduck.signature.scanner.license.search=true\n'
91+
'--detect.blackduck.signature.scanner.upload.source.mode=true (CAUTION - will upload local source files)',
92+
9193
},
9294

9395
'FILES3': {
@@ -100,6 +102,16 @@
100102
'cli_text': '--detect.blackduck.signature.scanner.snippet.matching=SNIPPET_MATCHING (To search for copied OSS source files and functions within source files)',
101103
},
102104

105+
'FILES4': {
106+
'level': 'imp',
107+
'desc': 'Folders included in scan which should probably be excluded',
108+
'impact': 'Scan size may be larger than required and additional components identified',
109+
'action': 'Rerun with --full option to see list of folders to exclude, then use the --detect.excluded.directories option to exclude folders',
110+
'cli': 'scan',
111+
'cli_search': 'detect.excluded.directories',
112+
'cli_text': '--detect.excluded.directories=XXX with --detect.excluded.directories.search.depth=X (search for and exclude folders from scan - see list of folders for exclusion using --full option)',
113+
},
114+
103115
'SCAN1': {
104116
'level': 'crit',
105117
'desc': 'Overall scan size {:>,d} MB) is too large (default max scan size 5GB)',
@@ -139,7 +151,7 @@
139151
'level': 'imp',
140152
'desc': 'Large amount of data ({:>,d} MB) in {} binary files found',
141153
'impact': 'Binary files not analysed by standard scan, will increase scan size and impact Capacity license usage',
142-
'action': 'Remove files or ignore folders (using .bdignore files), also consider using Binary scan',
154+
'action': 'See list of binary files using --full option, then remove files or ignore folders (using .bdignore files), also consider using Binary scan',
143155
'cli': 'scan',
144156
'cli_search': 'detect.binary.scan.file.name.patterns',
145157
'cli_text': '--detect.binary.scan.file.name.patterns=exe,bin,dll (for example) and --detect.binary.scan.search.depth=X (folder depth to search for binaries)'
@@ -166,14 +178,14 @@
166178
'level': 'crit',
167179
'desc': 'Required package manager programs ({}) missing for dependency scan in invocation folder',
168180
'impact': 'Scan will fail',
169-
'action': 'Install required package manager programs',
181+
'action': 'See list of affected PMs using --full option, then install required package manager programs',
170182
},
171183

172184
'PACKAGES4': {
173185
'level': 'imp',
174186
'desc': 'Required package manager programs ({}) missing for dependency scan in sub-folders',
175187
'impact': 'The scan will fail if the scan depth is modified from the default level 0',
176-
'action': 'Install required package manager programs',
188+
'action': 'See list of affected PMs using --full option, , then install required package manager programs',
177189
},
178190

179191
'PACKAGES5': {
@@ -186,8 +198,8 @@
186198
'PACKAGES6': {
187199
'level': 'crit',
188200
'desc': 'Missing lockfiles/PMs for package manager files in invocation folder',
189-
'impact': 'Dependency scan will fail unless lockfiles created, PMs installed or --detect.accuracy.required=NONE specified',
190-
'action': 'Either install required package manager programs, create lockfiles or specify --detect.accuracy.required=NONE (reduced accuracy scan)',
201+
'impact': 'Dependency scan will fail',
202+
'action': 'See list of affected PMs using --full option, then either install required package manager programs, create lockfiles or specify --detect.accuracy.required=NONE (reduced accuracy scan)',
191203
'cli': 'reqd',
192204
'cli_search': 'detect.accuracy.required',
193205
'cli_text': '--detect.accuracy.required=NONE (OR specify --detect.XXXX.path=<LOCATION> where XXX is package manager OR install package managers OR create lockfiles)',
@@ -196,8 +208,8 @@
196208
'PACKAGES7': {
197209
'level': 'imp',
198210
'desc': 'Missing lockfiles/PMs will cause scan to fail for package manager files in sub-folders',
199-
'impact': 'Dependency scan will fail if scan depth > 0 unless lockfiles created, PMs installed or --detect.accuracy.required=NONE specified',
200-
'action': 'Either install required package manager programs, create lockfiles or specify --detect.accuracy.required=NONE (reduced accuracy scan)',
211+
'impact': 'Dependency scan will fail if scan depth > 0',
212+
'action': 'See list of affected PMs using --full option, then either install required package manager programs, create lockfiles or specify --detect.accuracy.required=NONE (reduced accuracy scan)',
201213
'cli': 'reqd',
202214
'cli_search': 'detect.accuracy.required',
203215
'cli_text': '--detect.accuracy.required=NONE (OR specify --detect.XXXX.path=<LOCATION> where XXX is package manager OR install package managers)',
@@ -233,7 +245,7 @@
233245
# 'cli_search': 'detect.accuracy.required',
234246
# 'cli_text': '--detect.accuracy.required=NONE (OR install JS packages)',
235247
# },
236-
#
248+
237249
'PACKAGES12': {
238250
'level': 'imp',
239251
'desc': 'Lockfile(s) required for dependency scan missing in invocation folder',
@@ -260,7 +272,10 @@
260272

261273

262274
def message(id, val1='', val2=''):
275+
if id in global_values.message_list:
276+
return
263277
if id in messages_dict:
278+
global_values.message_list.append(id)
264279
if val2 != '':
265280
mtext = f"- {levtexts[messages_dict[id]['level']]}: " + messages_dict[id]['desc'].format(val1, val2) + '\n'
266281
elif val1 != '':

detect_advisor/output.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ def output_cli(critical_only, reportfile):
193193
if global_values.recs_msgs_dict['crit']:
194194
output += "Note that scan will probably fail - see CRITICAL recommendations above\n\n"
195195

196-
output += " DETECT COMMAND:\n"
197-
output += re.sub(r"^", " ", global_values.cli_msgs_dict['detect'], flags=re.MULTILINE)
198-
output += "\n MINIMUM REQUIRED OPTIONS:\n"
199-
output += re.sub(r"^", " ", global_values.cli_msgs_dict['reqd'], flags=re.MULTILINE)
196+
output += "DETECT COMMAND:\n"
197+
output += global_values.cli_msgs_dict['detect']
198+
output += "\nMINIMUM REQUIRED OPTIONS:\n"
199+
output += global_values.cli_msgs_dict['reqd']
200200

201201
# if len(bdignore_list) > 0:
202202
# if report:
@@ -208,8 +208,11 @@ def output_cli(critical_only, reportfile):
208208

209209
if not critical_only:
210210
output += '\n'
211+
if global_values.cli_msgs_dict['proj'] != '':
212+
output += "\nPROJECT OPTIONS:\n" + global_values.cli_msgs_dict['proj'] + "\n"
213+
211214
if global_values.cli_msgs_dict['scan'] != '':
212-
output += "\nOPTIONS TO IMPROVE SCAN COVERAGE:\n" + global_values.cli_msgs_dict['scan'] + "\n"
215+
output += "\nOPTIONS TO IMPROVE SCAN COVERAGE/ACCURACY:\n" + global_values.cli_msgs_dict['scan'] + "\n"
213216

214217
if global_values.cli_msgs_dict['size'] != '':
215218
output += "\nOPTIONS TO REDUCE SIGNATURE SCAN SIZE:\n" + global_values.cli_msgs_dict['size'] + "\n"
@@ -220,9 +223,6 @@ def output_cli(critical_only, reportfile):
220223
if global_values.cli_msgs_dict['lic'] != '':
221224
output += "\nOPTIONS TO IMPROVE LICENSE COMPLIANCE ANALYSIS:\n" + global_values.cli_msgs_dict['lic'] + "\n"
222225

223-
if global_values.cli_msgs_dict['proj'] != '':
224-
output += "\nPROJECT OPTIONS:\n" + global_values.cli_msgs_dict['proj'] + "\n"
225-
226226
if global_values.cli_msgs_dict['rep'] != '':
227227
output += "\nREPORTING OPTIONS:\n" + global_values.cli_msgs_dict['rep'] + "\n"
228228

@@ -241,11 +241,11 @@ def output_config(projdir):
241241
"# Uncomment and update required options\n#\n#\n" + \
242242
"# DETECT COMMAND TO RUN:\n#\n" + global_values.cli_msgs_dict['detect'] + "\n" + \
243243
"# MINIMUM REQUIRED OPTIONS:\n#\n" + global_values.cli_msgs_dict['reqd'] + "\n" + \
244-
"# OPTIONS TO IMPROVE SCAN COVERAGE:\n#\n" + global_values.cli_msgs_dict['scan'] + "\n" + \
244+
"# PROJECT OPTIONS:\n#\n" + global_values.cli_msgs_dict['proj'] + "\n" + \
245+
"# OPTIONS TO IMPROVE SCAN COVERAGE/ACCURACY:\n#\n" + global_values.cli_msgs_dict['scan'] + "\n" + \
245246
"# OPTIONS TO REDUCE SIGNATURE SCAN SIZE:\n#\n" + global_values.cli_msgs_dict['size'] + "\n" + \
246247
"# OPTIONS TO CONFIGURE DEPENDENCY SCAN:\n#\n" + global_values.cli_msgs_dict['dep'] + "\n" + \
247248
"# OPTIONS TO IMPROVE LICENSE COMPLIANCE ANALYSIS:\n#\n" + global_values.cli_msgs_dict['lic'] + "\n" + \
248-
"# PROJECT OPTIONS:\n#\n" + global_values.cli_msgs_dict['proj'] + "\n" + \
249249
"# REPORTING OPTIONS:\n#\n" + global_values.cli_msgs_dict['rep'] + "\n"
250250

251251
config = re.sub("=", ": ", config)

detect_advisor/process.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,11 @@ def det_excluded(dir):
221221
break
222222
return excluded
223223

224-
225224
def process_dir(path, dirdepth):
225+
from . import messages
226226
dir_size = 0
227227
dir_entries = 0
228228
filenames_string = ""
229-
# global global_values.messages
230229

231230
if sig_excluded(path):
232231
return 0
@@ -245,6 +244,7 @@ def process_dir(path, dirdepth):
245244
dir_size += this_size
246245
if entry in global_values.exclude_dirs:
247246
global_values.file_list['exclude_dirs'].append(entry.path)
247+
messages.message('FILES4')
248248
else:
249249
ftype = checkfile(entry.name, entry.path, entry.stat(follow_symlinks=False).st_size, 0,
250250
dirdepth, False)
@@ -264,13 +264,15 @@ def process_dir(path, dirdepth):
264264
# check depth to exclude
265265
if global_values.exclude_files[entry.name] == 1:
266266
global_values.file_list['exclude_dirs'].append(os.path.dirname(entry.path))
267+
messages.message('FILES4')
267268
else:
268269
p = Path(entry.path)
269270
count = global_values.exclude_files[entry.name]
270271
while count > 0:
271272
p = p.parent
272273
count -= 1
273274
global_values.file_list['exclude_dirs'].append(str(p))
275+
messages.message('FILES4')
274276

275277
except OSError:
276278
global_values.messages += "ERROR: Unable to open folder {}\n".format(path)
@@ -601,7 +603,7 @@ def pm_getter(item):
601603
global_values.cli_msgs_dict['crit'] += (
602604
f"For {pm}:\n" + global_values.pm_dict[pm]['cli_reqd'] + '\n')
603605

604-
print(" Done")
606+
print(" Done\n")
605607

606608
return
607609

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "detect_advisor"
7-
version = "1.0.5"
7+
version = "1.0.6"
88
authors = [
99
{ name="Matthew Brady", email="[email protected]" },
1010
]

0 commit comments

Comments
 (0)