Merge lp:~gesha/linaro-license-protection/human-readable-size into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Approved by: Stevan Radaković
Approved revision: 119
Merged at revision: 121
Proposed branch: lp:~gesha/linaro-license-protection/human-readable-size
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 58 lines (+23/-1)
2 files modified
license_protected_downloads/tests/test_views.py (+9/-0)
license_protected_downloads/views.py (+14/-1)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/human-readable-size
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Review via email: mp+121330@code.launchpad.net

Description of the change

As part of updating template to "apache generated" style this branch adds displaying filesize in human readable format.
It's more appearance improvement then necessity :)

To post a comment you must log in.
Revision history for this message
Stevan Radaković (stevanr) wrote :

Looks good.
Approve +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'license_protected_downloads/tests/test_views.py'
--- license_protected_downloads/tests/test_views.py 2012-08-24 14:17:02 +0000
+++ license_protected_downloads/tests/test_views.py 2012-08-26 11:42:19 +0000
@@ -10,6 +10,7 @@
10from license_protected_downloads import bzr_version10from license_protected_downloads import bzr_version
11from license_protected_downloads.buildinfo import BuildInfo11from license_protected_downloads.buildinfo import BuildInfo
12from license_protected_downloads.views import _insert_license_into_db12from license_protected_downloads.views import _insert_license_into_db
13from license_protected_downloads.views import _sizeof_fmt
13from license_protected_downloads.config import INTERNAL_HOSTS14from license_protected_downloads.config import INTERNAL_HOSTS
1415
15THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))16THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
@@ -479,5 +480,13 @@
479 # this test should not cause an exception. Anything else is a pass.480 # this test should not cause an exception. Anything else is a pass.
480 self.assertEqual(response.status_code, 200)481 self.assertEqual(response.status_code, 200)
481482
483 def test_sizeof_fmt(self):
484 self.assertEqual(_sizeof_fmt(1), '1')
485 self.assertEqual(_sizeof_fmt(1234), '1.2K')
486 self.assertEqual(_sizeof_fmt(1234567), '1.2M')
487 self.assertEqual(_sizeof_fmt(1234567899), '1.1G')
488 self.assertEqual(_sizeof_fmt(1234567899999), '1.1T')
489
490
482if __name__ == '__main__':491if __name__ == '__main__':
483 unittest.main()492 unittest.main()
484493
=== modified file 'license_protected_downloads/views.py'
--- license_protected_downloads/views.py 2012-08-24 14:13:10 +0000
+++ license_protected_downloads/views.py 2012-08-26 11:42:19 +0000
@@ -41,6 +41,19 @@
41 return False41 return False
4242
4343
44def _sizeof_fmt(num):
45 ''' Returns in human readable format for num.
46 '''
47 if num < 1024 and num > -1024:
48 return str(num)
49 num /= 1024.0
50 for x in ['K', 'M', 'G']:
51 if num < 1024.0 and num > -1024.0:
52 return "%3.1f%s" % (num, x)
53 num /= 1024.0
54 return "%3.1f%s" % (num, 'T')
55
56
44def dir_list(url, path):57def dir_list(url, path):
45 files = os.listdir(path)58 files = os.listdir(path)
46 files.sort()59 files.sort()
@@ -87,7 +100,7 @@
87 license_digest_list = is_protected(pathname)100 license_digest_list = is_protected(pathname)
88 license_list = License.objects.all_with_hashes(license_digest_list)101 license_list = License.objects.all_with_hashes(license_digest_list)
89 listing.append({'name': name,102 listing.append({'name': name,
90 'size': size,103 'size': _sizeof_fmt(size),
91 'type': type,104 'type': type,
92 'mtime': mtime,105 'mtime': mtime,
93 'license_digest_list': license_digest_list,106 'license_digest_list': license_digest_list,

Subscribers

People subscribed via source and target branches