Passed
Push — master ( ba6342...71f198 )
by P.R.
07:12
created

backuppc_clone.helper.HostDelete   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 81.82 %

Importance

Changes 0
Metric Value
eloc 22
dl 54
loc 66
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A HostDelete.delete_host() 10 10 1
A HostDelete.__init__() 14 14 1
A HostDelete.__delete_metadata() 7 7 1
A HostDelete.__delete_files() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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