Merge lp:~dooferlad/linaro-license-protection/api-robot-readable into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by James Tunnicliffe
Status: Merged
Approved by: Milo Casagrande
Approved revision: 180
Merged at revision: 180
Proposed branch: lp:~dooferlad/linaro-license-protection/api-robot-readable
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 101 lines (+19/-15)
2 files modified
license_protected_downloads/tests/test_views.py (+2/-5)
license_protected_downloads/views.py (+17/-10)
To merge this branch: bzr merge lp:~dooferlad/linaro-license-protection/api-robot-readable
Reviewer Review Type Date Requested Status
Milo Casagrande (community) Approve
Review via email: mp+156510@code.launchpad.net

Description of the change

Made the API more robot readable.

To post a comment you must log in.
Revision history for this message
Milo Casagrande (milo) wrote :

It looks good to go for me.
+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 2013-03-18 18:22:29 +0000
+++ license_protected_downloads/tests/test_views.py 2013-04-02 10:03:04 +0000
@@ -1,6 +1,5 @@
1__author__ = 'dooferlad'1__author__ = 'dooferlad'
22
3from datetime import datetime
4from django.conf import settings3from django.conf import settings
5from django.test import Client, TestCase4from django.test import Client, TestCase
6import hashlib5import hashlib
@@ -285,8 +284,7 @@
285 else:284 else:
286 self.assertTrue(os.path.isfile(file_path))285 self.assertTrue(os.path.isfile(file_path))
287286
288 mtime = datetime.fromtimestamp(287 mtime = os.path.getmtime(file_path)
289 os.path.getmtime(file_path)).strftime('%d-%b-%Y %H:%M')
290288
291 self.assertEqual(mtime, file_info["mtime"])289 self.assertEqual(mtime, file_info["mtime"])
292290
@@ -309,8 +307,7 @@
309 else:307 else:
310 self.assertTrue(os.path.isfile(file_path))308 self.assertTrue(os.path.isfile(file_path))
311309
312 mtime = datetime.fromtimestamp(310 mtime = os.path.getmtime(file_path)
313 os.path.getmtime(file_path)).strftime('%d-%b-%Y %H:%M')
314311
315 self.assertEqual(mtime, file_info["mtime"])312 self.assertEqual(mtime, file_info["mtime"])
316313
317314
=== modified file 'license_protected_downloads/views.py'
--- license_protected_downloads/views.py 2013-03-18 18:22:29 +0000
+++ license_protected_downloads/views.py 2013-04-02 10:03:04 +0000
@@ -63,7 +63,7 @@
63 return "%3.1f%s" % (num, 'T')63 return "%3.1f%s" % (num, 'T')
6464
6565
66def dir_list(url, path):66def dir_list(url, path, human_readable=True):
67 files = os.listdir(path)67 files = os.listdir(path)
68 files.sort()68 files.sort()
69 listing = []69 listing = []
@@ -76,21 +76,16 @@
76 file_name = os.path.join(path, file_name)76 file_name = os.path.join(path, file_name)
7777
78 if os.path.exists(file_name):78 if os.path.exists(file_name):
79 mtime = datetime.fromtimestamp(79 mtime = os.path.getmtime(file_name)
80 os.path.getmtime(file_name)).strftime('%d-%b-%Y %H:%M')
81 else:80 else:
82 # If the file we are looking at doesn't exist (broken symlink for81 # If the file we are looking at doesn't exist (broken symlink for
83 # example), it doesn't have a mtime.82 # example), it doesn't have a mtime.
84 mtime = 083 mtime = 0
8584
86 target_type = "other"
87 if os.path.isdir(file_name):85 if os.path.isdir(file_name):
88 target_type = "folder"86 target_type = "folder"
89 else:87 else:
90 type_tuple = guess_type(name)88 target_type = guess_type(name)[0]
91 if type_tuple and type_tuple[0]:
92 if type_tuple[0].split('/')[0] == "text":
93 target_type = "text"
9489
95 if os.path.exists(file_name):90 if os.path.exists(file_name):
96 size = os.path.getsize(file_name)91 size = os.path.getsize(file_name)
@@ -106,11 +101,23 @@
106 # there isn't one.101 # there isn't one.
107 url = re.sub(r'/$', '', url)102 url = re.sub(r'/$', '', url)
108103
104 if human_readable:
105 if mtime:
106 mtime = datetime.fromtimestamp(mtime).strftime(
107 '%d-%b-%Y %H:%M')
108 if target_type:
109 if target_type.split('/')[0] == "text":
110 target_type = "text"
111 else:
112 target_type = "other"
113
114 size = _sizeof_fmt(size)
115
109 pathname = os.path.join(path, name)116 pathname = os.path.join(path, name)
110 license_digest_list = is_protected(pathname)117 license_digest_list = is_protected(pathname)
111 license_list = License.objects.all_with_hashes(license_digest_list)118 license_list = License.objects.all_with_hashes(license_digest_list)
112 listing.append({'name': name,119 listing.append({'name': name,
113 'size': _sizeof_fmt(size),120 'size': size,
114 'type': target_type,121 'type': target_type,
115 'mtime': mtime,122 'mtime': mtime,
116 'license_digest_list': license_digest_list,123 'license_digest_list': license_digest_list,
@@ -520,7 +527,7 @@
520 path = os.path.dirname(path)527 path = os.path.dirname(path)
521 url = os.path.dirname(url)528 url = os.path.dirname(url)
522529
523 listing = dir_list(url, path)530 listing = dir_list(url, path, human_readable=False)
524531
525 clean_listing = []532 clean_listing = []
526 for entry in listing:533 for entry in listing:

Subscribers

People subscribed via source and target branches