Skip to content

Commit

Permalink
fix: prevent find_venvs from traversing subdirectories within .venv
Browse files Browse the repository at this point in the history
… folders
  • Loading branch information
Tlaloc-Es committed Jan 2, 2025
1 parent 1bb4eed commit 3389a2e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pykill/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from textual.app import App, ComposeResult
from textual.widgets import DataTable, Header
import time
import shutil


def get_folder_size(folder_path):
Expand All @@ -28,19 +29,24 @@ def find_venvs(base_directory="."):
venvs = []

for root, dirs, files in os.walk(base_directory):
for dir_name in dirs:
dirs_copy = dirs[:]
for dir_name in dirs_copy:
if dir_name.startswith(".venv"):
venv_path = os.path.join(root, dir_name)
last_modified = int(
round((time.time() - os.path.getmtime(venv_path)) / (24 * 3600))
)
size = format_size(get_folder_size(venv_path))
venvs.append((venv_path, last_modified, size))
dirs.remove(dir_name)

return venvs


class TableApp(App):

deleted_cells = []

def compose(self) -> ComposeResult:
yield Header()
yield DataTable()
Expand All @@ -64,10 +70,13 @@ def on_key(self, event):
table = self.query_one(DataTable)
cursor_cell = table.cursor_coordinate
if cursor_cell:
if cursor_cell in self.deleted_cells:
return event
row_data = table.get_row_at(cursor_cell.row)

path = row_data[0]
shutil.rmtree(path)
table.update_cell_at(cursor_cell, f"DELETED {row_data[0]}")

self.deleted_cells.append(cursor_cell)
self.bell()
return event

Expand Down

0 comments on commit 3389a2e

Please sign in to comment.