Issues (23)

backuppc_clone/helper/HostDelete.py (1 issue)

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