Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Color Palette in CLI #95

Closed
wants to merge 2 commits into from
Closed
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
50 changes: 24 additions & 26 deletions twinTrim/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ def cli(directory, all, min_size, max_size, file_type, exclude, label_color, bar
file_filter.addFileExclude(file_name)

if all:
add-dry-run
if dry_run:
click.echo(click.style("Dry run mode enabled: Skipping actual deletion.", fg='yellow'))
handleAllFlag(directory, file_filter, label_color, bar_color, dry_run=dry_run) # Modify handleAllFlag to support dry_run
=======
logging.info("Deleting all duplicate files whithout asking.")
handleAllFlag(directory, file_filter, label_color, bar_color)
>>>>> main
return
add-dry-run
if dry_run:
click.echo(click.style("Dry run mode enabled: Skipping actual deletion.", fg='yellow'))
handleAllFlag(directory, file_filter, label_color, bar_color, dry_run=dry_run) # Modify handleAllFlag to support dry_run
logging.info("Deleting all duplicate files whithout asking.")
handleAllFlag(directory, file_filter, label_color, bar_color)

return

start_time = time.time()
logging.info(f"Searching for duplicates in directory: {directory}")
Expand All @@ -59,11 +58,11 @@ def cli(directory, all, min_size, max_size, file_type, exclude, label_color, bar


if not duplicates:
click.echo(click.style("No duplicate files found.", fg='green'))
click.secho("No duplicate files found.", bold=True, bg='green')
logging.info("No duplicate files found.")
return

click.echo(click.style(f"Found {len(duplicates)} sets of duplicate files:", fg='yellow'))
click.echo(click.style(f"Found {len(duplicates)} sets of duplicate files:", bold=True, bg='green'))
logging.info(f"Found {len(duplicates)} set of duplicate files")

duplicates_dict = defaultdict(list)
Expand All @@ -72,25 +71,27 @@ def cli(directory, all, min_size, max_size, file_type, exclude, label_color, bar

# Process each set of duplicates
for original, duplicates_list in duplicates_dict.items():
click.echo(click.style(f"Original file: \"{original}\"", fg='cyan'))
click.echo(click.style(f"Number of duplicate files found: {len(duplicates_list)}", fg='cyan'))
click.echo(click.style("Original file", fg='cyan', bold=True) + ": " + click.style(f"\"{original}\""))
click.echo(click.style("Number of duplicate files found", fg='cyan', bold=True) + ": " + click.style(f"{len(duplicates_list)}"))
logging.info(f"Original file: \"{original}\" with {len(duplicates_list)} duplicates")

click.echo(click.style("They are:", fg='cyan'))
click.echo(click.style("They are", fg='yellow', bold=True) + ":")
file_options = [f"{idx + 1}) {duplicate}" for idx, duplicate in enumerate(duplicates_list)]

# Prompt user to select which files to delete
selected_indices = select_multiple(
file_options, # List of files to choose from
ticked_indices=[], # Default indices that are selected
maximal_count=len(file_options)
maximal_count=len(file_options),
tick_style='green',
cursor_style='green'
)

# Convert the indices back to the original file paths
files_to_delete = [duplicates_list[int(option.split(")")[0]) - 1] for option in selected_indices]

for file_path in files_to_delete:
add-dry-run
add-dry-run
if dry_run:
click.echo(click.style(f"[Dry Run] Would delete: {file_path}", fg='yellow'))
else:
Expand All @@ -103,20 +104,17 @@ def cli(directory, all, min_size, max_size, file_type, exclude, label_color, bar

click.echo(click.style(f"Time taken: {time_taken:.2f} seconds.", fg='green'))

=======
try:
handle_and_remove(file_path)
logging.info(f"Deleted duplicate file: {file_path}")
except Exception as e:
logging.error(f"Error deleting file {file_path}: {str(e)}")
click.echo(click.style(f"Error deleting file: {file_path}. Check the log for details.", fg='red'))

try:
handle_and_remove(file_path)
logging.info(f"Deleted duplicate file: {file_path}")
except Exception as e:
logging.error(f"Error deleting file {file_path}: {str(e)}")
click.echo(click.style(f"Error deleting file: {file_path}. Check the log for details.", fg='red'))

end_time = time.time()
time_taken = end_time - start_time
click.echo(click.style(f"Time taken: {time_taken:.2f} seconds.", fg='green'))
logging.info(f"Total time taken: {time_taken:.2f} seconds.")

if __name__ == "__main__":
cli()
main
cli()
4 changes: 2 additions & 2 deletions twinTrim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def handle_and_remove(filepath):
try:
os.remove(filepath)
click.echo(click.style(f"Deleted: {filepath}", fg='green'))
click.echo(click.style(f"Deleted: {filepath}"))
except FileNotFoundError:
click.echo(click.style(f"File not found (skipped): {filepath}", fg='red'))
except PermissionError:
Expand Down Expand Up @@ -38,4 +38,4 @@ def parse_size(size_str):
return int(size_str) # This can also be modified to handle sizes without suffix
except ValueError:
# If conversion fails, return 0 for invalid formats
return 0
return 0
Loading