Files manager
FileCopier
Controller class for the Backup Juggler application.
Attributes:
| Name | Type | Description |
|---|---|---|
_paths |
Paths
|
The |
_viewer |
ProgressViewer
|
The |
Methods
- _copy_to: Copy files from source to destination.
- _copy_file: Copy a single file from source to destination.
Source code in backup_juggler/files_manager.py
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
__init__(paths, viewer)
Initialize a FileCopier instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths |
Paths
|
The |
required |
viewer |
ProgressViewer
|
The |
required |
Source code in backup_juggler/files_manager.py
27 28 29 30 31 32 33 34 35 36 37 | |
backup(source, destination)
Perform a file backup operation from the source path to the destination path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source |
Path
|
The source directory or file path. |
required |
destination |
Path
|
The destination directory. |
required |
Initiates a file backup operation by creating instances of Paths, ProgressViewer,
and FileCopier classes. The file copying is performed by calling the do_copy method
of the FileCopier instance.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a source file or directory does not exist. |
Source code in backup_juggler/files_manager.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
calculates_size(sources)
Calculate the total size of the given source directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources |
list[Path]
|
A list of source directories or file paths. |
required |
This function calculates the total size of the given source directories or files.
It iterates through the provided list of Path objects and sums up the sizes
of all the sources. The result is then displayed in a human-readable format.
The size is calculated in bytes and converted to the appropriate unit (B, KB, MB, GB, TB) to improve readability. The function automatically selects the most appropriate unit based on the size.
Examples:
>>> sources = [Path('path/to/source1'), Path('path/to/source2')]
>>> calculates_size(sources)
Source code in backup_juggler/files_manager.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
parallel_backups(sources, destinations)
Perform multiple file backup operations in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources |
list[Path]
|
A list of source directories or file paths. |
required |
destinations |
list[Path]
|
A list of destination directories. |
required |
Examples:
>>> sources = [Path('path/to/source1'), Path('path/to/source2')]
>>> destinations = [Path('path/to/destination1'), Path('path/to/destination2')]
>>> parallel_backups(sources, destinations)
Initiates multiple file backup operations in parallel using ThreadPoolExecutor from
the concurrent.futures module. The backup function is submitted as a task to the executor
for each combination of source and destination paths. The function waits for all tasks to complete
before returning.
Source code in backup_juggler/files_manager.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |