Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Upcoming changes...
### Fixed
- Fixed terminal cursor disappearing after aborting scan with Ctrl+C

## [1.40.1] - 2025-10-29
### Changed
Expand Down
75 changes: 37 additions & 38 deletions src/scanoss/filecount.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import os
import pathlib
import sys
from contextlib import nullcontext

from progress.spinner import Spinner

Expand Down Expand Up @@ -105,48 +106,46 @@ def count_files(self, scan_dir: str) -> bool:
"""
success = True
if not scan_dir:
raise Exception(f'ERROR: Please specify a folder to scan')
raise Exception('ERROR: Please specify a folder to scan')
if not os.path.exists(scan_dir) or not os.path.isdir(scan_dir):
raise Exception(f'ERROR: Specified folder does not exist or is not a folder: {scan_dir}')

self.print_msg(f'Searching {scan_dir} for files to count...')
spinner = None
if not self.quiet and self.isatty:
spinner = Spinner('Searching ')
file_types = {}
file_count = 0
file_size = 0
for root, dirs, files in os.walk(scan_dir):
self.print_trace(f'U Root: {root}, Dirs: {dirs}, Files {files}')
dirs[:] = self.__filter_dirs(dirs) # Strip out unwanted directories
filtered_files = self.__filter_files(files) # Strip out unwanted files
self.print_trace(f'F Root: {root}, Dirs: {dirs}, Files {filtered_files}')
for file in filtered_files: # Cycle through each filtered file
path = os.path.join(root, file)
f_size = 0
try:
f_size = os.stat(path).st_size
except Exception as e:
self.print_trace(f'Ignoring missing symlink file: {file} ({e})') # broken symlink
if f_size > 0: # Ignore broken links and empty files
file_count = file_count + 1
file_size = file_size + f_size
f_suffix = pathlib.Path(file).suffix
if not f_suffix or f_suffix == '':
f_suffix = 'no_suffix'
self.print_trace(f'Counting {path} ({f_suffix} - {f_size})..')
fc = file_types.get(f_suffix)
if not fc:
fc = [1, f_size]
else:
fc[0] = fc[0] + 1
fc[1] = fc[1] + f_size
file_types[f_suffix] = fc
if spinner:
spinner.next()
# End for loop
if spinner:
spinner.finish()
spinner_ctx = Spinner('Searching ') if (not self.quiet and self.isatty) else nullcontext()

with spinner_ctx as spinner:
file_types = {}
file_count = 0
file_size = 0
for root, dirs, files in os.walk(scan_dir):
self.print_trace(f'U Root: {root}, Dirs: {dirs}, Files {files}')
dirs[:] = self.__filter_dirs(dirs) # Strip out unwanted directories
filtered_files = self.__filter_files(files) # Strip out unwanted files
self.print_trace(f'F Root: {root}, Dirs: {dirs}, Files {filtered_files}')
for file in filtered_files: # Cycle through each filtered file
path = os.path.join(root, file)
f_size = 0
try:
f_size = os.stat(path).st_size
except Exception as e:
self.print_trace(f'Ignoring missing symlink file: {file} ({e})') # broken symlink
if f_size > 0: # Ignore broken links and empty files
file_count = file_count + 1
file_size = file_size + f_size
f_suffix = pathlib.Path(file).suffix
if not f_suffix or f_suffix == '':
f_suffix = 'no_suffix'
self.print_trace(f'Counting {path} ({f_suffix} - {f_size})..')
fc = file_types.get(f_suffix)
if not fc:
fc = [1, f_size]
else:
fc[0] = fc[0] + 1
fc[1] = fc[1] + f_size
file_types[f_suffix] = fc
if spinner:
spinner.next()
# End for loop
self.print_stderr(f'Found {file_count:,.0f} files with a total size of {file_size / (1 << 20):,.2f} MB.')
if file_types:
csv_dict = []
Expand Down
Loading
Loading