Skip to content

Commit

Permalink
added delete files
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkasirer committed Nov 19, 2024
1 parent a5b9e2d commit 7414568
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added new task `DeleteFiles` to `installlib.tasks`.

### Changed

### Removed
Expand Down
17 changes: 17 additions & 0 deletions src/installlib/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,20 @@ def execute(self):
except Exception as ex:
return False, f"Failed to copy files: {ex}"
return True, None


class DeleteFiles:
def __init__(self, filepaths, name=None) -> None:
self.name = name or DeleteFiles.__name__
self.filepaths = filepaths

def execute(self):
try:
files = self.filepaths() if callable(self.filepaths) else self.filepaths
if not isinstance(files, list):
files = [files]
for file in files:
os.remove(file)
except Exception as ex:
return False, f"Failed to delete files: {ex}"
return True, None

0 comments on commit 7414568

Please sign in to comment.