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@file 

3@brief Various functions to display information about files 

4""" 

5 

6import datetime 

7 

8 

9def format_file_size(size): 

10 """ 

11 Formats the file size as string. 

12 

13 @param size numeric value 

14 @return string (something + unit) 

15 """ 

16 if size >= 2 ** 30: 

17 size = size / 2 ** 30 

18 return "%1.2f Gb" % size 

19 elif size >= 2 ** 20: 

20 size = size / 2 ** 20 

21 return "%1.2f Mb" % size 

22 elif size >= 2 ** 10: 

23 size = size / 2 ** 10 

24 return "%1.2f Kb" % size 

25 else: 

26 return "%d" % size 

27 

28 

29def format_file_mtime(timestamp): 

30 """ 

31 Returns a :epkg:`datetime` for a file. 

32 

33 @param timestamp modified date for example 

34 @return datetime 

35 """ 

36 return datetime.datetime.fromtimestamp(timestamp)