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
1=== modified file 'license_protected_downloads/tests/test_views.py'
2--- license_protected_downloads/tests/test_views.py 2013-03-18 18:22:29 +0000
3+++ license_protected_downloads/tests/test_views.py 2013-04-02 10:03:04 +0000
4@@ -1,6 +1,5 @@
5 __author__ = 'dooferlad'
6
7-from datetime import datetime
8 from django.conf import settings
9 from django.test import Client, TestCase
10 import hashlib
11@@ -285,8 +284,7 @@
12 else:
13 self.assertTrue(os.path.isfile(file_path))
14
15- mtime = datetime.fromtimestamp(
16- os.path.getmtime(file_path)).strftime('%d-%b-%Y %H:%M')
17+ mtime = os.path.getmtime(file_path)
18
19 self.assertEqual(mtime, file_info["mtime"])
20
21@@ -309,8 +307,7 @@
22 else:
23 self.assertTrue(os.path.isfile(file_path))
24
25- mtime = datetime.fromtimestamp(
26- os.path.getmtime(file_path)).strftime('%d-%b-%Y %H:%M')
27+ mtime = os.path.getmtime(file_path)
28
29 self.assertEqual(mtime, file_info["mtime"])
30
31
32=== modified file 'license_protected_downloads/views.py'
33--- license_protected_downloads/views.py 2013-03-18 18:22:29 +0000
34+++ license_protected_downloads/views.py 2013-04-02 10:03:04 +0000
35@@ -63,7 +63,7 @@
36 return "%3.1f%s" % (num, 'T')
37
38
39-def dir_list(url, path):
40+def dir_list(url, path, human_readable=True):
41 files = os.listdir(path)
42 files.sort()
43 listing = []
44@@ -76,21 +76,16 @@
45 file_name = os.path.join(path, file_name)
46
47 if os.path.exists(file_name):
48- mtime = datetime.fromtimestamp(
49- os.path.getmtime(file_name)).strftime('%d-%b-%Y %H:%M')
50+ mtime = os.path.getmtime(file_name)
51 else:
52 # If the file we are looking at doesn't exist (broken symlink for
53 # example), it doesn't have a mtime.
54 mtime = 0
55
56- target_type = "other"
57 if os.path.isdir(file_name):
58 target_type = "folder"
59 else:
60- type_tuple = guess_type(name)
61- if type_tuple and type_tuple[0]:
62- if type_tuple[0].split('/')[0] == "text":
63- target_type = "text"
64+ target_type = guess_type(name)[0]
65
66 if os.path.exists(file_name):
67 size = os.path.getsize(file_name)
68@@ -106,11 +101,23 @@
69 # there isn't one.
70 url = re.sub(r'/$', '', url)
71
72+ if human_readable:
73+ if mtime:
74+ mtime = datetime.fromtimestamp(mtime).strftime(
75+ '%d-%b-%Y %H:%M')
76+ if target_type:
77+ if target_type.split('/')[0] == "text":
78+ target_type = "text"
79+ else:
80+ target_type = "other"
81+
82+ size = _sizeof_fmt(size)
83+
84 pathname = os.path.join(path, name)
85 license_digest_list = is_protected(pathname)
86 license_list = License.objects.all_with_hashes(license_digest_list)
87 listing.append({'name': name,
88- 'size': _sizeof_fmt(size),
89+ 'size': size,
90 'type': target_type,
91 'mtime': mtime,
92 'license_digest_list': license_digest_list,
93@@ -520,7 +527,7 @@
94 path = os.path.dirname(path)
95 url = os.path.dirname(url)
96
97- listing = dir_list(url, path)
98+ listing = dir_list(url, path, human_readable=False)
99
100 clean_listing = []
101 for entry in listing:

Subscribers

People subscribed via source and target branches