-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.py
87 lines (73 loc) · 2.87 KB
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from dataclasses import dataclass
import os
import logging
logger = logging.getLogger(__name__)
logger.setLevel(os.getenv('MERGELOGGING', 'INFO'))
def sizeof_fmt(num, suffix="B"):
for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"):
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
return f"{num:.1f}Yi{suffix}"
@dataclass
class ProcessStats():
processed_files_size: int
deleted_files_size: int
copied_files_size: int
duplicated_files_size: int
deleted_files_count: int
ignored_files_count: int
copied_files_count: int
duplicated_files_count: int
def __init__(self):
self.processed_files_size = 0
self.ignored_files_size = 0
self.deleted_files_size = 0
self.copied_files_size = 0
self.duplicated_files_size = 0
self.processed_files_count = 0
self.ignored_files_count = 0
self.deleted_files_count = 0
self.copied_files_count = 0
self.duplicated_files_count = 0
def deleted(self, size: int):
self.deleted_files_count += 1
self.deleted_files_size += size
def processed(self, size: int):
self.processed_files_count += 1
self.processed_files_size += size
def ignored(self, size: int):
self.ignored_files_count += 1
self.ignored_files_size += size
def deleted(self, size: int):
self.deleted_files_count += 1
self.deleted_files_size += size
def copied(self, size: int):
self.copied_files_count += 1
self.copied_files_size += size
def duplicated(self, size: int):
self.duplicated_files_count += 1
self.duplicated_files_size += size
def print_stats(self):
total_msg = f"""
A total of {self.processed_files_count} files were processed from the source.
The total size of the source directory was: {sizeof_fmt(self.processed_files_size)}"""
delete_msg = f"""
A total of {self.deleted_files_count} files were deleted from the source.
Size of deleted files: {sizeof_fmt(self.deleted_files_size)}"""
ignored_msg = f"""
A total of {self.ignored_files_count} files were ignored as duplicated.
Size of ignored files: {sizeof_fmt(self.ignored_files_size)}"""
copy_msg = f"""
A total of {self.copied_files_count} files were copied.
Size of copied files: {sizeof_fmt(self.copied_files_size)}"""
duplicated_msg = f"""
A total of {self.duplicated_files_count} files existed on the target and were copied with an alternative name.
Size of duplicated files: {sizeof_fmt(self.duplicated_files_size)}"""
print('***********************************************')
print(total_msg)
print(copy_msg)
print(delete_msg)
print(ignored_msg)
print(duplicated_msg)
print('***********************************************')