Skip to content

Commit 51b8d71

Browse files
committed
Added options to include skipped files and folders
1 parent 69fed74 commit 51b8d71

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- Upcoming changes...
1111

12+
## [0.7.2] - 2021-12-10
13+
### Added
14+
- Added option to process all file extensions while scanning (--all-extensions)
15+
- Added option to process all folders while scanning (--all-folders)
16+
- Added option to process all hidden files/folders while scanning (--all-hidden)
17+
1218
## [0.7.1] - 2021-11-12
1319
### Added
1420
- Added option to skip WFP file generation while scanning (--no-wfp-output)
@@ -68,3 +74,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6874
[0.6.11]: https://github.com/scanoss/scanoss.py/compare/v0.6.6...v0.6.11
6975
[0.7.0]: https://github.com/scanoss/scanoss.py/compare/v0.6.11...v0.7.0
7076
[0.7.1]: https://github.com/scanoss/scanoss.py/compare/v0.7.0...v0.7.1
77+
[0.7.2]: https://github.com/scanoss/scanoss.py/compare/v0.7.1...v0.7.2

src/scanoss/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
THE SOFTWARE.
2323
"""
2424

25-
__version__ = '0.7.1'
25+
__version__ = '0.7.2'

src/scanoss/cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def setup_args() -> None:
8282
help='Timeout (in seconds) for API communication (optional - default 120)'
8383
)
8484
p_scan.add_argument('--no-wfp-output', action='store_true', help='Skip WFP file generation')
85+
p_scan.add_argument('--all-extensions', action='store_true', help='Scan all file extensions')
86+
p_scan.add_argument('--all-folders', action='store_true', help='Scan all folders')
87+
p_scan.add_argument('--all-hidden', action='store_true', help='Scan all hidden files/folders')
8588

8689
# Sub-command: fingerprint
8790
p_wfp = subparsers.add_parser('fingerprint', aliases=['fp', 'wfp'],
@@ -199,6 +202,12 @@ def scan(parser, args):
199202
output_format = args.format if args.format else 'plain'
200203
flags = args.flags if args.flags else None
201204
if args.debug and not args.quiet:
205+
if args.all_extensions:
206+
print_stderr("Scanning all file extensions/types...")
207+
if args.all_folders:
208+
print_stderr("Scanning all folders...")
209+
if args.all_hidden:
210+
print_stderr("Scanning all hidden files/folders...")
202211
if args.skip_snippets:
203212
print_stderr("Skipping snippets...")
204213
if args.post_size != 64:
@@ -216,7 +225,8 @@ def scan(parser, args):
216225
scanner = Scanner(debug=args.debug, trace=args.trace, quiet=args.quiet, api_key=args.key, url=args.apiurl,
217226
sbom_path=sbom_path, scan_type=scan_type, scan_output=scan_output, output_format=output_format,
218227
flags=flags, nb_threads=args.threads, skip_snippets=args.skip_snippets, post_size=args.post_size,
219-
timeout=args.timeout, no_wfp_file=args.no_wfp_output
228+
timeout=args.timeout, no_wfp_file=args.no_wfp_output, all_extensions=args.all_extensions,
229+
all_folders=args.all_folders, hidden_files_folders=args.all_hidden
220230
)
221231
if args.wfp:
222232
if args.threads > 1:

src/scanoss/scanner.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class Scanner:
7878
def __init__(self, wfp: str = None, scan_output: str = None, output_format: str = 'plain',
7979
debug: bool = False, trace: bool = False, quiet: bool = False, api_key: str = None, url: str = None,
8080
sbom_path: str = None, scan_type: str = None, flags: str = None, nb_threads: int = 5,
81-
skip_snippets: bool = False, post_size: int = 64, timeout: int = 120, no_wfp_file: bool = False
81+
skip_snippets: bool = False, post_size: int = 64, timeout: int = 120, no_wfp_file: bool = False,
82+
all_extensions: bool = False, all_folders: bool = False, hidden_files_folders: bool = False
8283
):
8384
"""
8485
Initialise scanning class, including Winnowing, ScanossApi and ThreadedScanning
@@ -91,7 +92,10 @@ def __init__(self, wfp: str = None, scan_output: str = None, output_format: str
9192
self.output_format = output_format
9293
self.no_wfp_file = no_wfp_file
9394
self.isatty = sys.stderr.isatty()
94-
self.winnowing = Winnowing(debug=debug, quiet=quiet, skip_snippets=skip_snippets)
95+
self.all_extensions = all_extensions
96+
self.all_folders = all_folders
97+
self.hidden_files_folders = hidden_files_folders
98+
self.winnowing = Winnowing(debug=debug, quiet=quiet, skip_snippets=skip_snippets, all_extensions=all_extensions)
9599
self.scanoss_api = ScanossApi(debug=debug, trace=trace, quiet=quiet, api_key=api_key, url=url,
96100
sbom_path=sbom_path, scan_type=scan_type, flags=flags, timeout=timeout
97101
)
@@ -106,8 +110,7 @@ def __init__(self, wfp: str = None, scan_output: str = None, output_format: str
106110
if skip_snippets:
107111
self.max_post_size = 8 * 1024 # 8k Max post size if we're skipping snippets
108112

109-
@staticmethod
110-
def __filter_files(files) -> list:
113+
def __filter_files(self, files: list) -> list:
111114
"""
112115
Filter which files should be considered for processing
113116
:param files: list of files to filter
@@ -116,23 +119,22 @@ def __filter_files(files) -> list:
116119
file_list = []
117120
for f in files:
118121
ignore = False
119-
if f.startswith("."): # Ignore all . files
122+
if f.startswith(".") and not self.hidden_files_folders: # Ignore all . files unless requested
120123
ignore = True
121-
if not ignore:
124+
if not ignore and not self.all_extensions: # Skip this check if we're allowing all extensions
122125
f_lower = f.lower()
123-
if f_lower in FILTERED_FILES: # Check for exact files to ignore
126+
if f_lower in FILTERED_FILES: # Check for exact files to ignore
124127
ignore = True
125128
if not ignore:
126-
for ending in FILTERED_EXT: # Check for file endings to ignore
129+
for ending in FILTERED_EXT: # Check for file endings to ignore
127130
if f_lower.endswith(ending):
128131
ignore = True
129132
break
130133
if not ignore:
131134
file_list.append(f)
132135
return file_list
133136

134-
@staticmethod
135-
def __filter_dirs(dirs: list) -> list:
137+
def __filter_dirs(self, dirs: list) -> list:
136138
"""
137139
Filter which folders should be considered for processing
138140
:param dirs: list of directories to filter
@@ -141,9 +143,9 @@ def __filter_dirs(dirs: list) -> list:
141143
dir_list = []
142144
for d in dirs:
143145
ignore = False
144-
if d.startswith("."): # Ignore all . folders
146+
if d.startswith(".") and not self.hidden_files_folders: # Ignore all . folders unless requested
145147
ignore = True
146-
if not ignore:
148+
if not ignore and not self.all_folders: # Skip this check if we're allowing all folders
147149
d_lower = d.lower()
148150
if d_lower in FILTERED_DIRS: # Ignore specific folders
149151
ignore = True
@@ -278,8 +280,8 @@ def scan_folder(self, scan_dir: str) -> bool:
278280
scan_started = False
279281
for root, dirs, files in os.walk(scan_dir):
280282
self.print_trace(f'U Root: {root}, Dirs: {dirs}, Files {files}')
281-
dirs[:] = Scanner.__filter_dirs(dirs) # Strip out unwanted directories
282-
filtered_files = Scanner.__filter_files(files) # Strip out unwanted files
283+
dirs[:] = self.__filter_dirs(dirs) # Strip out unwanted directories
284+
filtered_files = self.__filter_files(files) # Strip out unwanted files
283285
self.print_debug(f'F Root: {root}, Dirs: {dirs}, Files {filtered_files}')
284286
for file in filtered_files: # Cycle through each filtered file
285287
path = os.path.join(root, file)
@@ -624,8 +626,8 @@ def wfp_folder(self, scan_dir: str, wfp_file: str = None):
624626
scan_dir_len = len(scan_dir) if scan_dir.endswith(os.path.sep) else len(scan_dir)+1
625627
self.print_msg(f'Searching {scan_dir} for files to fingerprint...')
626628
for root, dirs, files in os.walk(scan_dir):
627-
dirs[:] = Scanner.__filter_dirs(dirs) # Strip out unwanted directories
628-
filtered_files = Scanner.__filter_files(files) # Strip out unwanted files
629+
dirs[:] = self.__filter_dirs(dirs) # Strip out unwanted directories
630+
filtered_files = self.__filter_files(files) # Strip out unwanted files
629631
self.print_trace(f'Root: {root}, Dirs: {dirs}, Files {filtered_files}')
630632
for file in filtered_files:
631633
path = os.path.join(root, file)

src/scanoss/winnowing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Winnowing:
102102
"""
103103

104104
def __init__(self, size_limit: bool = True, debug: bool = False, trace: bool = False, quiet: bool = False,
105-
skip_snippets: bool = False, post_size: int = 64
105+
skip_snippets: bool = False, post_size: int = 64, all_extensions: bool = False
106106
):
107107
"""
108108
Instantiate Winnowing class
@@ -117,6 +117,7 @@ def __init__(self, size_limit: bool = True, debug: bool = False, trace: bool = F
117117
self.quiet = quiet
118118
self.skip_snippets = skip_snippets
119119
self.max_post_size = post_size * 1024 if post_size > 0 else MAX_POST_SIZE
120+
self.all_extensions = all_extensions
120121

121122
@staticmethod
122123
def __normalize(byte):
@@ -151,6 +152,8 @@ def __skip_snippets(self, file: str, src: str) -> bool:
151152
True: if file should be skipped
152153
False: otherwise
153154
"""
155+
if self.all_extensions:
156+
return False
154157
if file:
155158
lower_file = file.lower()
156159
for ending in SKIP_SNIPPET_EXT:

0 commit comments

Comments
 (0)