Merge lp:~gesha/linaro-license-protection/non-recursive-search into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Approved by: Stevan Radaković
Approved revision: 141
Merged at revision: 141
Proposed branch: lp:~gesha/linaro-license-protection/non-recursive-search
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 176 lines (+40/-67)
2 files modified
license_protected_downloads/render_text_files.py (+16/-6)
license_protected_downloads/tests/test_render_text_files.py (+24/-61)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/non-recursive-search
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Linaro Infrastructure Pending
Review via email: mp+130979@code.launchpad.net

Description of the change

This branch adds non-recursive search for README, INSTALL, etc. and for howto/HOWTO_* These files will be rendered only if found in current dir.
Made flash firmware instructions non-mandatory. Updated tests to reflect current state.

To post a comment you must log in.
Revision history for this message
Stevan Radaković (stevanr) wrote :

Hey gesha, this looks good.

One comment though, I don't think we should make flashfirmware non-mandatory so easy.
It should be put under discussion first in the email thread we had, I already told fabo about this.
This effects only android, and it was determined previously that it should have fallback links.
Let's remove it for now, it doesn't have to do anything with the bug were're fixing here.

review: Needs Fixing
141. By Georgy Redkozubov

Revert back HOWTO_flashfirmware.txt

Revision history for this message
Stevan Radaković (stevanr) wrote :

Thanks. Approve +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/render_text_files.py'
2--- license_protected_downloads/render_text_files.py 2012-10-22 17:00:23 +0000
3+++ license_protected_downloads/render_text_files.py 2012-10-23 12:13:28 +0000
4@@ -4,6 +4,8 @@
5 from collections import OrderedDict
6 from django.conf import settings
7
8+HOWTO_PATH = 'howto/'
9+
10 UBUNTU_FILES = ('README',
11 'INSTALL',
12 'HACKING',
13@@ -100,18 +102,24 @@
14 # If there are more of the same type then one, throw custom error as
15 # written above.
16 multiple = 0
17- filepaths = cls.dirEntries(path, True, FILES_MAP.keys())
18- if len(filepaths) > 0:
19- for filepath in FILES_MAP.keys():
20- if len(cls.findall(filepaths,
21+ howtopath = os.path.join(path, HOWTO_PATH)
22+ androidpaths = cls.dirEntries(howtopath, False, ANDROID_FILES)
23+ ubuntupaths = cls.dirEntries(path, False, UBUNTU_FILES)
24+ if len(androidpaths) > 0 and len(ubuntupaths) > 0:
25+ raise MultipleFilesException
26+ if len(androidpaths) > 0:
27+ for filepath in ANDROID_FILES:
28+ if len(cls.findall(androidpaths,
29 lambda x: re.search(filepath, x))) > 1:
30 multiple += 1
31 if multiple == 0:
32- return filepaths
33+ return androidpaths
34 else:
35 raise MultipleFilesException
36+ elif len(ubuntupaths) > 0:
37+ return ubuntupaths
38 else:
39- return filepaths
40+ return []
41
42 @classmethod
43 def flatten(cls, l, ltypes=(list, tuple)):
44@@ -140,6 +148,8 @@
45 directory are added to the list.
46 '''
47 fileList = []
48+ if not os.path.exists(path):
49+ return fileList
50 for file in os.listdir(path):
51 dirfile = os.path.join(path, file)
52 if os.path.isfile(dirfile):
53
54=== modified file 'license_protected_downloads/tests/test_render_text_files.py'
55--- license_protected_downloads/tests/test_render_text_files.py 2012-10-22 17:00:23 +0000
56+++ license_protected_downloads/tests/test_render_text_files.py 2012-10-23 12:13:28 +0000
57@@ -8,7 +8,7 @@
58 import MultipleFilesException
59 from license_protected_downloads.render_text_files import ANDROID_FILES
60 from license_protected_downloads.render_text_files import UBUNTU_FILES
61-
62+from license_protected_downloads.render_text_files import HOWTO_PATH
63
64 THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
65
66@@ -35,87 +35,50 @@
67 self.assertEqual([],
68 RenderTextFiles.findall(l, lambda x: re.search(r'1', x)))
69
70- def make_temp_dir(self, empty=True, file_list=None, dir=None):
71+ def make_temp_dir(self, empty=True, file_list=None, dir=None, subdir=None):
72 path = tempfile.mkdtemp(dir=dir)
73 if not empty:
74 if file_list:
75+ if subdir:
76+ movepath = os.path.join(path, HOWTO_PATH)
77+ os.makedirs(movepath)
78+ else:
79+ movepath = path
80 for file in file_list:
81- handle, fname = tempfile.mkstemp(dir=path)
82- shutil.move(fname, os.path.join(path, file))
83+ handle, fname = tempfile.mkstemp(dir=movepath)
84+ shutil.move(fname, os.path.join(movepath, file))
85 return path
86
87- def test_find_relevant_files_multiple_files(self):
88- path = tempfile.mkdtemp()
89- handle, fname = tempfile.mkstemp(dir=path)
90- shutil.move(fname, os.path.join(path, 'README'))
91- path1 = tempfile.mkdtemp(dir=path)
92- handle, fname = tempfile.mkstemp(dir=path1)
93- shutil.move(fname, os.path.join(path1, 'README'))
94- with self.assertRaises(MultipleFilesException):
95- RenderTextFiles.find_relevant_files(path)
96-
97 def test_find_relevant_files_android(self):
98- path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES)
99+ path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
100+ subdir=HOWTO_PATH)
101 full_android_files = []
102 for file in ANDROID_FILES:
103- full_android_files.append(os.path.join(path, file))
104+ full_android_files.append(os.path.join(path, HOWTO_PATH, file))
105 self.assertEqual(sorted(full_android_files),
106 sorted(RenderTextFiles.find_relevant_files(path)))
107
108 def test_find_relevant_files_android_subdir(self):
109 path = self.make_temp_dir()
110 full_path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
111- dir=path)
112+ dir=path, subdir=HOWTO_PATH)
113 full_android_files = []
114 for file in ANDROID_FILES:
115- full_android_files.append(os.path.join(full_path, file))
116- self.assertEqual(sorted(full_android_files),
117+ full_android_files.append(os.path.join(full_path, HOWTO_PATH,
118+ file))
119+ self.assertEqual([],
120 sorted(RenderTextFiles.find_relevant_files(path)))
121 self.assertEqual(sorted(full_android_files),
122 sorted(RenderTextFiles.find_relevant_files(full_path)))
123
124- def test_find_relevant_files_android_several_subdirs(self):
125- path = self.make_temp_dir()
126- full_path1 = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
127- dir=path)
128- full_path2 = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
129- dir=path)
130- full_android_files1 = []
131- full_android_files2 = []
132- for file in ANDROID_FILES:
133- full_android_files1.append(os.path.join(full_path1, file))
134- full_android_files2.append(os.path.join(full_path2, file))
135- with self.assertRaises(MultipleFilesException):
136- RenderTextFiles.find_relevant_files(path)
137- self.assertEqual(sorted(full_android_files1),
138- sorted(RenderTextFiles.find_relevant_files(full_path1)))
139- self.assertEqual(sorted(full_android_files2),
140- sorted(RenderTextFiles.find_relevant_files(full_path2)))
141-
142 def test_find_relevant_files_android_and_ubuntu_samedir(self):
143- flist = ANDROID_FILES + UBUNTU_FILES
144- path = self.make_temp_dir(empty=False, file_list=flist)
145+ path = self.make_temp_dir(empty=False, file_list=UBUNTU_FILES)
146+ os.makedirs(os.path.join(path, HOWTO_PATH))
147 full_files = []
148- for file in flist:
149+ for file in ANDROID_FILES:
150+ full_files.append(os.path.join(path, HOWTO_PATH, file))
151+ open(os.path.join(path, HOWTO_PATH, file), 'w').close()
152+ for file in UBUNTU_FILES:
153 full_files.append(os.path.join(path, file))
154- self.assertListEqual(sorted(full_files),
155- sorted(RenderTextFiles.find_relevant_files(path)))
156-
157- def test_find_relevant_files_android_and_ubuntu_different_subdirs(self):
158- path = self.make_temp_dir()
159- android_path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
160- dir=path)
161- ubuntu_path = self.make_temp_dir(empty=False, file_list=UBUNTU_FILES,
162- dir=path)
163- full_android_files = []
164- full_ubuntu_files = []
165- for file in ANDROID_FILES:
166- full_android_files.append(os.path.join(android_path, file))
167- for file in UBUNTU_FILES:
168- full_ubuntu_files.append(os.path.join(ubuntu_path, file))
169- self.assertEqual(sorted(full_android_files + full_ubuntu_files),
170- sorted(RenderTextFiles.find_relevant_files(path)))
171- self.assertEqual(sorted(full_android_files),
172- sorted(RenderTextFiles.find_relevant_files(android_path)))
173- self.assertEqual(sorted(full_ubuntu_files),
174- sorted(RenderTextFiles.find_relevant_files(ubuntu_path)))
175+ with self.assertRaises(MultipleFilesException):
176+ RenderTextFiles.find_relevant_files(path)

Subscribers

People subscribed via source and target branches