Merge lp:~stevanr/linaro-license-protection/combined-build-info-files into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Stevan Radaković
Status: Merged
Merged at revision: 182
Proposed branch: lp:~stevanr/linaro-license-protection/combined-build-info-files
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 238 lines (+166/-0)
8 files modified
license_protected_downloads/buildinfo.py (+15/-0)
license_protected_downloads/splice_build_infos.py (+49/-0)
license_protected_downloads/tests/__init__.py (+3/-0)
license_protected_downloads/tests/test_buildinfo.py (+9/-0)
license_protected_downloads/tests/test_splicebuildinfos.py (+35/-0)
license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-open/BUILD-INFO.txt (+6/-0)
license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-protected/BUILD-INFO.txt (+7/-0)
license_protected_downloads/tests/testserver_root/build-info/write-test/BUILD-INFO.txt (+42/-0)
To merge this branch: bzr merge lp:~stevanr/linaro-license-protection/combined-build-info-files
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Georgy Redkozubov Pending
Review via email: mp+159810@code.launchpad.net

Description of the change

Add combined BUILD-INFO support.

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

Looks good.

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

Looks good. Now with the approve tag :-)

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/buildinfo.py'
2--- license_protected_downloads/buildinfo.py 2013-02-26 08:38:32 +0000
3+++ license_protected_downloads/buildinfo.py 2013-04-19 12:21:29 +0000
4@@ -173,6 +173,21 @@
5 for index in open_type:
6 self.file_info_array.pop(index)
7
8+ @classmethod
9+ def write_from_array(cls, build_info_array, file_path):
10+ with open(file_path, "w") as outfile:
11+ outfile.write("Format-Version: 0.1\n\n")
12+ for key in build_info_array[0]:
13+ if key != "format-version":
14+ outfile.write("Files-Pattern: %s\n" % key)
15+ for item in build_info_array[0][key][0]:
16+ text = build_info_array[0][key][0][item]
17+ if item == "license-text":
18+ text = text.replace("\n", "\n ")
19+ outfile.write("%s: %s\n" % (item, text))
20+ outfile.write("\n")
21+
22+
23 if __name__ == "__main__":
24 import sys
25 bi = BuildInfo(sys.argv[1])
26
27=== added file 'license_protected_downloads/splice_build_infos.py'
28--- license_protected_downloads/splice_build_infos.py 1970-01-01 00:00:00 +0000
29+++ license_protected_downloads/splice_build_infos.py 2013-04-19 12:21:29 +0000
30@@ -0,0 +1,49 @@
31+import os
32+
33+from buildinfo import BuildInfo
34+
35+IGNORED_FILES = ["BUILD-INFO.txt", "EULA.txt", "OPEN-EULA.txt"]
36+
37+
38+class SpliceBuildInfos:
39+
40+ def __init__(self, build_info_paths):
41+ """Initiates a splice build info object.
42+
43+ :param build_info_paths: list of dir paths containing
44+ the BUILD-INFO.txt files.
45+ """
46+ self.build_infos = []
47+ for build_info_path in build_info_paths:
48+ for path, subdirs, files in os.walk(build_info_path):
49+ for filename in files:
50+ if path == build_info_path:
51+ if filename not in IGNORED_FILES:
52+ self.build_infos.append(
53+ BuildInfo(os.path.join(path, filename)))
54+
55+ def splice(self, build_info_path):
56+
57+ build_info_res = {}
58+ for build_info in self.build_infos:
59+ build_info_res[build_info.fname] = build_info.file_info_array
60+
61+ build_info_res = self.merge_duplicates(build_info_res)
62+ BuildInfo.write_from_array(build_info_res, build_info_path)
63+
64+ @classmethod
65+ def merge_duplicates(cls, build_info_dict):
66+ build_info_res = {}
67+ for key in build_info_dict:
68+ if build_info_dict[key] in build_info_res.values():
69+ found_key = [name for name, value in
70+ build_info_res.iteritems()
71+ if value == build_info_dict[key]][0]
72+ if key != found_key:
73+ new_key = "%s, %s" % (found_key, key)
74+ build_info_res[new_key] = build_info_dict[key]
75+ del build_info_res[found_key]
76+ else:
77+ build_info_res[key] = build_info_dict[key]
78+
79+ return build_info_res
80
81=== modified file 'license_protected_downloads/tests/__init__.py'
82--- license_protected_downloads/tests/__init__.py 2012-11-28 12:30:30 +0000
83+++ license_protected_downloads/tests/__init__.py 2013-04-19 12:21:29 +0000
84@@ -2,6 +2,8 @@
85 BuildInfoTests,
86 FileNameMatchingTests,
87 )
88+from license_protected_downloads.tests.test_splicebuildinfos \
89+ import SpliceBuildInfosTests
90 from license_protected_downloads.tests.test_models import LicenseTestCase
91 from license_protected_downloads.tests.test_pep8 import TestPep8
92 from license_protected_downloads.tests.test_pyflakes import TestPyflakes
93@@ -19,6 +21,7 @@
94 #starts the test suite
95 __test__ = {
96 'BuildInfoTests': BuildInfoTests,
97+ 'SpliceBuildInfosTests': SpliceBuildInfosTests,
98 'FileNameMatchingTests': FileNameMatchingTests,
99 'FileViewTests': FileViewTests,
100 'HowtoViewTests': HowtoViewTests,
101
102=== modified file 'license_protected_downloads/tests/test_buildinfo.py'
103--- license_protected_downloads/tests/test_buildinfo.py 2013-02-26 08:38:32 +0000
104+++ license_protected_downloads/tests/test_buildinfo.py 2013-04-19 12:21:29 +0000
105@@ -286,6 +286,15 @@
106
107 self.assertEquals(build_info.file_info_array, [{}])
108
109+ def test_write_from_array(self):
110+ build_info = BuildInfo(self.buildinfo_file_path)
111+ file_path = THIS_DIRECTORY + \
112+ '/testserver_root/build-info/write-test/BUILD-INFO.txt'
113+ BuildInfo.write_from_array(build_info.build_info_array, file_path)
114+ build_info_test = BuildInfo(file_path)
115+ self.assertEquals(build_info_test.build_info_array,
116+ build_info.build_info_array)
117+
118
119 class FileNameMatchingTests(unittest.TestCase):
120 def test_buildinfo_simple_filename(self):
121
122=== added file 'license_protected_downloads/tests/test_splicebuildinfos.py'
123--- license_protected_downloads/tests/test_splicebuildinfos.py 1970-01-01 00:00:00 +0000
124+++ license_protected_downloads/tests/test_splicebuildinfos.py 2013-04-19 12:21:29 +0000
125@@ -0,0 +1,35 @@
126+_author__ = 'stevanr'
127+
128+import os
129+import unittest
130+from license_protected_downloads.splice_build_infos import SpliceBuildInfos
131+
132+THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
133+
134+
135+class SpliceBuildInfosTests(unittest.TestCase):
136+ def setUp(self):
137+ dir_path1 = THIS_DIRECTORY + \
138+ '/testserver_root/build-info/splice-build-info/build-info-open'
139+ dir_path2 = THIS_DIRECTORY + \
140+ '/testserver_root/build-info/splice-build-info/build-info-protected'
141+ self.splice_build_infos = SpliceBuildInfos([dir_path1, dir_path2])
142+
143+ def test_merge_duplicates(self):
144+ build_info_dict = {
145+ 'test-protected.txt':
146+ [{'license-type': 'protected',
147+ 'build-name': 'landing-protected',
148+ 'openid-launchpad-teams': 'linaro'}],
149+ 'test-protected-2.txt':
150+ [{'license-type': 'protected',
151+ 'build-name': 'landing-protected',
152+ 'openid-launchpad-teams': 'linaro'}]}
153+
154+ result = {'test-protected.txt, test-protected-2.txt':
155+ [{'license-type': 'protected',
156+ 'build-name': 'landing-protected',
157+ 'openid-launchpad-teams': 'linaro'}]}
158+
159+ build_info_res = SpliceBuildInfos.merge_duplicates(build_info_dict)
160+ self.assertEquals(build_info_res, result)
161
162=== added directory 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info'
163=== added directory 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-open'
164=== added file 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-open/BUILD-INFO.txt'
165--- license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-open/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
166+++ license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-open/BUILD-INFO.txt 2013-04-19 12:21:29 +0000
167@@ -0,0 +1,6 @@
168+Format-Version: 0.1
169+
170+
171+Files-Pattern: *.txt
172+Build-Name: landing-open
173+License-Type: open
174
175=== added file 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-open/testfile.txt'
176=== added file 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-open/testfile2.txt'
177=== added directory 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-protected'
178=== added file 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-protected/BUILD-INFO.txt'
179--- license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-protected/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
180+++ license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-protected/BUILD-INFO.txt 2013-04-19 12:21:29 +0000
181@@ -0,0 +1,7 @@
182+Format-Version: 0.1
183+
184+
185+Files-Pattern: *, *.txt
186+Build-Name: landing-protected
187+License-Type: protected
188+OpenID-Launchpad-Teams: linaro
189
190=== added file 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-protected/test-protected-2.txt'
191=== added file 'license_protected_downloads/tests/testserver_root/build-info/splice-build-info/build-info-protected/test-protected.txt'
192=== added directory 'license_protected_downloads/tests/testserver_root/build-info/write-test'
193=== added file 'license_protected_downloads/tests/testserver_root/build-info/write-test/BUILD-INFO.txt'
194--- license_protected_downloads/tests/testserver_root/build-info/write-test/BUILD-INFO.txt 1970-01-01 00:00:00 +0000
195+++ license_protected_downloads/tests/testserver_root/build-info/write-test/BUILD-INFO.txt 2013-04-19 12:21:29 +0000
196@@ -0,0 +1,42 @@
197+Format-Version: 0.1
198+
199+Files-Pattern: *openid*
200+license-type: protected
201+build-name: landing-protected
202+openid-launchpad-teams: linaro
203+
204+Files-Pattern: *panda*
205+license-type: open
206+build-name: landing-panda
207+
208+Files-Pattern: *.txt
209+license-type: protected
210+build-name: landing-protected
211+openid-launchpad-teams:
212+theme: stericsson
213+collect-user-data: yes
214+license-text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
215+ <p>
216+ THIS IS A LEGALLY BINDING AGREEMENT
217+ </p>
218+
219+Files-Pattern: *origen*
220+theme: samsung
221+license-type: protected
222+build-name: landing-origen
223+license-text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
224+ <p>
225+ THIS IS A LEGALLY BINDING AGREEMENT BETWEEN YOU, an individual or a
226+ legal entity, (“LICENSEE”) AND HAL 1000.
227+ </p>
228+
229+Files-Pattern: *snowball*
230+theme: stericsson
231+license-type: protected
232+build-name: landing-snowball
233+license-text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p>
234+ <p>
235+ THIS IS A LEGALLY BINDING AGREEMENT BETWEEN YOU, an individual or a
236+ legal entity, (“LICENSEE”) AND ME, THE TEST SERVER.
237+ </p>
238+

Subscribers

People subscribed via source and target branches