1
|
|
|
""" |
2
|
|
|
BackupPC Clone |
3
|
|
|
""" |
4
|
|
|
import os |
5
|
|
|
import shutil |
6
|
|
|
|
7
|
|
|
from backuppc_clone.Config import Config |
8
|
|
|
from backuppc_clone.DataLayer import DataLayer |
9
|
|
|
from backuppc_clone.style.BackupPcCloneStyle import BackupPcCloneStyle |
10
|
|
|
|
11
|
|
|
|
12
|
|
View Code Duplication |
class HostDelete: |
|
|
|
|
13
|
|
|
""" |
14
|
|
|
Deletes a host entirely frm the clone. |
15
|
|
|
""" |
16
|
|
|
|
17
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
18
|
|
|
def __init__(self, io: BackupPcCloneStyle): |
19
|
|
|
""" |
20
|
|
|
Object constructor. |
21
|
|
|
|
22
|
|
|
:param BackupPcCloneStyle io: The output style. |
23
|
|
|
""" |
24
|
|
|
|
25
|
|
|
self.__io: BackupPcCloneStyle = io |
26
|
|
|
""" |
27
|
|
|
The output style. |
28
|
|
|
""" |
29
|
|
|
|
30
|
|
|
self.__host: str = '' |
31
|
|
|
""" |
32
|
|
|
The host of the backup. |
33
|
|
|
""" |
34
|
|
|
|
35
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
36
|
|
|
def __delete_files(self) -> None: |
37
|
|
|
""" |
38
|
|
|
Removes the host from the clone file system. |
39
|
|
|
""" |
40
|
|
|
self.__io.writeln(' Removing files') |
41
|
|
|
|
42
|
|
|
host_dir_clone = Config.instance.host_dir_clone(self.__host) |
43
|
|
|
if os.path.isdir(host_dir_clone): |
44
|
|
|
shutil.rmtree(host_dir_clone) |
45
|
|
|
|
46
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
47
|
|
|
def __delete_metadata(self) -> None: |
48
|
|
|
""" |
49
|
|
|
Removes the metadata from the database. |
50
|
|
|
""" |
51
|
|
|
self.__io.writeln(' Removing metadata') |
52
|
|
|
|
53
|
|
|
DataLayer.instance.host_delete(self.__host) |
54
|
|
|
|
55
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
56
|
|
|
def delete_host(self, host: str) -> None: |
57
|
|
|
""" |
58
|
|
|
Deletes a backup of a host. |
59
|
|
|
|
60
|
|
|
:param str host: The name of the host. |
61
|
|
|
""" |
62
|
|
|
self.__host = host |
63
|
|
|
|
64
|
|
|
self.__delete_metadata() |
65
|
|
|
self.__delete_files() |
66
|
|
|
|
67
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
68
|
|
|
|