Merge lp:~gesha/linaro-license-protection/add-HEADER-handling into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 92
Merged at revision: 93
Proposed branch: lp:~gesha/linaro-license-protection/add-HEADER-handling
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 138 lines (+80/-1)
4 files modified
license_protected_downloads/tests/test_views.py (+8/-0)
license_protected_downloads/tests/testserver_root/~linaro-android/HEADER.html (+49/-0)
license_protected_downloads/views.py (+22/-1)
templates/dir_template.html (+1/-0)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/add-HEADER-handling
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+117073@code.launchpad.net

Description of the change

This branch adds support of HEADER.html processing which are used on releases.l.o and now is processed internal by apache.

To post a comment you must log in.
Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Hi,

I like the idea. Please add a comment before the header_html = os.path.join(path, "HEADER.html") chunk that you added (or even better, put it in a function with its own docstring). Also, a test would be nice :-)

review: Needs Fixing
91. By Georgy Redkozubov

Moved HEADER.html processing to function. Added test.

92. By Georgy Redkozubov

Added test HEADER.html file

Revision history for this message
Georgy Redkozubov (gesha) wrote :

Fixed.

Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Great. Thanks for the update.

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-07-27 15:03:11 +0000
+++ license_protected_downloads/tests/test_views.py 2012-07-27 15:28:19 +0000
@@ -332,5 +332,13 @@
332 file_path = os.path.join(TESTSERVER_ROOT, target_file)332 file_path = os.path.join(TESTSERVER_ROOT, target_file)
333 self.assertEqual(response['X-Sendfile'], file_path)333 self.assertEqual(response['X-Sendfile'], file_path)
334334
335 def test_header_html(self):
336 target_file = "~linaro-android"
337 url = urlparse.urljoin("http://testserver/", target_file)
338 response = self.client.get(url, follow=True)
339
340 self.assertContains(response,
341 r"Welcome to the Linaro releases server")
342
335if __name__ == '__main__':343if __name__ == '__main__':
336 unittest.main()344 unittest.main()
337345
=== added file 'license_protected_downloads/tests/testserver_root/~linaro-android/HEADER.html'
--- license_protected_downloads/tests/testserver_root/~linaro-android/HEADER.html 1970-01-01 00:00:00 +0000
+++ license_protected_downloads/tests/testserver_root/~linaro-android/HEADER.html 2012-07-27 15:28:19 +0000
@@ -0,0 +1,49 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html>
3<head>
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5 <title>Linaro Releases</title>
6 <link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
7 <link href="http://www.linaro.org/remote/css/init.css" rel="stylesheet" type="text/css" >
8 <link href="http://www.linaro.org/remote/css/remote.css" rel="stylesheet" type="text/css" >
9 </style>
10 <script language="javascript" type="text/javascript" src="http://www.linaro.org/remote/js/linarofamily.js"></script>
11 <script type="text/javascript">
12 var _gaq = _gaq || [];
13 _gaq.push(['_setAccount', 'UA-16756069-8']);
14 _gaq.push(['_trackPageview']);
15
16 (function() {
17 var ga = document.createElement('script'); ga.type = 'text/javascript';
18 ga.async = true;
19 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
20 var s = document.getElementsByTagName('script')[0];
21 s.parentNode.insertBefore(ga, s);
22 })();
23 </script>
24</head>
25<body>
26 <div id="head">
27 <h1>Linaro Releases</h1>
28 </div>
29 <div id="content">
30 <h1>Welcome to the Linaro releases server</h1>
31 Below you will find the images and hardware packs produced by Linaro.
32 <BR />
33 <BR />
34 For more information on how to use these builds please see the Linaro wiki at:
35 <BR />
36 <BR />
37&nbsp; &nbsp; &nbsp; &nbsp; <a href="https://wiki.linaro.org/Platform/Android/ImageInstallation">https://wiki.linaro.org/Platform/Android/ImageInstallation</a>
38 <BR />
39&nbsp; &nbsp; &nbsp; &nbsp; <a href="https://wiki.linaro.org/Platform/DevPlatform/Ubuntu/ImageInstallation">https://wiki.linaro.org/Platform/DevPlatform/Ubuntu/ImageInstallation</a>
40 <BR />
41 <BR />
42 and for an explanation of what is in the builds themselves please head on over to:
43 <BR />
44 <BR />
45&nbsp; &nbsp; &nbsp; &nbsp;<a href="https://wiki.linaro.org/Cycles">https://wiki.linaro.org/Cycles</a>
46 <BR />
47 <BR />
48</body>
49</html>
050
=== modified file 'license_protected_downloads/views.py'
--- license_protected_downloads/views.py 2012-07-27 14:05:42 +0000
+++ license_protected_downloads/views.py 2012-07-27 15:28:19 +0000
@@ -21,6 +21,7 @@
21from buildinfo import BuildInfo21from buildinfo import BuildInfo
22from models import License22from models import License
23from openid_auth import OpenIDAuth23from openid_auth import OpenIDAuth
24from BeautifulSoup import BeautifulSoup
2425
2526
26def _hidden_file(file_name):27def _hidden_file(file_name):
@@ -107,6 +108,24 @@
107 return vendor[1:]108 return vendor[1:]
108109
109110
111def _get_header_html_content(path):
112 """
113 Read HEADER.html in current directory if exists and return
114 contents of <div id="content"> block to include in rendered
115 html.
116 """
117 header_html = os.path.join(path, "HEADER.html")
118 header_content = u""
119 if os.path.isfile(header_html):
120 with open(header_html, "r") as infile:
121 body = infile.read()
122 soup = BeautifulSoup(body)
123 for chunk in soup.findAll(id="content"):
124 header_content += chunk.prettify().decode("utf-8")
125 header_content = '\n'.join(header_content.split('\n')[1:-1])
126 return header_content
127
128
110def is_protected(path):129def is_protected(path):
111 build_info = None130 build_info = None
112 max_index = 1131 max_index = 1
@@ -235,6 +254,7 @@
235 else:254 else:
236 up_dir = None255 up_dir = None
237256
257 header_content = _get_header_html_content(path)
238 download = None258 download = None
239 if 'dl' in request.GET:259 if 'dl' in request.GET:
240 download = request.GET['dl']260 download = request.GET['dl']
@@ -242,7 +262,8 @@
242 return render_to_response('dir_template.html',262 return render_to_response('dir_template.html',
243 {'dirlist': dir_list(url, path),263 {'dirlist': dir_list(url, path),
244 'up_dir': up_dir,264 'up_dir': up_dir,
245 'dl': download})265 'dl': download,
266 'header_content': header_content})
246267
247 file_name = os.path.basename(path)268 file_name = os.path.basename(path)
248269
249270
=== modified file 'templates/dir_template.html'
--- templates/dir_template.html 2012-07-27 14:07:33 +0000
+++ templates/dir_template.html 2012-07-27 15:28:19 +0000
@@ -1,6 +1,7 @@
1{% extends "header.html" %}1{% extends "header.html" %}
22
3{% block content %}3{% block content %}
4{{ header_content|safe }}
4<table>5<table>
5 <tr>6 <tr>
6 <th></th><th>Name</th><th>License</th><th>Last modified</th><th>Size</th>7 <th></th><th>Name</th><th>License</th><th>Last modified</th><th>Size</th>

Subscribers

People subscribed via source and target branches