Merge lp:~gesha/linaro-license-protection/remove-fallback into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
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
Reviewer Review Type Date Requested Status
Данило Шеган (community) Approve
Review via email: mp+131152@code.launchpad.net

Description of the change

This branch removes fallback support for HOWTOs and adds searching of HOWTOs only in current dir.

To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) 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.

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?

review: Needs Fixing
Revision history for this message
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

Revision history for this message
Данило Шеган (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 MultipleFilesException.

147. By Georgy Redkozubov

Removed recursive search based on review.

Revision history for this message
Данило Шеган (danilo) wrote :

Other than the exception still missing the string passed in, looks good. Thanks for keeping up with my requests :)

review: Approve
148. By Georgy Redkozubov

Added exception explanation.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'license_protected_downloads/render_text_files.py'
--- license_protected_downloads/render_text_files.py 2012-10-23 18:51:49 +0000
+++ license_protected_downloads/render_text_files.py 2012-10-24 16:10:24 +0000
@@ -1,5 +1,4 @@
1import os1import os
2import re
3import textile2import textile
4import OrderedDict3import OrderedDict
5from django.conf import settings4from django.conf import settings
@@ -35,15 +34,6 @@
35 title = settings.FILES_MAP[os.path.basename(filepath)]34 title = settings.FILES_MAP[os.path.basename(filepath)]
36 result[title] = cls.render_file(filepath)35 result[title] = cls.render_file(filepath)
3736
38 # Switch to fallback data for mandatory files.
39 if cls.check_for_manifest_or_tarballs(path):
40 for filename in settings.MANDATORY_ANDROID_FILES:
41 if settings.FILES_MAP[filename] not in result:
42 filepath = os.path.join(settings.TEXTILE_FALLBACK_PATH,
43 filename)
44 title = settings.FILES_MAP[filename]
45 result[title] = cls.render_file(filepath)
46
47 if not filepaths and len(result) == 0:37 if not filepaths and len(result) == 0:
48 return None38 return None
4939
@@ -67,26 +57,20 @@
67 # Go recursively and find howto's, readme's, hackings, installs.57 # Go recursively and find howto's, readme's, hackings, installs.
68 # If there are more of the same type then one, throw custom error as58 # If there are more of the same type then one, throw custom error as
69 # written above.59 # written above.
70 multiple = 060 # Raise MultipleFilesException if files from ANDROID_FILES and
71 howtopath = os.path.join(path, settings.HOWTO_PATH)61 # LINUX_FILES exist in the same dir.
72 androidpaths = cls.dirEntries(howtopath, False,62
73 settings.ANDROID_FILES)63 androidpaths = cls.dirEntries(path, files_list=settings.ANDROID_FILES)
74 ubuntupaths = cls.dirEntries(path, False, settings.LINUX_FILES)64 ubuntupaths = cls.dirEntries(path, files_list=settings.LINUX_FILES)
75 if len(androidpaths) > 0 and len(ubuntupaths) > 0:65 if len(androidpaths) > 0 and len(ubuntupaths) > 0:
76 raise MultipleFilesException66 # Files from ANDROID_FILES and LINUX_FILES exist in the same dir
77 if len(androidpaths) > 0:67 raise MultipleFilesException("Both Android and Ubuntu HOWTO " \
78 for filepath in settings.ANDROID_FILES:68 "files are found, which is unsupported.")
79 if len(cls.findall(androidpaths,69 else:
80 lambda x: re.search(filepath, x))) > 1:70 if len(androidpaths) > 0:
81 multiple += 1
82 if multiple == 0:
83 return androidpaths71 return androidpaths
84 else:72 else:
85 raise MultipleFilesException73 return ubuntupaths
86 elif len(ubuntupaths) > 0:
87 return ubuntupaths
88 else:
89 return []
9074
91 @classmethod75 @classmethod
92 def flatten(cls, l, ltypes=(list, tuple)):76 def flatten(cls, l, ltypes=(list, tuple)):
@@ -105,29 +89,23 @@
105 return ltype(l)89 return ltype(l)
10690
107 @classmethod91 @classmethod
108 def dirEntries(cls, path, subdir, *args):92 def dirEntries(cls, path, files_list=None):
109 ''' Return a list of file names found in directory 'dir_name'93 ''' Return a list of file names found in directory 'path'
110 If 'subdir' is True, recursively access subdirectories under94 'files_list' are file names to match filenames. Matched file names
111 'dir_name'.95 are added to the list.
112 Additional arguments, if any, are file names to match filenames.
113 Matched file names are added to the list.
114 If there are no additional arguments, all files found in the96 If there are no additional arguments, all files found in the
115 directory are added to the list.97 directory are added to the list.
116 '''98 '''
117 fileList = []99 fileList = []
118 if not os.path.exists(path):100 if os.path.exists(path):
119 return fileList101 for file in os.listdir(path):
120 for file in os.listdir(path):102 dirfile = os.path.join(path, file)
121 dirfile = os.path.join(path, file)103 if os.path.isfile(dirfile):
122 if os.path.isfile(dirfile):104 if not files_list:
123 if not args:
124 fileList.append(dirfile)
125 else:
126 if file in cls.flatten(args):
127 fileList.append(dirfile)105 fileList.append(dirfile)
128 # recursively access file names in subdirectories106 else:
129 elif os.path.isdir(dirfile) and subdir:107 if file in cls.flatten(files_list):
130 fileList.extend(cls.dirEntries(dirfile, subdir, *args))108 fileList.append(dirfile)
131 return fileList109 return fileList
132110
133 @classmethod111 @classmethod
@@ -149,20 +127,3 @@
149 # hence there is an out of range exception127 # hence there is an out of range exception
150 except IndexError:128 except IndexError:
151 return indices129 return indices
152
153 @classmethod
154 def check_for_manifest_or_tarballs(cls, path):
155 ''' Check if there is a MANIFEST file in current path or a tarball.
156 Also check if we are currently somewhere in 'android' path.
157 This hack is necessary for fallback wiki howto links.
158 '''
159 if 'android' in path:
160 for filename in os.listdir(path):
161 if "MANIFEST" in filename:
162 return True
163 if "tar.bz2" in filename:
164 return True
165 if ".img" in filename:
166 return True
167
168 return False
169130
=== modified file 'license_protected_downloads/tests/test_render_text_files.py'
--- license_protected_downloads/tests/test_render_text_files.py 2012-10-23 12:37:11 +0000
+++ license_protected_downloads/tests/test_render_text_files.py 2012-10-24 16:10:24 +0000
@@ -33,29 +33,21 @@
33 self.assertEqual([],33 self.assertEqual([],
34 RenderTextFiles.findall(l, lambda x: re.search(r'1', x)))34 RenderTextFiles.findall(l, lambda x: re.search(r'1', x)))
3535
36 def make_temp_dir(self, empty=True, file_list=None, dir=None, subdir=None):36 def make_temp_dir(self, empty=True, file_list=None, dir=None):
37 path = tempfile.mkdtemp(dir=dir)37 path = tempfile.mkdtemp(dir=dir)
38 if not empty:38 if not empty:
39 if file_list:39 if file_list:
40 if subdir:
41 movepath = os.path.join(path, settings.HOWTO_PATH)
42 os.makedirs(movepath)
43 else:
44 movepath = path
45 for file in file_list:40 for file in file_list:
46 handle, fname = tempfile.mkstemp(dir=movepath)41 handle, fname = tempfile.mkstemp(dir=path)
47 shutil.move(fname, os.path.join(movepath, file))42 shutil.move(fname, os.path.join(path, file))
48 return path43 return path
4944
50 def test_find_relevant_files_android(self):45 def test_find_relevant_files_android(self):
51 path = self.make_temp_dir(empty=False,46 path = self.make_temp_dir(empty=False,
52 file_list=settings.ANDROID_FILES,47 file_list=settings.ANDROID_FILES)
53 subdir=settings.HOWTO_PATH)
54 full_android_files = []48 full_android_files = []
55 for file in settings.ANDROID_FILES:49 for file in settings.ANDROID_FILES:
56 full_android_files.append(os.path.join(path,50 full_android_files.append(os.path.join(path, file))
57 settings.HOWTO_PATH,
58 file))
59 self.assertEqual(sorted(full_android_files),51 self.assertEqual(sorted(full_android_files),
60 sorted(RenderTextFiles.find_relevant_files(path)))52 sorted(RenderTextFiles.find_relevant_files(path)))
6153
@@ -63,24 +55,22 @@
63 path = self.make_temp_dir()55 path = self.make_temp_dir()
64 full_path = self.make_temp_dir(empty=False,56 full_path = self.make_temp_dir(empty=False,
65 file_list=settings.ANDROID_FILES,57 file_list=settings.ANDROID_FILES,
66 dir=path, subdir=settings.HOWTO_PATH)58 dir=path)
67 full_android_files = []59 full_android_files = []
68 for file in settings.ANDROID_FILES:60 for file in settings.ANDROID_FILES:
69 full_android_files.append(os.path.join(full_path,61 full_android_files.append(os.path.join(full_path, file))
70 settings.HOWTO_PATH,
71 file))
72 self.assertEqual([],62 self.assertEqual([],
73 sorted(RenderTextFiles.find_relevant_files(path)))63 sorted(RenderTextFiles.find_relevant_files(path)))
74 self.assertEqual(sorted(full_android_files),64 self.assertEqual(sorted(full_android_files),
75 sorted(RenderTextFiles.find_relevant_files(full_path)))65 sorted(RenderTextFiles.find_relevant_files(full_path)))
7666
77 def test_find_relevant_files_android_and_ubuntu_samedir(self):67 def test_find_relevant_files_android_and_ubuntu_samedir(self):
78 path = self.make_temp_dir(empty=False, file_list=settings.LINUX_FILES)68 path = self.make_temp_dir(empty=False,
79 os.makedirs(os.path.join(path, settings.HOWTO_PATH))69 file_list=settings.LINUX_FILES + settings.ANDROID_FILES)
80 full_files = []70 full_files = []
81 for file in settings.ANDROID_FILES:71 for file in settings.ANDROID_FILES:
82 full_files.append(os.path.join(path, settings.HOWTO_PATH, file))72 full_files.append(os.path.join(path, file))
83 open(os.path.join(path, settings.HOWTO_PATH, file), 'w').close()73 open(os.path.join(path, file), 'w').close()
84 for file in settings.LINUX_FILES:74 for file in settings.LINUX_FILES:
85 full_files.append(os.path.join(path, file))75 full_files.append(os.path.join(path, file))
86 with self.assertRaises(MultipleFilesException):76 with self.assertRaises(MultipleFilesException):
8777
=== modified file 'settings.py'
--- settings.py 2012-10-23 13:07:01 +0000
+++ settings.py 2012-10-24 16:10:24 +0000
@@ -163,22 +163,18 @@
163)163)
164164
165# Render TEXTILE files settings.165# Render TEXTILE files settings.
166HOWTO_PATH = 'howto/'
167
168LINUX_FILES = ('README',166LINUX_FILES = ('README',
169 'INSTALL',167 'INSTALL',
170 'HACKING',168 'HACKING',
171 'FIRMWARE',169 'FIRMWARE',
172 'RTSM')170 'RTSM')
171
173ANDROID_FILES = ('HOWTO_releasenotes.txt',172ANDROID_FILES = ('HOWTO_releasenotes.txt',
174 'HOWTO_install.txt',173 'HOWTO_install.txt',
175 'HOWTO_getsourceandbuild.txt',174 'HOWTO_getsourceandbuild.txt',
176 'HOWTO_flashfirmware.txt',175 'HOWTO_flashfirmware.txt',
177 'HOWTO_rtsm.txt')176 'HOWTO_rtsm.txt')
178177
179MANDATORY_ANDROID_FILES = ('HOWTO_install.txt',
180 'HOWTO_getsourceandbuild.txt')
181
182FILES_MAP = {'HOWTO_releasenotes.txt': 'Release Notes',178FILES_MAP = {'HOWTO_releasenotes.txt': 'Release Notes',
183 'HOWTO_install.txt': 'Binary Image Installation',179 'HOWTO_install.txt': 'Binary Image Installation',
184 'HOWTO_getsourceandbuild.txt': 'Building From Source',180 'HOWTO_getsourceandbuild.txt': 'Building From Source',
185181
=== removed directory 'templates/textile_fallbacks'
=== removed file 'templates/textile_fallbacks/HOWTO_flashfirmware.txt'
--- templates/textile_fallbacks/HOWTO_flashfirmware.txt 2012-10-19 11:06:33 +0000
+++ templates/textile_fallbacks/HOWTO_flashfirmware.txt 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1Please 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
20
=== removed file 'templates/textile_fallbacks/HOWTO_getsourceandbuild.txt'
--- templates/textile_fallbacks/HOWTO_getsourceandbuild.txt 2012-10-19 11:06:33 +0000
+++ templates/textile_fallbacks/HOWTO_getsourceandbuild.txt 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1Please 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
20
=== removed file 'templates/textile_fallbacks/HOWTO_install.txt'
--- templates/textile_fallbacks/HOWTO_install.txt 2012-10-19 11:06:33 +0000
+++ templates/textile_fallbacks/HOWTO_install.txt 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1Please 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

Subscribers

People subscribed via source and target branches