Total Complexity | 7 |
Total Lines | 54 |
Duplicated Lines | 81.48 % |
Changes | 0 |
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: |
|
|
|||
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 | |||
56 |