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