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
1=== modified file 'license_protected_downloads/tests/test_views.py'
2--- license_protected_downloads/tests/test_views.py 2012-07-27 15:03:11 +0000
3+++ license_protected_downloads/tests/test_views.py 2012-07-27 15:28:19 +0000
4@@ -332,5 +332,13 @@
5 file_path = os.path.join(TESTSERVER_ROOT, target_file)
6 self.assertEqual(response['X-Sendfile'], file_path)
7
8+ def test_header_html(self):
9+ target_file = "~linaro-android"
10+ url = urlparse.urljoin("http://testserver/", target_file)
11+ response = self.client.get(url, follow=True)
12+
13+ self.assertContains(response,
14+ r"Welcome to the Linaro releases server")
15+
16 if __name__ == '__main__':
17 unittest.main()
18
19=== added file 'license_protected_downloads/tests/testserver_root/~linaro-android/HEADER.html'
20--- license_protected_downloads/tests/testserver_root/~linaro-android/HEADER.html 1970-01-01 00:00:00 +0000
21+++ license_protected_downloads/tests/testserver_root/~linaro-android/HEADER.html 2012-07-27 15:28:19 +0000
22@@ -0,0 +1,49 @@
23+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
24+<html>
25+<head>
26+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
27+ <title>Linaro Releases</title>
28+ <link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
29+ <link href="http://www.linaro.org/remote/css/init.css" rel="stylesheet" type="text/css" >
30+ <link href="http://www.linaro.org/remote/css/remote.css" rel="stylesheet" type="text/css" >
31+ </style>
32+ <script language="javascript" type="text/javascript" src="http://www.linaro.org/remote/js/linarofamily.js"></script>
33+ <script type="text/javascript">
34+ var _gaq = _gaq || [];
35+ _gaq.push(['_setAccount', 'UA-16756069-8']);
36+ _gaq.push(['_trackPageview']);
37+
38+ (function() {
39+ var ga = document.createElement('script'); ga.type = 'text/javascript';
40+ ga.async = true;
41+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
42+ var s = document.getElementsByTagName('script')[0];
43+ s.parentNode.insertBefore(ga, s);
44+ })();
45+ </script>
46+</head>
47+<body>
48+ <div id="head">
49+ <h1>Linaro Releases</h1>
50+ </div>
51+ <div id="content">
52+ <h1>Welcome to the Linaro releases server</h1>
53+ Below you will find the images and hardware packs produced by Linaro.
54+ <BR />
55+ <BR />
56+ For more information on how to use these builds please see the Linaro wiki at:
57+ <BR />
58+ <BR />
59+&nbsp; &nbsp; &nbsp; &nbsp; <a href="https://wiki.linaro.org/Platform/Android/ImageInstallation">https://wiki.linaro.org/Platform/Android/ImageInstallation</a>
60+ <BR />
61+&nbsp; &nbsp; &nbsp; &nbsp; <a href="https://wiki.linaro.org/Platform/DevPlatform/Ubuntu/ImageInstallation">https://wiki.linaro.org/Platform/DevPlatform/Ubuntu/ImageInstallation</a>
62+ <BR />
63+ <BR />
64+ and for an explanation of what is in the builds themselves please head on over to:
65+ <BR />
66+ <BR />
67+&nbsp; &nbsp; &nbsp; &nbsp;<a href="https://wiki.linaro.org/Cycles">https://wiki.linaro.org/Cycles</a>
68+ <BR />
69+ <BR />
70+</body>
71+</html>
72
73=== modified file 'license_protected_downloads/views.py'
74--- license_protected_downloads/views.py 2012-07-27 14:05:42 +0000
75+++ license_protected_downloads/views.py 2012-07-27 15:28:19 +0000
76@@ -21,6 +21,7 @@
77 from buildinfo import BuildInfo
78 from models import License
79 from openid_auth import OpenIDAuth
80+from BeautifulSoup import BeautifulSoup
81
82
83 def _hidden_file(file_name):
84@@ -107,6 +108,24 @@
85 return vendor[1:]
86
87
88+def _get_header_html_content(path):
89+ """
90+ Read HEADER.html in current directory if exists and return
91+ contents of <div id="content"> block to include in rendered
92+ html.
93+ """
94+ header_html = os.path.join(path, "HEADER.html")
95+ header_content = u""
96+ if os.path.isfile(header_html):
97+ with open(header_html, "r") as infile:
98+ body = infile.read()
99+ soup = BeautifulSoup(body)
100+ for chunk in soup.findAll(id="content"):
101+ header_content += chunk.prettify().decode("utf-8")
102+ header_content = '\n'.join(header_content.split('\n')[1:-1])
103+ return header_content
104+
105+
106 def is_protected(path):
107 build_info = None
108 max_index = 1
109@@ -235,6 +254,7 @@
110 else:
111 up_dir = None
112
113+ header_content = _get_header_html_content(path)
114 download = None
115 if 'dl' in request.GET:
116 download = request.GET['dl']
117@@ -242,7 +262,8 @@
118 return render_to_response('dir_template.html',
119 {'dirlist': dir_list(url, path),
120 'up_dir': up_dir,
121- 'dl': download})
122+ 'dl': download,
123+ 'header_content': header_content})
124
125 file_name = os.path.basename(path)
126
127
128=== modified file 'templates/dir_template.html'
129--- templates/dir_template.html 2012-07-27 14:07:33 +0000
130+++ templates/dir_template.html 2012-07-27 15:28:19 +0000
131@@ -1,6 +1,7 @@
132 {% extends "header.html" %}
133
134 {% block content %}
135+{{ header_content|safe }}
136 <table>
137 <tr>
138 <th></th><th>Name</th><th>License</th><th>Last modified</th><th>Size</th>

Subscribers

People subscribed via source and target branches