moved size_convert function and about dialog outside MVC scope
[findit] / src / mvc / misc / functions.py
1 #!/usr/bin/env python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4 # pylint: disable-msg=C0301
5
6
7 def size_convert(size):
8     """Return string with package size in b or Kb or Mb or Gb or Tb."""
9
10     for i, unit in enumerate(['%d b', '%.1f Kb', '%.2f Mb', '%.3f Gb', '%.4f Tb']):
11         if size < 1024**(i+1):
12             return unit % (size/1024.**i)
13     return '>1024 Tb'