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

AuxiliaryFileScanner.scan()   B

Complexity

Conditions 6

Size

Total Lines 25
Code Lines 17

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
eloc 17
nop 2
dl 25
loc 25
rs 8.6166
c 0
b 0
f 0
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