Skip to content

delete

Bases: FileOperation, FileRemoverMixin

An operation to delete files from source directory that match specific patterns.

This class identifies files in the source directory and removes them permanently. It uses the FileRemoverMixin to ensure that each deletion is handled safely and logged correctly.

Source code in file_operations/delete.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class DeleteOperation(FileOperation, FileRemoverMixin):
    """
    An operation to delete files from source directory that match specific patterns.

    This class identifies files in the source directory and removes them
    permanently. It uses the FileRemoverMixin to ensure that each deletion
    is handled safely and logged correctly.
    """
    @staticmethod
    def add_arguments(settings: AppSettings, parser: argparse.ArgumentParser) -> None:
        """
        Defines command-line arguments for the delete operation.

        This specific operation does not require unique arguments beyond
        the standard source and pattern parameters.

        Args:
            settings (AppSettings): The global settings object for default values.
            parser (argparse.ArgumentParser): The CLI parser to which arguments are added.
        """
        pass


    def do_task(self):
        """
        Executes the deletion task for all collected files.

        This method calls the '_remove_all' helper from FileRemoverMixin
        to process the list of files found in the source directory.
        """
        self.remove_all(self.files_for_task)

add_arguments(settings, parser) staticmethod

Defines command-line arguments for the delete operation.

This specific operation does not require unique arguments beyond the standard source and pattern parameters.

Parameters:

Name Type Description Default
settings AppSettings

The global settings object for default values.

required
parser ArgumentParser

The CLI parser to which arguments are added.

required
Source code in file_operations/delete.py
16
17
18
19
20
21
22
23
24
25
26
27
28
@staticmethod
def add_arguments(settings: AppSettings, parser: argparse.ArgumentParser) -> None:
    """
    Defines command-line arguments for the delete operation.

    This specific operation does not require unique arguments beyond
    the standard source and pattern parameters.

    Args:
        settings (AppSettings): The global settings object for default values.
        parser (argparse.ArgumentParser): The CLI parser to which arguments are added.
    """
    pass

do_task()

Executes the deletion task for all collected files.

This method calls the '_remove_all' helper from FileRemoverMixin to process the list of files found in the source directory.

Source code in file_operations/delete.py
31
32
33
34
35
36
37
38
def do_task(self):
    """
    Executes the deletion task for all collected files.

    This method calls the '_remove_all' helper from FileRemoverMixin
    to process the list of files found in the source directory.
    """
    self.remove_all(self.files_for_task)