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

backuppc_clone.helper.AuxiliaryFileScanner   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 81.48 %

Importance

Changes 0
Metric Value
eloc 24
dl 44
loc 54
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AuxiliaryFileScanner.__init__() 9 9 1
B AuxiliaryFileScanner.scan() 25 25 6

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
from typing import List, Dict
6
7
from backuppc_clone.style.BackupPcCloneStyle import BackupPcCloneStyle
8
9
10 View Code Duplication
class AuxiliaryFileScanner:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    """
12
    Scans for auxiliary files.
13
    """
14
15
    # ------------------------------------------------------------------------------------------------------------------
16
    def __init__(self, io: BackupPcCloneStyle):
17
        """
18
        Object constructor.
19
20
        :param BackupPcCloneStyle io: The output style.
21
        """
22
23
        self.__io: BackupPcCloneStyle = io
24
        """
25
        The output style.
26
        """
27
28
    # ------------------------------------------------------------------------------------------------------------------
29
    def scan(self, pc_dir: str) -> List[Dict]:
30
        """
31
        Scans recursively a directory for auxiliary of hosts.
32
33
        :param str pc_dir: The PC dir, i.e. the directory where the host backups are stored.
34
        """
35
        self.__io.writeln(' Scanning <fso>{}</fso>'.format(pc_dir))
36
37
        hosts = []
38
        files = []
39
        for entry in os.scandir(pc_dir):
40
            if entry.is_dir():
41
                hosts.append(entry.name)
42
43
        for host in hosts:
44
            host_dir = os.path.join(pc_dir, host)
45
            for entry in os.scandir(host_dir):
46
                if entry.is_file():
47
                    stats = os.stat(os.path.join(host_dir, entry.name))
48
                    files.append({'host':  host,
49
                                  'name':  entry.name,
50
                                  'size':  stats.st_size,
51
                                  'mtime': stats.st_mtime})
52
53
        return files
54
55
# ------------------------------------------------------------------------------------------------------------------
56