|
29 | 29 |
|
30 | 30 | from pathspec import GitIgnoreSpec |
31 | 31 |
|
32 | | -from .scanoss_settings import ScanossSettings |
33 | 32 | from .scanossbase import ScanossBase |
34 | 33 |
|
35 | 34 | # Files to skip |
@@ -240,48 +239,35 @@ class FileFilters(ScanossBase): |
240 | 239 | Handles both inclusion and exclusion rules based on file paths, extensions, and sizes. |
241 | 240 | """ |
242 | 241 |
|
243 | | - def __init__( |
244 | | - self, |
245 | | - debug: bool = False, |
246 | | - trace: bool = False, |
247 | | - quiet: bool = False, |
248 | | - scanoss_settings: 'ScanossSettings | None' = None, |
249 | | - all_extensions: bool = False, |
250 | | - all_folders: bool = False, |
251 | | - hidden_files_folders: bool = False, |
252 | | - operation_type: str = 'scanning', |
253 | | - skip_size: int = 0, |
254 | | - skip_extensions=None, |
255 | | - skip_folders=None, |
256 | | - ): |
| 242 | + def __init__(self, debug: bool = False, trace: bool = False, quiet: bool = False, **kwargs): |
257 | 243 | """ |
258 | 244 | Initialize scan filters based on default settings. Optionally append custom settings. |
259 | 245 |
|
260 | 246 | Args: |
261 | 247 | debug (bool): Enable debug output |
262 | 248 | trace (bool): Enable trace output |
263 | 249 | quiet (bool): Suppress output |
264 | | - scanoss_settings (ScanossSettings): Custom settings to override defaults |
265 | | - all_extensions (bool): Include all file extensions |
266 | | - all_folders (bool): Include all folders |
267 | | - hidden_files_folders (bool): Include hidden files and folders |
268 | | - operation_type: operation type. can be either 'scanning' or 'fingerprinting' |
| 250 | + **kwargs: Additional arguments including: |
| 251 | + scanoss_settings (ScanossSettings): Custom settings to override defaults |
| 252 | + all_extensions (bool): Include all file extensions |
| 253 | + all_folders (bool): Include all folders |
| 254 | + hidden_files_folders (bool): Include hidden files and folders |
| 255 | + operation_type (str): Operation type ('scanning' or 'fingerprinting') |
| 256 | + skip_size (int): Size to skip |
| 257 | + skip_extensions (list): Extensions to skip |
| 258 | + skip_folders (list): Folders to skip |
269 | 259 | """ |
270 | 260 | super().__init__(debug, trace, quiet) |
271 | 261 |
|
272 | | - if skip_folders is None: |
273 | | - skip_folders = [] |
274 | | - if skip_extensions is None: |
275 | | - skip_extensions = [] |
276 | | - self.hidden_files_folders = hidden_files_folders |
277 | | - self.scanoss_settings = scanoss_settings |
278 | | - self.all_extensions = all_extensions |
279 | | - self.all_folders = all_folders |
280 | | - self.skip_folders = skip_folders |
281 | | - self.skip_size = skip_size |
282 | | - self.skip_extensions = skip_extensions |
283 | | - self.file_folder_pat_spec = self._get_file_folder_pattern_spec(operation_type) |
284 | | - self.size_pat_rules = self._get_size_limit_pattern_rules(operation_type) |
| 262 | + self.hidden_files_folders = kwargs.get('hidden_files_folders', False) |
| 263 | + self.scanoss_settings = kwargs.get('scanoss_settings') |
| 264 | + self.all_extensions = kwargs.get('all_extensions', False) |
| 265 | + self.all_folders = kwargs.get('all_folders', False) |
| 266 | + self.skip_folders = kwargs.get('skip_folders', []) |
| 267 | + self.skip_size = kwargs.get('skip_size', 0) |
| 268 | + self.skip_extensions = kwargs.get('skip_extensions', []) |
| 269 | + self.file_folder_pat_spec = self._get_file_folder_pattern_spec(kwargs.get('operation_type', 'scanning')) |
| 270 | + self.size_pat_rules = self._get_size_limit_pattern_rules(kwargs.get('operation_type', 'scanning')) |
285 | 271 |
|
286 | 272 | def get_filtered_files_from_folder(self, root: str) -> List[str]: |
287 | 273 | """ |
@@ -311,16 +297,16 @@ def get_filtered_files_from_folder(self, root: str) -> List[str]: |
311 | 297 | return all_files |
312 | 298 | # Walk the tree looking for files to process. While taking into account files/folders to skip |
313 | 299 | for dirpath, dirnames, filenames in os.walk(root_path): |
314 | | - dirpath = Path(dirpath) |
315 | | - rel_path = dirpath.relative_to(root_path) |
316 | | - if dirpath.is_symlink(): # TODO should we skip symlink folders? |
317 | | - self.print_msg(f'WARNING: Found symbolic link folder: {dirpath}') |
| 300 | + dir_path = Path(dirpath) |
| 301 | + rel_path = dir_path.relative_to(root_path) |
| 302 | + if dir_path.is_symlink(): # TODO should we skip symlink folders? |
| 303 | + self.print_msg(f'WARNING: Found symbolic link folder: {dir_path}') |
318 | 304 |
|
319 | 305 | if self.should_skip_dir(str(rel_path)): # Current directory should be skipped |
320 | 306 | dirnames.clear() |
321 | 307 | continue |
322 | 308 | for filename in filenames: |
323 | | - file_path = dirpath / filename |
| 309 | + file_path = dir_path / filename |
324 | 310 | all_files.append(str(file_path)) |
325 | 311 | # End os.walk loop |
326 | 312 | # Now filter the files and return the reduced list |
@@ -452,7 +438,7 @@ def _get_operation_size_limits(self, file_path: str = None) -> tuple: |
452 | 438 | # End rules loop |
453 | 439 | return min_size, max_size |
454 | 440 |
|
455 | | - def should_skip_dir(self, dir_rel_path: str) -> bool: |
| 441 | + def should_skip_dir(self, dir_rel_path: str) -> bool: # noqa: PLR0911 |
456 | 442 | """ |
457 | 443 | Check if a directory should be skipped based on operation type and default rules. |
458 | 444 |
|
@@ -490,7 +476,7 @@ def should_skip_dir(self, dir_rel_path: str) -> bool: |
490 | 476 | return True |
491 | 477 | return False |
492 | 478 |
|
493 | | - def _should_skip_file(self, file_rel_path: str) -> bool: |
| 479 | + def _should_skip_file(self, file_rel_path: str) -> bool: # noqa: PLR0911 |
494 | 480 | """ |
495 | 481 | Check if a file should be skipped based on operation type and default rules. |
496 | 482 |
|
|
0 commit comments