Merge lp:~gesha/linaro-license-protection/remove-fallback into lp:~linaro-automation/linaro-license-protection/trunk
- remove-fallback
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 144 |
Proposed branch: | lp:~gesha/linaro-license-protection/remove-fallback |
Merge into: | lp:~linaro-automation/linaro-license-protection/trunk |
Diff against target: |
243 lines (+35/-91) 6 files modified
license_protected_downloads/render_text_files.py (+23/-62) license_protected_downloads/tests/test_render_text_files.py (+11/-21) settings.py (+1/-5) templates/textile_fallbacks/HOWTO_flashfirmware.txt (+0/-1) templates/textile_fallbacks/HOWTO_getsourceandbuild.txt (+0/-1) templates/textile_fallbacks/HOWTO_install.txt (+0/-1) |
To merge this branch: | bzr merge lp:~gesha/linaro-license-protection/remove-fallback |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Данило Шеган (community) | Approve | ||
Review via email: mp+131152@code.launchpad.net |
Commit message
Description of the change
This branch removes fallback support for HOWTOs and adds searching of HOWTOs only in current dir.
Georgy Redkozubov (gesha) wrote : | # |
> In the call to cls.dirEntries, it is unclear what do arguments represent
> (especially "False"). Python does have one of my favourite features for
> readability, which is passing arguments by keywords: please use that.
Not sure is you meant what I did, but anyway fixed.
>
> Where you check
>
> if len(androidpaths) > 0 and len(ubuntupaths) > 0:
>
> you could add an "else" block and get rid of the "else" block in the if below
> (and replace "elif" simply with "else"): not a big deal, but will move
> "corner" cases to one if, and actual handling to another.
Done
>
> In tests, I wonder if subdir argument is still needed at all for
> make_temp_dir?
Thanks for pointing to this, I forget to remove initially.
- 146. By Georgy Redkozubov
-
Fixes based on review comments
Данило Шеган (danilo) wrote : | # |
Ok, now that it's clear that second parameter to dirEntries is "subdir", I suppose we can get rid of that as well :)
Also, please provide a string explanation of the error condition where we raise MultipleFilesEx
- 147. By Georgy Redkozubov
-
Removed recursive search based on review.
Данило Шеган (danilo) wrote : | # |
Other than the exception still missing the string passed in, looks good. Thanks for keeping up with my requests :)
- 148. By Georgy Redkozubov
-
Added exception explanation.
Preview Diff
1 | === modified file 'license_protected_downloads/render_text_files.py' |
2 | --- license_protected_downloads/render_text_files.py 2012-10-23 18:51:49 +0000 |
3 | +++ license_protected_downloads/render_text_files.py 2012-10-24 16:10:24 +0000 |
4 | @@ -1,5 +1,4 @@ |
5 | import os |
6 | -import re |
7 | import textile |
8 | import OrderedDict |
9 | from django.conf import settings |
10 | @@ -35,15 +34,6 @@ |
11 | title = settings.FILES_MAP[os.path.basename(filepath)] |
12 | result[title] = cls.render_file(filepath) |
13 | |
14 | - # Switch to fallback data for mandatory files. |
15 | - if cls.check_for_manifest_or_tarballs(path): |
16 | - for filename in settings.MANDATORY_ANDROID_FILES: |
17 | - if settings.FILES_MAP[filename] not in result: |
18 | - filepath = os.path.join(settings.TEXTILE_FALLBACK_PATH, |
19 | - filename) |
20 | - title = settings.FILES_MAP[filename] |
21 | - result[title] = cls.render_file(filepath) |
22 | - |
23 | if not filepaths and len(result) == 0: |
24 | return None |
25 | |
26 | @@ -67,26 +57,20 @@ |
27 | # Go recursively and find howto's, readme's, hackings, installs. |
28 | # If there are more of the same type then one, throw custom error as |
29 | # written above. |
30 | - multiple = 0 |
31 | - howtopath = os.path.join(path, settings.HOWTO_PATH) |
32 | - androidpaths = cls.dirEntries(howtopath, False, |
33 | - settings.ANDROID_FILES) |
34 | - ubuntupaths = cls.dirEntries(path, False, settings.LINUX_FILES) |
35 | + # Raise MultipleFilesException if files from ANDROID_FILES and |
36 | + # LINUX_FILES exist in the same dir. |
37 | + |
38 | + androidpaths = cls.dirEntries(path, files_list=settings.ANDROID_FILES) |
39 | + ubuntupaths = cls.dirEntries(path, files_list=settings.LINUX_FILES) |
40 | if len(androidpaths) > 0 and len(ubuntupaths) > 0: |
41 | - raise MultipleFilesException |
42 | - if len(androidpaths) > 0: |
43 | - for filepath in settings.ANDROID_FILES: |
44 | - if len(cls.findall(androidpaths, |
45 | - lambda x: re.search(filepath, x))) > 1: |
46 | - multiple += 1 |
47 | - if multiple == 0: |
48 | + # Files from ANDROID_FILES and LINUX_FILES exist in the same dir |
49 | + raise MultipleFilesException("Both Android and Ubuntu HOWTO " \ |
50 | + "files are found, which is unsupported.") |
51 | + else: |
52 | + if len(androidpaths) > 0: |
53 | return androidpaths |
54 | else: |
55 | - raise MultipleFilesException |
56 | - elif len(ubuntupaths) > 0: |
57 | - return ubuntupaths |
58 | - else: |
59 | - return [] |
60 | + return ubuntupaths |
61 | |
62 | @classmethod |
63 | def flatten(cls, l, ltypes=(list, tuple)): |
64 | @@ -105,29 +89,23 @@ |
65 | return ltype(l) |
66 | |
67 | @classmethod |
68 | - def dirEntries(cls, path, subdir, *args): |
69 | - ''' Return a list of file names found in directory 'dir_name' |
70 | - If 'subdir' is True, recursively access subdirectories under |
71 | - 'dir_name'. |
72 | - Additional arguments, if any, are file names to match filenames. |
73 | - Matched file names are added to the list. |
74 | + def dirEntries(cls, path, files_list=None): |
75 | + ''' Return a list of file names found in directory 'path' |
76 | + 'files_list' are file names to match filenames. Matched file names |
77 | + are added to the list. |
78 | If there are no additional arguments, all files found in the |
79 | directory are added to the list. |
80 | ''' |
81 | fileList = [] |
82 | - if not os.path.exists(path): |
83 | - return fileList |
84 | - for file in os.listdir(path): |
85 | - dirfile = os.path.join(path, file) |
86 | - if os.path.isfile(dirfile): |
87 | - if not args: |
88 | - fileList.append(dirfile) |
89 | - else: |
90 | - if file in cls.flatten(args): |
91 | + if os.path.exists(path): |
92 | + for file in os.listdir(path): |
93 | + dirfile = os.path.join(path, file) |
94 | + if os.path.isfile(dirfile): |
95 | + if not files_list: |
96 | fileList.append(dirfile) |
97 | - # recursively access file names in subdirectories |
98 | - elif os.path.isdir(dirfile) and subdir: |
99 | - fileList.extend(cls.dirEntries(dirfile, subdir, *args)) |
100 | + else: |
101 | + if file in cls.flatten(files_list): |
102 | + fileList.append(dirfile) |
103 | return fileList |
104 | |
105 | @classmethod |
106 | @@ -149,20 +127,3 @@ |
107 | # hence there is an out of range exception |
108 | except IndexError: |
109 | return indices |
110 | - |
111 | - @classmethod |
112 | - def check_for_manifest_or_tarballs(cls, path): |
113 | - ''' Check if there is a MANIFEST file in current path or a tarball. |
114 | - Also check if we are currently somewhere in 'android' path. |
115 | - This hack is necessary for fallback wiki howto links. |
116 | - ''' |
117 | - if 'android' in path: |
118 | - for filename in os.listdir(path): |
119 | - if "MANIFEST" in filename: |
120 | - return True |
121 | - if "tar.bz2" in filename: |
122 | - return True |
123 | - if ".img" in filename: |
124 | - return True |
125 | - |
126 | - return False |
127 | |
128 | === modified file 'license_protected_downloads/tests/test_render_text_files.py' |
129 | --- license_protected_downloads/tests/test_render_text_files.py 2012-10-23 12:37:11 +0000 |
130 | +++ license_protected_downloads/tests/test_render_text_files.py 2012-10-24 16:10:24 +0000 |
131 | @@ -33,29 +33,21 @@ |
132 | self.assertEqual([], |
133 | RenderTextFiles.findall(l, lambda x: re.search(r'1', x))) |
134 | |
135 | - def make_temp_dir(self, empty=True, file_list=None, dir=None, subdir=None): |
136 | + def make_temp_dir(self, empty=True, file_list=None, dir=None): |
137 | path = tempfile.mkdtemp(dir=dir) |
138 | if not empty: |
139 | if file_list: |
140 | - if subdir: |
141 | - movepath = os.path.join(path, settings.HOWTO_PATH) |
142 | - os.makedirs(movepath) |
143 | - else: |
144 | - movepath = path |
145 | for file in file_list: |
146 | - handle, fname = tempfile.mkstemp(dir=movepath) |
147 | - shutil.move(fname, os.path.join(movepath, file)) |
148 | + handle, fname = tempfile.mkstemp(dir=path) |
149 | + shutil.move(fname, os.path.join(path, file)) |
150 | return path |
151 | |
152 | def test_find_relevant_files_android(self): |
153 | path = self.make_temp_dir(empty=False, |
154 | - file_list=settings.ANDROID_FILES, |
155 | - subdir=settings.HOWTO_PATH) |
156 | + file_list=settings.ANDROID_FILES) |
157 | full_android_files = [] |
158 | for file in settings.ANDROID_FILES: |
159 | - full_android_files.append(os.path.join(path, |
160 | - settings.HOWTO_PATH, |
161 | - file)) |
162 | + full_android_files.append(os.path.join(path, file)) |
163 | self.assertEqual(sorted(full_android_files), |
164 | sorted(RenderTextFiles.find_relevant_files(path))) |
165 | |
166 | @@ -63,24 +55,22 @@ |
167 | path = self.make_temp_dir() |
168 | full_path = self.make_temp_dir(empty=False, |
169 | file_list=settings.ANDROID_FILES, |
170 | - dir=path, subdir=settings.HOWTO_PATH) |
171 | + dir=path) |
172 | full_android_files = [] |
173 | for file in settings.ANDROID_FILES: |
174 | - full_android_files.append(os.path.join(full_path, |
175 | - settings.HOWTO_PATH, |
176 | - file)) |
177 | + full_android_files.append(os.path.join(full_path, file)) |
178 | self.assertEqual([], |
179 | sorted(RenderTextFiles.find_relevant_files(path))) |
180 | self.assertEqual(sorted(full_android_files), |
181 | sorted(RenderTextFiles.find_relevant_files(full_path))) |
182 | |
183 | def test_find_relevant_files_android_and_ubuntu_samedir(self): |
184 | - path = self.make_temp_dir(empty=False, file_list=settings.LINUX_FILES) |
185 | - os.makedirs(os.path.join(path, settings.HOWTO_PATH)) |
186 | + path = self.make_temp_dir(empty=False, |
187 | + file_list=settings.LINUX_FILES + settings.ANDROID_FILES) |
188 | full_files = [] |
189 | for file in settings.ANDROID_FILES: |
190 | - full_files.append(os.path.join(path, settings.HOWTO_PATH, file)) |
191 | - open(os.path.join(path, settings.HOWTO_PATH, file), 'w').close() |
192 | + full_files.append(os.path.join(path, file)) |
193 | + open(os.path.join(path, file), 'w').close() |
194 | for file in settings.LINUX_FILES: |
195 | full_files.append(os.path.join(path, file)) |
196 | with self.assertRaises(MultipleFilesException): |
197 | |
198 | === modified file 'settings.py' |
199 | --- settings.py 2012-10-23 13:07:01 +0000 |
200 | +++ settings.py 2012-10-24 16:10:24 +0000 |
201 | @@ -163,22 +163,18 @@ |
202 | ) |
203 | |
204 | # Render TEXTILE files settings. |
205 | -HOWTO_PATH = 'howto/' |
206 | - |
207 | LINUX_FILES = ('README', |
208 | 'INSTALL', |
209 | 'HACKING', |
210 | 'FIRMWARE', |
211 | 'RTSM') |
212 | + |
213 | ANDROID_FILES = ('HOWTO_releasenotes.txt', |
214 | 'HOWTO_install.txt', |
215 | 'HOWTO_getsourceandbuild.txt', |
216 | 'HOWTO_flashfirmware.txt', |
217 | 'HOWTO_rtsm.txt') |
218 | |
219 | -MANDATORY_ANDROID_FILES = ('HOWTO_install.txt', |
220 | - 'HOWTO_getsourceandbuild.txt') |
221 | - |
222 | FILES_MAP = {'HOWTO_releasenotes.txt': 'Release Notes', |
223 | 'HOWTO_install.txt': 'Binary Image Installation', |
224 | 'HOWTO_getsourceandbuild.txt': 'Building From Source', |
225 | |
226 | === removed directory 'templates/textile_fallbacks' |
227 | === removed file 'templates/textile_fallbacks/HOWTO_flashfirmware.txt' |
228 | --- templates/textile_fallbacks/HOWTO_flashfirmware.txt 2012-10-19 11:06:33 +0000 |
229 | +++ templates/textile_fallbacks/HOWTO_flashfirmware.txt 1970-01-01 00:00:00 +0000 |
230 | @@ -1,1 +0,0 @@ |
231 | -Please read "Flash Firmware Wiki page":https://wiki.linaro.org/Platform/Android/FlashFirmware <br><br>For more info, check out this "page":https://wiki.linaro.org/Platform/Android |
232 | |
233 | === removed file 'templates/textile_fallbacks/HOWTO_getsourceandbuild.txt' |
234 | --- templates/textile_fallbacks/HOWTO_getsourceandbuild.txt 2012-10-19 11:06:33 +0000 |
235 | +++ templates/textile_fallbacks/HOWTO_getsourceandbuild.txt 1970-01-01 00:00:00 +0000 |
236 | @@ -1,1 +0,0 @@ |
237 | -Please read these two pages: "Get Source page":https://wiki.linaro.org/Platform/Android/GetSource and "Build Source page":https://wiki.linaro.org/Platform/Android/BuildSource <br><br>For more info, check out this "page":https://wiki.linaro.org/Platform/Android |
238 | |
239 | === removed file 'templates/textile_fallbacks/HOWTO_install.txt' |
240 | --- templates/textile_fallbacks/HOWTO_install.txt 2012-10-19 11:06:33 +0000 |
241 | +++ templates/textile_fallbacks/HOWTO_install.txt 1970-01-01 00:00:00 +0000 |
242 | @@ -1,1 +0,0 @@ |
243 | -Please read "Image Installation Wiki page":https://wiki.linaro.org/Platform/Android/ImageInstallation <br><br>For more info, check out this "page":https://wiki.linaro.org/Platform/Android |
In the call to cls.dirEntries, it is unclear what do arguments represent (especially "False"). Python does have one of my favourite features for readability, which is passing arguments by keywords: please use that.
Where you check
if len(androidpaths) > 0 and len(ubuntupaths) > 0:
you could add an "else" block and get rid of the "else" block in the if below (and replace "elif" simply with "else"): not a big deal, but will move "corner" cases to one if, and actual handling to another.
In tests, I wonder if subdir argument is still needed at all for make_temp_dir?