Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

""" 

Helper functions. 

""" 

 

from tgutils.application import * # pylint: disable=wildcard-import,unused-wildcard-import 

from typing import List 

from uuid import UUID 

 

import hashlib 

import mmap 

 

 

def file_uuid(path: str) -> UUID: 

""" 

Compute a checksum of a disk file. 

""" 

md5 = hashlib.md5() 

 

with open(path, 'rb') as file: 

mapped = mmap.mmap(file.fileno(), 0, prot=mmap.PROT_READ) 

md5.update(mapped) # type: ignore 

mapped.close() 

 

return UUID(bytes=md5.digest()) 

 

 

def combine_uuids(uuids: List[UUID]) -> UUID: 

""" 

Use ``md5sum`` to combine multiple UUIDs into a single UUID. 

""" 

md5 = hashlib.md5() 

for uuid in uuids: 

md5.update(uuid.bytes) 

return UUID(bytes=md5.digest()) 

 

 

def sum_profiles_loop(expected: int) -> Loop: 

""" 

Create a logged loop for summing profiles. 

""" 

return Loop(start='Sum profiles...', 

progress='Summed %sK profiles (%.2f%%)...', 

completed='Summed %s profiles', 

log_every=100_000, 

log_with=1_000, 

expected=expected)