Skip to content

Paths manager

Paths

Model class for the Backup Juggler application.

Attributes:

Name Type Description
_source Path

The source directory or file path.

_destination Path

The destination directory.

_total_size int

The total size of the files to be copied.

Methods
  • source: Get the source path.
  • destination: Get the destination directory.
  • total_size: Get the total size of the files to be copied.
Notes
  • The total size calculation includes subdirectories and files within the source directory.
  • The total size is calculated only once during the initialization of the Paths instance.
Source code in backup_juggler/paths_manager.py
 4
 5
 6
 7
 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Paths:
    """
    Model class for the Backup Juggler application.

    Attributes:
        _source: The source directory or file path.
        _destination: The destination directory.
        _total_size: The total size of the files to be copied.

    Methods:
        - source: Get the source path.
        - destination: Get the destination directory.
        - total_size: Get the total size of the files to be copied.

    Notes:
        - The total size calculation includes subdirectories and files within the source directory.
        - The total size is calculated only once during the initialization of the `Paths` instance.
    """

    def __init__(self, source: Path, destination: Path = None) -> None:
        """
        Initialize a `Paths` instance.

        Args:
            source: The source directory or file path.
            destination: The destination directory. Defaults to `None`.
        """

        self._source: Path = source
        self._destination: Path = destination
        if self.source.is_file():
            self._total_size: int = self.source.stat().st_size
        else:
            self._total_size: int = sum(
                src_file.stat().st_size
                for src_file in self.source.rglob('*.*')
            )

    @property
    def source(self) -> Path:
        """
        Get the source path.

        Returns:
            _source: The source path.
        """

        return self._source

    @property
    def destination(self) -> Path:
        """
        Get the destination directory.

        Returns:
            _destination: The destination directory.
        """

        return self._destination

    @property
    def total_size(self) -> int:
        """
        Get the total size of the files to be copied.

        Returns:
            _total_size: The total size in bytes.
        """

        return self._total_size

destination: Path property

Get the destination directory.

Returns:

Name Type Description
_destination Path

The destination directory.

source: Path property

Get the source path.

Returns:

Name Type Description
_source Path

The source path.

total_size: int property

Get the total size of the files to be copied.

Returns:

Name Type Description
_total_size int

The total size in bytes.

__init__(source, destination=None)

Initialize a Paths instance.

Parameters:

Name Type Description Default
source Path

The source directory or file path.

required
destination Path

The destination directory. Defaults to None.

None
Source code in backup_juggler/paths_manager.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def __init__(self, source: Path, destination: Path = None) -> None:
    """
    Initialize a `Paths` instance.

    Args:
        source: The source directory or file path.
        destination: The destination directory. Defaults to `None`.
    """

    self._source: Path = source
    self._destination: Path = destination
    if self.source.is_file():
        self._total_size: int = self.source.stat().st_size
    else:
        self._total_size: int = sum(
            src_file.stat().st_size
            for src_file in self.source.rglob('*.*')
        )